diff --git a/plugins/system/system.go b/plugins/system/system.go index afa8d6701..a2567c864 100644 --- a/plugins/system/system.go +++ b/plugins/system/system.go @@ -34,9 +34,10 @@ type SystemStats struct { ps PS } -func (s *SystemStats) add(acc plugins.Accumulator, name string, val float64) { +func (s *SystemStats) add(acc plugins.Accumulator, + name string, val float64, tags map[string]string) { if val >= 0 { - acc.Add(name, val, nil) + acc.Add(name, val, tags) } } @@ -56,17 +57,21 @@ func (s *SystemStats) Gather(acc plugins.Accumulator) error { } for _, cts := range times { - s.add(acc, cts.CPU+".user", cts.User) - s.add(acc, cts.CPU+".system", cts.System) - s.add(acc, cts.CPU+".idle", cts.Idle) - s.add(acc, cts.CPU+".nice", cts.Nice) - s.add(acc, cts.CPU+".iowait", cts.Iowait) - s.add(acc, cts.CPU+".irq", cts.Irq) - s.add(acc, cts.CPU+".softirq", cts.Softirq) - s.add(acc, cts.CPU+".steal", cts.Steal) - s.add(acc, cts.CPU+".guest", cts.Guest) - s.add(acc, cts.CPU+".guestNice", cts.GuestNice) - s.add(acc, cts.CPU+".stolen", cts.Stolen) + tags := map[string]string{ + "cpu": cts.CPU, + } + + s.add(acc, "user", cts.User, tags) + s.add(acc, "system", cts.System, tags) + s.add(acc, "idle", cts.Idle, tags) + s.add(acc, "nice", cts.Nice, tags) + s.add(acc, "iowait", cts.Iowait, tags) + s.add(acc, "irq", cts.Irq, tags) + s.add(acc, "softirq", cts.Softirq, tags) + s.add(acc, "steal", cts.Steal, tags) + s.add(acc, "guest", cts.Guest, tags) + s.add(acc, "guestNice", cts.GuestNice, tags) + s.add(acc, "stolen", cts.Stolen, tags) } disks, err := s.ps.DiskUsage() diff --git a/plugins/system/system_test.go b/plugins/system/system_test.go index d885f3752..c5a7865a3 100644 --- a/plugins/system/system_test.go +++ b/plugins/system/system_test.go @@ -170,17 +170,21 @@ func TestSystemStats_GenerateStats(t *testing.T) { assert.True(t, acc.CheckValue("load5", 1.5)) assert.True(t, acc.CheckValue("load15", 0.8)) - assert.True(t, acc.CheckValue("all.user", 3.1)) - assert.True(t, acc.CheckValue("all.system", 8.2)) - assert.True(t, acc.CheckValue("all.idle", 80.1)) - assert.True(t, acc.CheckValue("all.nice", 1.3)) - assert.True(t, acc.CheckValue("all.iowait", 0.2)) - assert.True(t, acc.CheckValue("all.irq", 0.1)) - assert.True(t, acc.CheckValue("all.softirq", 0.11)) - assert.True(t, acc.CheckValue("all.steal", 0.0001)) - assert.True(t, acc.CheckValue("all.guest", 8.1)) - assert.True(t, acc.CheckValue("all.guestNice", 0.324)) - assert.True(t, acc.CheckValue("all.stolen", 0.051)) + cputags := map[string]string{ + "cpu": "all", + } + + assert.True(t, acc.CheckTaggedValue("user", 3.1, cputags)) + assert.True(t, acc.CheckTaggedValue("system", 8.2, cputags)) + assert.True(t, acc.CheckTaggedValue("idle", 80.1, cputags)) + assert.True(t, acc.CheckTaggedValue("nice", 1.3, cputags)) + assert.True(t, acc.CheckTaggedValue("iowait", 0.2, cputags)) + assert.True(t, acc.CheckTaggedValue("irq", 0.1, cputags)) + assert.True(t, acc.CheckTaggedValue("softirq", 0.11, cputags)) + assert.True(t, acc.CheckTaggedValue("steal", 0.0001, cputags)) + assert.True(t, acc.CheckTaggedValue("guest", 8.1, cputags)) + assert.True(t, acc.CheckTaggedValue("guestNice", 0.324, cputags)) + assert.True(t, acc.CheckTaggedValue("stolen", 0.051, cputags)) tags := map[string]string{ "path": "/",