forked from bosun-monitor/bosun
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cassandra_unix.go
52 lines (47 loc) · 1.31 KB
/
cassandra_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// +build darwin linux
package collectors
import (
"strings"
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/util"
)
func init() {
collectors = append(collectors, &IntervalCollector{F: c_nodestats_cfstats_linux})
}
func c_nodestats_cfstats_linux() (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
var keyspace, table string
util.ReadCommand(func(line string) error {
fields := strings.Split(strings.TrimSpace(line), ": ")
if len(fields) != 2 {
return nil
}
if fields[0] == "Keyspace" {
keyspace = fields[1]
table = ""
return nil
}
if fields[0] == "Table" {
table = fields[1]
return nil
}
metric := strings.Replace(fields[0], " ", "_", -1)
metric = strings.Replace(metric, "(", "", -1)
metric = strings.Replace(metric, ")", "", -1)
metric = strings.Replace(metric, ",", "", -1)
metric = strings.ToLower(metric)
values := strings.Fields(fields[1])
if values[0] == "NaN" {
return nil
}
value := values[0]
if table == "" {
Add(&md, "cassandra.tables."+metric, value, opentsdb.TagSet{"keyspace": keyspace}, metadata.Unknown, metadata.None, "")
} else {
Add(&md, "cassandra.tables."+metric, value, opentsdb.TagSet{"keyspace": keyspace, "table": table}, metadata.Unknown, metadata.None, "")
}
return nil
}, "nodetool", "cfstats")
return md, nil
}