Skip to content

Commit

Permalink
ignore orphaned counters
Browse files Browse the repository at this point in the history
The purpose of this module is to expose metrics for prometheus. As
such, we are building time series from the counters. This means we
should not expose metrics that do not exist anymore: configured out
from syslog-ng and reloaded. This patch filters out orphan counters.

Signed-off-by: Antal Nemes <[email protected]>
  • Loading branch information
furiel committed Apr 25, 2024
1 parent c28c53a commit 237dd1d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/syslog-ng-ctl/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,17 @@ func parseStats(rsp string) (stats []Stat, errs error) {
errs = errors.Join(errs, err)
continue
}
stats = append(stats, Stat{
SourceName: fields[0],
SourceID: fields[1],
SourceInstance: fields[2],
SourceState: SourceState(fields[3][0]),
Type: fields[4],
Number: num,
})

if fields[3] != string(SourceStateOrphaned) {
stats = append(stats, Stat{
SourceName: fields[0],
SourceID: fields[1],
SourceInstance: fields[2],
SourceState: SourceState(fields[3][0]),
Type: fields[4],
Number: num,
})
}
}
return
}
12 changes: 12 additions & 0 deletions pkg/syslog-ng-ctl/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ src.internal;s_src#1;;a;processed;59
src.internal;s_src#1;;a;stamp;1673105444
destination;d_newserr;;a;processed;0
global;scratch_buffers_bytes;;a;queued;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_last_1h;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_last_24h;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;dropped;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;processed;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;queued;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;memory_usage;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;written;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;truncated_bytes;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;eps_since_start;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;msg_size_max;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;truncated_count;0
dst.network;#anon-destination0#0;tcp,localhost:1234;o;msg_size_avg;0
.
`
expected := []Stat{
Expand Down

0 comments on commit 237dd1d

Please sign in to comment.