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:
- units: int64
- tags: `server=<hostname> port=<port>`
- tags: `server=<hostname> port=<port> state=<leader|follower>`
Measurement names:
- zookeeper_avg_latency
@ -55,8 +55,12 @@ Measurement names:
Meta:
- units: string
- tags: `server=<hostname> port=<port>`
- tags: `server=<hostname> port=<port> state=<leader|follower>`
Measurement names:
- 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 {
var zookeeper_state string
_, _, err := net.SplitHostPort(address)
if err != nil {
address = address + ":2181"
@ -78,7 +79,6 @@ func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error
if len(service) != 2 {
return fmt.Errorf("Invalid service address: %s", address)
}
tags := map[string]string{"server": service[0], "port": service[1]}
fields := make(map[string]interface{})
for scanner.Scan() {
@ -92,15 +92,24 @@ func (z *Zookeeper) gatherServer(address string, acc telegraf.Accumulator) error
}
measurement := strings.TrimPrefix(parts[1], "zk_")
sValue := string(parts[2])
iVal, err := strconv.ParseInt(sValue, 10, 64)
if err == nil {
fields[measurement] = iVal
if measurement == "server_state" {
zookeeper_state = parts[2]
} else {
fields[measurement] = sValue
sValue := string(parts[2])
iVal, err := strconv.ParseInt(sValue, 10, 64)
if err == nil {
fields[measurement] = iVal
} else {
fields[measurement] = sValue
}
}
}
tags := map[string]string{
"server": service[0],
"port": service[1],
"state": zookeeper_state,
}
acc.AddFields("zookeeper", fields, tags)
return nil