From 7e96a9afda6eb382a8f2f2191a39e8f32c77b42b Mon Sep 17 00:00:00 2001 From: Shirou WAKAYAMA Date: Mon, 5 Oct 2015 10:43:46 +0900 Subject: [PATCH] Change MQTT output topic format to split plugin name. --- outputs/mqtt/mqtt.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/outputs/mqtt/mqtt.go b/outputs/mqtt/mqtt.go index e8af496f1..7f797f7cf 100644 --- a/outputs/mqtt/mqtt.go +++ b/outputs/mqtt/mqtt.go @@ -37,8 +37,9 @@ type MQTT struct { var sampleConfig = ` servers = ["localhost:1883"] # required. - # MQTT outputs send metrics - # "/host//mem_used_percent" + # MQTT outputs send metrics to this topic format + # "/host///" + # ex: prefix/host/web01.example.com/mem/available # topic_prefix = "prefix" # Set hostname used in the sending topic. if empty use os.Hostname(). @@ -97,7 +98,11 @@ func (m *MQTT) Write(bp client.BatchPoints) error { if m.TopicPrefix != "" { t = append(t, m.TopicPrefix) } - t = append(t, "host", m.Hostname, p.Measurement) + tm := strings.Split(p.Measurement, "_") + if len(tm) < 2 { + tm = []string{p.Measurement, "stat"} + } + t = append(t, "host", m.Hostname, tm[0], tm[1]) topic := strings.Join(t, "/") var value string