From 94eed9b43c48fb3c8e7a8396c170075ef15948ab Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Tue, 25 Aug 2015 13:18:33 -0600 Subject: [PATCH] Add MySQL server address tag to all measurements Closes #138 --- CHANGELOG.md | 1 + plugins/memcached/memcached.go | 2 +- plugins/mysql/mysql.go | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a26ed0ce0..19ecc0aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - [#133](https://github.com/influxdb/telegraf/pull/133): Add plugin.Gather error logging. Thanks @nickscript0! - [#136](https://github.com/influxdb/telegraf/issues/136): Add a -usage flag for printing usage of a single plugin. - [#137](https://github.com/influxdb/telegraf/issues/137): Memcached: fix when a value contains a space +- [#138](https://github.com/influxdb/telegraf/issues/138): MySQL server address tag. ### Bugfixes - [#128](https://github.com/influxdb/telegraf/issues/128): system_load measurement missing. diff --git a/plugins/memcached/memcached.go b/plugins/memcached/memcached.go index 7035bde04..2cf555c87 100644 --- a/plugins/memcached/memcached.go +++ b/plugins/memcached/memcached.go @@ -109,7 +109,7 @@ func (m *Memcached) gatherServer(address string, acc plugins.Accumulator) error values[string(s[1])] = string(s[2]) } - // + // Add server address as a tag tags := map[string]string{"server": address} // Process values diff --git a/plugins/mysql/mysql.go b/plugins/mysql/mysql.go index 9714b25e9..425f3ea98 100644 --- a/plugins/mysql/mysql.go +++ b/plugins/mysql/mysql.go @@ -111,10 +111,19 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error { var found bool + // Parse out user/password from server address tag if given + var servtag string + if strings.Contains(serv, "@") { + servtag = strings.Split(serv, "@")[1] + } else { + servtag = serv + } + tags := map[string]string{"server": servtag} + for _, mapped := range mappings { if strings.HasPrefix(name, mapped.onServer) { i, _ := strconv.Atoi(string(val.([]byte))) - acc.Add(mapped.inExport+name[len(mapped.onServer):], i, nil) + acc.Add(mapped.inExport+name[len(mapped.onServer):], i, tags) found = true } } @@ -130,14 +139,14 @@ func (m *Mysql) gatherServer(serv string, acc plugins.Accumulator) error { return err } - acc.Add("queries", i, nil) + acc.Add("queries", i, tags) case "Slow_queries": i, err := strconv.ParseInt(string(val.([]byte)), 10, 64) if err != nil { return err } - acc.Add("slow_queries", i, nil) + acc.Add("slow_queries", i, tags) } }