Skip to content

Commit

Permalink
Considere zookeeper's state as a tags (#1417)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tuier authored and sparrc committed Jul 16, 2016
1 parent 207c549 commit 300d9ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 7 additions & 3 deletions plugins/inputs/zookeeper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
-
23 changes: 16 additions & 7 deletions plugins/inputs/zookeeper/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand All @@ -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
Expand Down

0 comments on commit 300d9ad

Please sign in to comment.