Skip to content

Commit

Permalink
Handle lines with percentile statistics counters and buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
aleroyer committed Feb 18, 2023
1 parent 2f41ec1 commit 4e17db7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
rsyslogInputIMDUP
rsyslogForward
rsyslogKubernetes
rsyslogPercentile
rsyslogPercentileBucket
)

type rsyslogExporter struct {
Expand Down Expand Up @@ -131,6 +133,15 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
re.set(p)
}

case rsyslogPercentile, rsyslogPercentileBucket:
p, err := newPercentileStatFromJSON(buf)
if err != nil {
return err
}
for _, p := range p.toPoints() {
re.set(p)
}

default:
return fmt.Errorf("unknown pstat type: %v", pstatType)
}
Expand Down
63 changes: 63 additions & 0 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,69 @@ func TestHandleLineWithDynafileCache(t *testing.T) {
testHelper(t, dynafileCacheLog, tests)
}

func TestHandleLineWithPercentileGlobal(t *testing.T) {
tests := []*testUnit{
&testUnit{
Name: "percentile_global",
Val: 0,
LabelValue: "host_statistics.ops_overflow",
},
&testUnit{
Name: "percentile_global",
Val: 1,
LabelValue: "host_statistics.new_metric_add",
},
}

log := []byte(`2022-02-18T19:11:12.672935+00:00 some-node.example.org rsyslogd-pstats: { "name": "global", "origin": "percentile", "values": { "host_statistics.new_metric_add": 1, "host_statistics.ops_overflow": 0 } }`)

testHelper(t, log, tests)
}

func TestHandleLineWithPercentileBucket(t *testing.T) {
tests := []*testUnit{
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1950,
LabelValue: "msg_per_host|p95",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1500,
LabelValue: "msg_per_host|p50",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1990,
LabelValue: "msg_per_host|p99",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1001,
LabelValue: "msg_per_host|window_min",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 2000,
LabelValue: "msg_per_host|window_max",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1500500,
LabelValue: "msg_per_host|window_sum",
},
&testUnit{
Name: "host_statistics_percentile_bucket",
Val: 1000,
LabelValue: "msg_per_host|window_count",
},
}

log := []byte(`2022-02-18T19:11:12.672935+00:00 some-node.example.org rsyslogd-pstats: { "name": "host_statistics", "origin": "percentile.bucket", "values": { "msg_per_host|p95": 1950, "msg_per_host|p50": 1500, "msg_per_host|p99": 1990, "msg_per_host|window_min": 1001, "msg_per_host|window_max": 2000, "msg_per_host|window_sum": 1500500, "msg_per_host|window_count": 1000 } }`)

testHelper(t, log, tests)
}

func TestHandleUnknown(t *testing.T) {
unknownLog := []byte(`2017-08-30T08:10:04.786350+00:00 some-node.example.org rsyslogd-pstats: {"a":"b"}`)

Expand Down

0 comments on commit 4e17db7

Please sign in to comment.