forked from aerospike/aerospike-prometheus-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watcher_jobs.go
122 lines (98 loc) · 3.14 KB
/
watcher_jobs.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
)
// Jobs raw metrics
var jobsRawMetrics = map[string]metricType{
"priority": mtGauge,
"net-io-time": mtGauge,
"n-pids-requested": mtGauge,
"rps": mtGauge,
"active-threads": mtGauge,
"job-progress": mtGauge,
"run-time": mtGauge,
"time-since-done": mtGauge,
"recs-throttled": mtGauge,
"recs-filtered-meta": mtGauge,
"recs-filtered-bins": mtGauge,
"recs-succeeded": mtGauge,
"recs-failed": mtGauge,
"net-io-bytes": mtGauge,
"socket-timeout": mtGauge,
"udf-active": mtGauge,
"ops-active": mtGauge,
}
type JobsWatcher struct {
jobMetrics map[string]metricType
}
func (jw *JobsWatcher) describe(ch chan<- *prometheus.Desc) {}
func (jw *JobsWatcher) passOneKeys() []string {
// "build" info key should be returned here,
// but it is also being sent by LatencyWatcher.passOneKeys(),
// hence skipping here.
return nil
}
func (jw *JobsWatcher) passTwoKeys(rawMetrics map[string]string) (jobsCommands []string) {
if config.Aerospike.DisableJobMetrics {
// disabled
return nil
}
jobsCommands = []string{"jobs:", "scan-show:", "query-show:"}
ok, err := buildVersionGreaterThanOrEqual(rawMetrics, "6.0.0.0-0")
if err != nil {
log.Warn(err)
return jobsCommands
}
if ok {
return []string{"query-show:"}
}
ok, err = buildVersionGreaterThanOrEqual(rawMetrics, "5.7.0.0")
if err != nil {
log.Warn(err)
return jobsCommands
}
if ok {
return []string{"scan-show:", "query-show:"}
}
return []string{"jobs:"}
}
// var jobMetrics map[string]metricType
func (jw *JobsWatcher) refresh(o *Observer, infoKeys []string, rawMetrics map[string]string, ch chan<- prometheus.Metric) error {
if config.Aerospike.DisableJobMetrics {
// disabled
return nil
}
var jobStats []string
if rawMetrics["scan-show:"] != "" || rawMetrics["query-show:"] != "" {
jobStats = strings.Split(rawMetrics["scan-show:"], ";")
jobStats = append(jobStats, strings.Split(rawMetrics["query-show:"], ";")...)
} else {
jobStats = strings.Split(rawMetrics["jobs:"], ";")
}
log.Tracef("job-stats:%v", jobStats)
if jw.jobMetrics == nil {
jw.jobMetrics = getFilteredMetrics(jobsRawMetrics, config.Aerospike.JobMetricsAllowlist, config.Aerospike.JobMetricsAllowlistEnabled, config.Aerospike.JobMetricsBlocklist)
}
for i := range jobStats {
jobObserver := make(MetricMap, len(jw.jobMetrics))
for m, t := range jw.jobMetrics {
jobObserver[m] = makeMetric("aerospike_jobs", m, t, config.AeroProm.MetricLabels, "cluster_name", "service", "ns", "set", "module", "job_type", "trid", "sindex_name")
}
stats := parseStats(jobStats[i], ":")
for stat, pm := range jobObserver {
v, exists := stats[stat]
if !exists {
// not found
continue
}
pv, err := tryConvert(v)
if err != nil {
continue
}
ch <- prometheus.MustNewConstMetric(pm.desc, pm.valueType, pv, rawMetrics[ikClusterName], rawMetrics[ikService], stats["ns"], stats["set"], stats["module"], stats["job-type"], stats["trid"], stats["sindex-name"])
}
}
return nil
}