clean up and finish aerospike refactor & readme
This commit is contained in:
parent
0be69b8a44
commit
5f14ad9fa1
File diff suppressed because one or more lines are too long
|
@ -72,18 +72,17 @@ func (a *Aerospike) gatherServer(hostport string, acc telegraf.Accumulator) erro
|
||||||
nodes := c.GetNodes()
|
nodes := c.GetNodes()
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"node_name": n.GetName(),
|
|
||||||
"aerospike_host": hostport,
|
"aerospike_host": hostport,
|
||||||
}
|
}
|
||||||
fields := make(map[string]interface{})
|
fields := map[string]interface{}{
|
||||||
|
"node_name": n.GetName(),
|
||||||
|
}
|
||||||
stats, err := as.RequestNodeStats(n)
|
stats, err := as.RequestNodeStats(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for k, v := range stats {
|
for k, v := range stats {
|
||||||
if iv, err := strconv.ParseInt(v, 10, 64); err == nil {
|
fields[strings.Replace(k, "-", "_", -1)] = parseValue(v)
|
||||||
fields[strings.Replace(k, "-", "_", -1)] = iv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
acc.AddFields("aerospike_node", fields, tags, time.Now())
|
acc.AddFields("aerospike_node", fields, tags, time.Now())
|
||||||
|
|
||||||
|
@ -94,9 +93,13 @@ func (a *Aerospike) gatherServer(hostport string, acc telegraf.Accumulator) erro
|
||||||
namespaces := strings.Split(info["namespaces"], ";")
|
namespaces := strings.Split(info["namespaces"], ";")
|
||||||
|
|
||||||
for _, namespace := range namespaces {
|
for _, namespace := range namespaces {
|
||||||
nTags := copyTags(tags)
|
nTags := map[string]string{
|
||||||
|
"aerospike_host": hostport,
|
||||||
|
}
|
||||||
nTags["namespace"] = namespace
|
nTags["namespace"] = namespace
|
||||||
nFields := make(map[string]interface{})
|
nFields := map[string]interface{}{
|
||||||
|
"node_name": n.GetName(),
|
||||||
|
}
|
||||||
info, err := as.RequestNodeInfo(n, "namespace/"+namespace)
|
info, err := as.RequestNodeInfo(n, "namespace/"+namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -107,9 +110,7 @@ func (a *Aerospike) gatherServer(hostport string, acc telegraf.Accumulator) erro
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if iv, err := strconv.ParseInt(parts[1], 10, 64); err == nil {
|
nFields[strings.Replace(parts[0], "-", "_", -1)] = parseValue(parts[1])
|
||||||
nFields[strings.Replace(parts[0], "-", "_", -1)] = iv
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())
|
acc.AddFields("aerospike_namespace", nFields, nTags, time.Now())
|
||||||
}
|
}
|
||||||
|
@ -117,6 +118,16 @@ func (a *Aerospike) gatherServer(hostport string, acc telegraf.Accumulator) erro
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseValue(v string) interface{} {
|
||||||
|
if parsed, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||||
|
return parsed
|
||||||
|
} else if parsed, err := strconv.ParseBool(v); err == nil {
|
||||||
|
return parsed
|
||||||
|
} else {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func copyTags(m map[string]string) map[string]string {
|
func copyTags(m map[string]string) map[string]string {
|
||||||
out := make(map[string]string)
|
out := make(map[string]string)
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
|
|
Loading…
Reference in New Issue