Debian Codegraph @

exporter/modules.go

raw symbols SCIP
1 package exporter
2
3 import (
4 "strings"
5
6 "github.com/gomodule/redigo/redis"
7 "github.com/prometheus/client_golang/prometheus"
8 log "github.com/sirupsen/logrus"
9 )
10
11 func (e *Exporter) extractModulesMetrics(ch chan<- prometheus.Metric, c redis.Conn) {
12 info, err := redis.String(doRedisCmd(c, "INFO", "MODULES"))
13 if err != nil {
14 log.Errorf("extractSearchMetrics() err: %s", err)
15 return
16 }
17
18 lines := strings.SplitSeq(info, "\r\n")
19 for line := range lines {
20 log.Debugf("info: %s", line)
21
22 split := strings.Split(line, ":")
23 if len(split) != 2 {
24 continue
25 }
26
27 if split[0] == "module" {
28 // module format: 'module:name=<module-name>,ver=21005,api=1,filters=0,usedby=[],using=[],options=[]'
29 module := strings.Split(split[1], ",")
30 if len(module) != 7 {
31 continue
32 }
33 extractModuleVal := func(s string) string {
34 parts := strings.SplitN(s, "=", 2)
35 if len(parts) != 2 {
36 return ""
37 }
38 return parts[1]
39 }
40 e.registerConstMetricGauge(ch, "module_info", 1,
41 extractModuleVal(module[0]),
42 extractModuleVal(module[1]),
43 extractModuleVal(module[2]),
44 extractModuleVal(module[3]),
45 extractModuleVal(module[4]),
46 extractModuleVal(module[5]),
47 )
48 continue
49 }
50
51 fieldKey := split[0]
52 fieldValue := split[1]
53
54 if !e.includeMetric(fieldKey) {
55 continue
56 }
57 e.parseAndRegisterConstMetric(ch, fieldKey, fieldValue)
58 }
59 }