Skip to content

Commit 4e17db7

Browse files
committed
Handle lines with percentile statistics counters and buckets
1 parent 2f41ec1 commit 4e17db7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Diff for: exporter.go

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ const (
2424
rsyslogInputIMDUP
2525
rsyslogForward
2626
rsyslogKubernetes
27+
rsyslogPercentile
28+
rsyslogPercentileBucket
2729
)
2830

2931
type rsyslogExporter struct {
@@ -131,6 +133,15 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
131133
re.set(p)
132134
}
133135

136+
case rsyslogPercentile, rsyslogPercentileBucket:
137+
p, err := newPercentileStatFromJSON(buf)
138+
if err != nil {
139+
return err
140+
}
141+
for _, p := range p.toPoints() {
142+
re.set(p)
143+
}
144+
134145
default:
135146
return fmt.Errorf("unknown pstat type: %v", pstatType)
136147
}

Diff for: exporter_test.go

+63
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,69 @@ func TestHandleLineWithDynafileCache(t *testing.T) {
258258
testHelper(t, dynafileCacheLog, tests)
259259
}
260260

261+
func TestHandleLineWithPercentileGlobal(t *testing.T) {
262+
tests := []*testUnit{
263+
&testUnit{
264+
Name: "percentile_global",
265+
Val: 0,
266+
LabelValue: "host_statistics.ops_overflow",
267+
},
268+
&testUnit{
269+
Name: "percentile_global",
270+
Val: 1,
271+
LabelValue: "host_statistics.new_metric_add",
272+
},
273+
}
274+
275+
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 } }`)
276+
277+
testHelper(t, log, tests)
278+
}
279+
280+
func TestHandleLineWithPercentileBucket(t *testing.T) {
281+
tests := []*testUnit{
282+
&testUnit{
283+
Name: "host_statistics_percentile_bucket",
284+
Val: 1950,
285+
LabelValue: "msg_per_host|p95",
286+
},
287+
&testUnit{
288+
Name: "host_statistics_percentile_bucket",
289+
Val: 1500,
290+
LabelValue: "msg_per_host|p50",
291+
},
292+
&testUnit{
293+
Name: "host_statistics_percentile_bucket",
294+
Val: 1990,
295+
LabelValue: "msg_per_host|p99",
296+
},
297+
&testUnit{
298+
Name: "host_statistics_percentile_bucket",
299+
Val: 1001,
300+
LabelValue: "msg_per_host|window_min",
301+
},
302+
&testUnit{
303+
Name: "host_statistics_percentile_bucket",
304+
Val: 2000,
305+
LabelValue: "msg_per_host|window_max",
306+
},
307+
&testUnit{
308+
Name: "host_statistics_percentile_bucket",
309+
Val: 1500500,
310+
LabelValue: "msg_per_host|window_sum",
311+
},
312+
&testUnit{
313+
Name: "host_statistics_percentile_bucket",
314+
Val: 1000,
315+
LabelValue: "msg_per_host|window_count",
316+
},
317+
}
318+
319+
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 } }`)
320+
321+
testHelper(t, log, tests)
322+
}
323+
261324
func TestHandleUnknown(t *testing.T) {
262325
unknownLog := []byte(`2017-08-30T08:10:04.786350+00:00 some-node.example.org rsyslogd-pstats: {"a":"b"}`)
263326

0 commit comments

Comments
 (0)