forked from alicebob/asprom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sets.go
62 lines (55 loc) · 1.29 KB
/
sets.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
53
54
55
56
57
58
59
60
61
62
package main
import (
"strings"
as "github.com/aerospike/aerospike-client-go"
"github.com/prometheus/client_golang/prometheus"
)
var (
// SetMetrics lists the keys we report from aero's sets
// command.
// See `asinfo -l -v sets` for the full list.
SetMetrics = []metric{
gauge("objects", "objects"),
gauge("memory_data_bytes", "memory data bytes"),
counter("stop-writes-count", "stop writes count"),
}
)
type setCollector cmetrics
func newSetCollector() setCollector {
set := map[string]cmetric{}
for _, m := range SetMetrics {
set[m.aeroName] = cmetric{
typ: m.typ,
desc: prometheus.NewDesc(
promkey(systemSet, m.aeroName),
m.desc,
[]string{"namespace", "set"},
nil,
),
}
}
return set
}
func (setc setCollector) describe(ch chan<- *prometheus.Desc) {
for _, s := range setc {
ch <- s.desc
}
}
func (setc setCollector) collect(conn *as.Connection) ([]prometheus.Metric, error) {
var metrics []prometheus.Metric
info, err := as.RequestInfo(conn, "sets")
if err != nil {
return nil, err
}
for _, setInfo := range strings.Split(info["sets"], ";") {
if setInfo == "" {
continue
}
setStats := parseInfo(setInfo)
metrics = append(
metrics,
infoCollect(cmetrics(setc), setInfo, setStats["ns"], setStats["set"])...,
)
}
return metrics, nil
}