| 1 | package exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/ |
| 2 | |
| 3 | import ( |
| 4 | "regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/" |
| 5 | "strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/" |
| 7 | |
| 8 | "github.com/gomodule/redigo/redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/" |
| 9 | "github.com/prometheus/client_golang/prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/" |
| 10 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/ "github.com/sirupsen/logrusscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/" |
| 11 | ) |
| 12 | |
| 13 | var reSentinelMasterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/reSentinelMaster. = regexpscip-go gomod github.com/golang/go/src go1.25.0 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25.0 regexp/MustCompile().(`^master\d+`) |
| 14 | |
| 15 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) handleMetricsSentinelscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#handleMetricsSentinel().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, fieldKey string, fieldValue string) { |
| 16 | switch fieldKey { |
| 17 | case |
| 18 | "sentinel_masters", |
| 19 | "sentinel_tilt", |
| 20 | "sentinel_running_scripts", |
| 21 | "sentinel_scripts_queue_length", |
| 22 | "sentinel_simulate_failure_flags": |
| 23 | val, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.Atoiscip-go gomod github.com/golang/go/src go1.25.0 strconv/Atoi().(fieldValue) |
| 24 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, fieldKey, float64(val)) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | if masterName, masterStatus, masterAddress, masterSlaves, masterSentinels, ok := parseSentinelMasterStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseSentinelMasterString().(fieldKey, fieldValue); ok { |
| 29 | masterStatusNum := 0.0 |
| 30 | if masterStatus == "ok" { |
| 31 | masterStatusNum = 1 |
| 32 | } |
| 33 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_status", masterStatusNum, masterName, masterAddress, masterStatus) |
| 34 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_slaves", masterSlaves, masterName, masterAddress) |
| 35 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_sentinels", masterSentinels, masterName, masterAddress) |
| 36 | return |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) extractSentinelMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractSentinelMetrics().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, c redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Connscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#) { |
| 41 | masterDetails, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Valuesscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Values().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "SENTINEL", "MASTERS")) |
| 42 | if err != nil { |
| 43 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Error getting sentinel master details %s:", err) |
| 44 | return |
| 45 | } |
| 46 | |
| 47 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Sentinel master details: %#v", masterDetails) |
| 48 | |
| 49 | for _, masterDetail := range masterDetails { |
| 50 | masterDetailMap, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.StringMapscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/StringMap().(masterDetail, nil) |
| 51 | if err != nil { |
| 52 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Error getting masterDetailmap from masterDetail: %s, err: %s", masterDetail, err) |
| 53 | continue |
| 54 | } |
| 55 | |
| 56 | masterName, ok := masterDetailMap["name"] |
| 57 | if !ok { |
| 58 | continue |
| 59 | } |
| 60 | |
| 61 | masterIp, ok := masterDetailMap["ip"] |
| 62 | if !ok { |
| 63 | continue |
| 64 | } |
| 65 | |
| 66 | masterPort, ok := masterDetailMap["port"] |
| 67 | if !ok { |
| 68 | continue |
| 69 | } |
| 70 | masterAddr := masterIp + ":" + masterPort |
| 71 | |
| 72 | masterCkquorumMsg, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Stringscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/String().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "SENTINEL", "CKQUORUM", masterName)) |
| 73 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Sentinel ckquorum status for master %s: %s %s", masterName, masterCkquorumMsg, err) |
| 74 | masterCkquorumStatus := 1 |
| 75 | if err != nil { |
| 76 | masterCkquorumStatus = 0 |
| 77 | masterCkquorumMsg = err.Error() |
| 78 | } |
| 79 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_ckquorum_status", float64(masterCkquorumStatus), masterName, masterCkquorumMsg) |
| 80 | |
| 81 | masterCkquorum, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["quorum"], 64) |
| 82 | masterFailoverTimeout, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["failover-timeout"], 64) |
| 83 | masterParallelSyncs, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["parallel-syncs"], 64) |
| 84 | masterDownAfterMs, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["down-after-milliseconds"], 64) |
| 85 | masterConfigEpoch, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["config-epoch"], 64) |
| 86 | masterLastOkPingReplyMs, _ := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(masterDetailMap["last-ok-ping-reply"], 64) |
| 87 | masterLastOkPingReplySeconds := masterLastOkPingReplyMs / 1000.0 |
| 88 | |
| 89 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_setting_ckquorum", masterCkquorum, masterName, masterAddr) |
| 90 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_setting_failover_timeout", masterFailoverTimeout, masterName, masterAddr) |
| 91 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_setting_parallel_syncs", masterParallelSyncs, masterName, masterAddr) |
| 92 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_setting_down_after_milliseconds", masterDownAfterMs, masterName, masterAddr) |
| 93 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_config_epoch", masterConfigEpoch, masterName, masterAddr) |
| 94 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_last_ok_ping_reply_seconds", masterLastOkPingReplySeconds, masterName, masterAddr) |
| 95 | |
| 96 | sentinelDetails, _ := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Valuesscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Values().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "SENTINEL", "SENTINELS", masterName)) |
| 97 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Sentinel details for master %s: %s", masterName, sentinelDetails) |
| 98 | e.processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(ch, sentinelDetails, masterName, masterAddr) |
| 99 | |
| 100 | slaveDetails, _ := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Valuesscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Values().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "SENTINEL", "SLAVES", masterName)) |
| 101 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Slave details for master %s: %s", masterName, slaveDetails) |
| 102 | e.processSentinelSlavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSlaves().(ch, slaveDetails, masterName, masterAddr) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) extractSentinelConfigscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#extractSentinelConfig().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, c redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.Connscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/Conn#) { |
| 107 | if !e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..InclConfigMetricsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclConfigMetrics. { |
| 108 | return |
| 109 | } |
| 110 | sentinelConfig, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.StringMapscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/StringMap().(doRedisCmdscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/doRedisCmd().(c, "SENTINEL", "config", "get", "*")) |
| 111 | if err != nil { |
| 112 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Errorfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Errorf().("Error getting sentinel config: %s", err) |
| 113 | return |
| 114 | } |
| 115 | |
| 116 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Sentinel config: %v", sentinelConfig) |
| 117 | |
| 118 | for strKey, strVal := range sentinelConfig { |
| 119 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_config_key_value", 1.0, strKey, strVal) |
| 120 | if val, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(strVal, 64); err == nil { |
| 121 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_config_value", val, strKey) |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) processSentinelSentinelsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSentinels().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, sentinelDetails []any, labels ...string) { |
| 127 | |
| 128 | // If we are here then this master is in ok state |
| 129 | masterOkSentinels := 1 |
| 130 | hasMasterLabels := len(labels) >= 2 |
| 131 | masterName := "" |
| 132 | masterAddr := "" |
| 133 | if hasMasterLabels { |
| 134 | masterName = labels[0] |
| 135 | masterAddr = labels[1] |
| 136 | } |
| 137 | |
| 138 | for _, sentinelDetail := range sentinelDetails { |
| 139 | sentinelDetailMap, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.StringMapscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/StringMap().(sentinelDetail, nil) |
| 140 | if err != nil { |
| 141 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Error getting sentinelDetailMap from sentinelDetail: %s, err: %s", sentinelDetail, err) |
| 142 | continue |
| 143 | } |
| 144 | |
| 145 | name := "" |
| 146 | if v, ok := sentinelDetailMap["name"]; ok { |
| 147 | name = v |
| 148 | } |
| 149 | ip := "" |
| 150 | if v, ok := sentinelDetailMap["ip"]; ok { |
| 151 | ip = v |
| 152 | } |
| 153 | port := "" |
| 154 | if v, ok := sentinelDetailMap["port"]; ok { |
| 155 | port = v |
| 156 | } |
| 157 | runid := "" |
| 158 | if v, ok := sentinelDetailMap["runid"]; ok { |
| 159 | runid = v |
| 160 | } |
| 161 | flags := "" |
| 162 | flagsFound := false |
| 163 | if v, ok := sentinelDetailMap["flags"]; ok { |
| 164 | flags = v |
| 165 | flagsFound = true |
| 166 | } |
| 167 | if e.optionsscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#options..InclSentinelPeerInfoscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Options#InclSentinelPeerInfo. && hasMasterLabels { |
| 168 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_peer_info", 1, masterName, masterAddr, name, ip, port, runid, flags) |
| 169 | } |
| 170 | |
| 171 | if !flagsFound { |
| 172 | continue |
| 173 | } |
| 174 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(flags, "o_down") { |
| 175 | continue |
| 176 | } |
| 177 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(flags, "s_down") { |
| 178 | continue |
| 179 | } |
| 180 | masterOkSentinels = masterOkSentinels + 1 |
| 181 | } |
| 182 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_ok_sentinels", float64(masterOkSentinels), labels...) |
| 183 | } |
| 184 | |
| 185 | func (e *Exporterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#) processSentinelSlavesscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#processSentinelSlaves().(ch chan<- prometheusscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/.Metricscip-go gomod github.com/prometheus/client_golang v1.23.2 `github.com/prometheus/client_golang/prometheus`/Metric#, slaveDetails []any, labels ...string) { |
| 186 | masterOkSlaves := 0 |
| 187 | for _, slaveDetail := range slaveDetails { |
| 188 | slaveDetailMap, err := redisscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/.StringMapscip-go gomod github.com/gomodule/redigo v1.9.3 `github.com/gomodule/redigo/redis`/StringMap().(slaveDetail, nil) |
| 189 | if err != nil { |
| 190 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("Error getting slavedetailMap from slaveDetail: %s, err: %s", slaveDetail, err) |
| 191 | continue |
| 192 | } |
| 193 | |
| 194 | slaveFlags, ok := slaveDetailMap["flags"] |
| 195 | if !ok { |
| 196 | continue |
| 197 | } |
| 198 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(slaveFlags, "o_down") { |
| 199 | continue |
| 200 | } |
| 201 | if stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(slaveFlags, "s_down") { |
| 202 | continue |
| 203 | } |
| 204 | masterOkSlaves = masterOkSlaves + 1 |
| 205 | } |
| 206 | if len(labels) >= 2 { |
| 207 | e.registerConstMetricGaugescip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/Exporter#registerConstMetricGauge().(ch, "sentinel_master_ok_slaves", float64(masterOkSlaves), labels...) |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | valid examples: |
| 213 | |
| 214 | master0:name=user03,status=sdown,address=192.169.2.52:6381,slaves=1,sentinels=5 |
| 215 | master1:name=user02,status=ok,address=192.169.2.54:6380,slaves=1,sentinels=5 |
| 216 | */ |
| 217 | func parseSentinelMasterStringscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/parseSentinelMasterString().(master string, masterInfo string) (masterName string, masterStatus string, masterAddr string, masterSlaves float64, masterSentinels float64, ok bool) { |
| 218 | ok = false |
| 219 | if !reSentinelMasterscip-go gomod github.com/oliver006/redis_exporter . `github.com/oliver006/redis_exporter/exporter`/reSentinelMaster..MatchStringscip-go gomod github.com/golang/go/src go1.25.0 regexp/Regexp#MatchString().(master) { |
| 220 | return |
| 221 | } |
| 222 | matchedMasterInfo := make(map[string]string) |
| 223 | for kvPart := range stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.SplitSeqscip-go gomod github.com/golang/go/src go1.25.0 strings/SplitSeq().(masterInfo, ",") { |
| 224 | x := stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.25.0 strings/Split().(kvPart, "=") |
| 225 | if len(x) != 2 { |
| 226 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Errorfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Errorf().("Invalid format for sentinel's master string, got: %s", kvPart) |
| 227 | continue |
| 228 | } |
| 229 | matchedMasterInfo[x[0]] = x[1] |
| 230 | } |
| 231 | |
| 232 | masterName = matchedMasterInfo["name"] |
| 233 | masterStatus = matchedMasterInfo["status"] |
| 234 | masterAddr = matchedMasterInfo["address"] |
| 235 | masterSlaves, err := strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(matchedMasterInfo["slaves"], 64) |
| 236 | if err != nil { |
| 237 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("parseSentinelMasterString(): couldn't parse slaves value, got: %s, err: %s", matchedMasterInfo["slaves"], err) |
| 238 | return |
| 239 | } |
| 240 | masterSentinels, err = strconvscip-go gomod github.com/golang/go/src go1.25.0 strconv/.ParseFloatscip-go gomod github.com/golang/go/src go1.25.0 strconv/ParseFloat().(matchedMasterInfo["sentinels"], 64) |
| 241 | if err != nil { |
| 242 | logscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/.Debugfscip-go gomod github.com/sirupsen/logrus v1.9.4 `github.com/sirupsen/logrus`/Debugf().("parseSentinelMasterString(): couldn't parse sentinels value, got: %s, err: %s", matchedMasterInfo["sentinels"], err) |
| 243 | return |
| 244 | } |
| 245 | ok = true |
| 246 | |
| 247 | return |
| 248 | } |