forked from aerospike/aerospike-prometheus-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher_xdr.go
77 lines (59 loc) · 2.05 KB
/
watcher_xdr.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
type XdrWatcher struct {
xdrMetrics map[string]AerospikeStat
}
func (xw *XdrWatcher) describe(ch chan<- *prometheus.Desc) {}
func (xw *XdrWatcher) passOneKeys() []string {
return []string{"get-config:context=xdr"}
}
func (xw *XdrWatcher) passTwoKeys(rawMetrics map[string]string) []string {
res := rawMetrics["get-config:context=xdr"]
list := parseStats(res, ";")
dcsList := strings.Split(list["dcs"], ",")
var infoKeys []string
for _, dc := range dcsList {
if dc != "" {
infoKeys = append(infoKeys, "get-stats:context=xdr;dc="+dc)
}
}
return infoKeys
}
// All (allowed/blocked) XDR stats. Based on the config.Aerospike.XdrMetricsAllowlist, config.Aerospike.XdrMetricsBlocklist.
// var xdrMetrics = make(map[string]AerospikeStat)
func (xw *XdrWatcher) refresh(o *Observer, infoKeys []string, rawMetrics map[string]string, ch chan<- prometheus.Metric) error {
if xw.xdrMetrics == nil {
xw.xdrMetrics = make(map[string]AerospikeStat)
}
for _, dc := range infoKeys {
dcName := strings.ReplaceAll(dc, "get-stats:context=xdr;dc=", "")
log.Tracef("xdr-stats:%s:%s", dcName, rawMetrics[dc])
stats := parseStats(rawMetrics[dc], ";")
for stat, value := range stats {
pv, err := tryConvert(value)
if err != nil {
continue
}
asMetric, exists := xw.xdrMetrics[stat]
if !exists {
asMetric = newAerospikeStat(CTX_XDR, stat)
xw.xdrMetrics[stat] = asMetric
}
// handle any panic from prometheus, this may occur when prom encounters a config/stat with special characters
defer func() {
if r := recover(); r != nil {
log.Tracef("xdr-stats: recovered from panic while handling stat %s in %s", stat, dcName)
}
}()
if asMetric.isAllowed {
desc, valueType := asMetric.makePromMetric(METRIC_LABEL_CLUSTER_NAME, METRIC_LABEL_SERVICE, METRIC_LABEL_DC_NAME)
ch <- prometheus.MustNewConstMetric(desc, valueType, pv, rawMetrics[ikClusterName], rawMetrics[ikService], dcName)
}
}
}
return nil
}