Debian Codegraph @

exporter/slowlog.go

raw symbols SCIP
1 package exporter
2
3 import (
4 "github.com/gomodule/redigo/redis"
5 "github.com/prometheus/client_golang/prometheus"
6 )
7
8 func (e *Exporter) extractSlowLogMetrics(ch chan<- prometheus.Metric, c redis.Conn) {
9 if reply, err := redis.Int64(doRedisCmd(c, "SLOWLOG", "LEN")); err == nil {
10 e.registerConstMetricGauge(ch, "slowlog_length", float64(reply))
11 }
12
13 values, err := redis.Values(doRedisCmd(c, "SLOWLOG", "GET", "1"))
14 if err != nil {
15 return
16 }
17
18 var slowlogLastID int64
19 var lastSlowExecutionDurationSeconds float64
20
21 if len(values) > 0 {
22 if values, err = redis.Values(values[0], err); err == nil && len(values) > 0 {
23 if id, ok := values[0].(int64); ok {
24 slowlogLastID = id
25 }
26 if len(values) > 2 {
27 if dur, ok := values[2].(int64); ok {
28 lastSlowExecutionDurationSeconds = float64(dur) / 1e6
29 }
30 }
31 }
32 }
33
34 e.registerConstMetricGauge(ch, "slowlog_last_id", float64(slowlogLastID))
35 e.registerConstMetricGauge(ch, "last_slow_execution_duration_seconds", lastSlowExecutionDurationSeconds)
36 }