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:
parent
207c5498e7
commit
300d9adbd0
|
@ -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:
|
||||||
|
-
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue