Considere zookeeper's state as a tags (#1417)

This change will send the state of zookeeper (leader|follower) as a tag
and not a metrics
That way it will be easier to search for filter per state
This commit is contained in:
tuier 2016-07-16 19:19:21 +01:00 committed by Cameron Sparr
parent 207c5498e7
commit 300d9adbd0
2 changed files with 23 additions and 10 deletions

View File

@ -32,7 +32,7 @@ echo mntr | nc localhost 2181
Meta: Meta:
- units: int64 - units: int64
- tags: `server=<hostname> port=<port>` - tags: `server=<hostname> port=<port> state=<leader|follower>`
Measurement names: Measurement names:
- zookeeper_avg_latency - zookeeper_avg_latency
@ -55,8 +55,12 @@ Measurement names:
Meta: Meta:
- units: string - units: string
- tags: `server=<hostname> port=<port>` - tags: `server=<hostname> port=<port> state=<leader|follower>`
Measurement names: Measurement names:
- zookeeper_version - zookeeper_version
- zookeeper_server_state
### Tags:
- All measurements have the following tags:
-

View File

@ -55,6 +55,7 @@ func (z *Zookeeper) Gather(acc telegraf.Accumulator) error {
} }
func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error { func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error {
var zookeeper_state string
_, _, err := net.SplitHostPort(address) _, _, err := net.SplitHostPort(address)
if err != nil { if err != nil {
address = address + ":2181" address = address + ":2181"
@ -78,7 +79,6 @@ func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error
if len(service) != 2 { if len(service) != 2 {
return fmt.Errorf("Invalid service address: %s", address) return fmt.Errorf("Invalid service address: %s", address)
} }
tags := map[string]string{"server": service[0], "port": service[1]}
fields := make(map[string]interface{}) fields := make(map[string]interface{})
for scanner.Scan() { for scanner.Scan() {
@ -92,6 +92,9 @@ func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error
} }
measurement := strings.TrimPrefix(parts[1], "zk_") measurement := strings.TrimPrefix(parts[1], "zk_")
if measurement == "server_state" {
zookeeper_state = parts[2]
} else {
sValue := string(parts[2]) sValue := string(parts[2])
iVal, err := strconv.ParseInt(sValue, 10, 64) iVal, err := strconv.ParseInt(sValue, 10, 64)
@ -101,6 +104,12 @@ func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error
fields[measurement] = sValue fields[measurement] = sValue
} }
} }
}
tags := map[string]string{
"server": service[0],
"port": service[1],
"state": zookeeper_state,
}
acc.AddFields("zookeeper", fields, tags) acc.AddFields("zookeeper", fields, tags)
return nil return nil