@@ -36,7 +36,7 @@ func (e *Exporter) extractInfoMetrics(ch chan<- prometheus.Metric, info string,
36
36
line = strings .TrimSpace (line )
37
37
log .Debugf ("info: %s" , line )
38
38
if len (line ) > 0 && strings .HasPrefix (line , "# " ) {
39
- if strings .HasPrefix (line , "# Last scan db time " ) {
39
+ if strings .HasPrefix (line , "# Last DBSIZE SCAN " ) {
40
40
continue
41
41
}
42
42
fieldClass = line [2 :]
@@ -77,11 +77,12 @@ func (e *Exporter) extractInfoMetrics(ch chan<- prometheus.Metric, info string,
77
77
continue
78
78
79
79
case "Keyspace" :
80
- if keysTotal , keysEx , avgTTL , ok := parseDBKeyspaceString (fieldKey , fieldValue ); ok {
80
+ if keysTotal , keysEx , avgTTL , keysExpired , ok := parseDBKeyspaceString (fieldKey , fieldValue ); ok {
81
81
dbName := fieldKey
82
82
83
83
e .registerConstMetricGauge (ch , "db_keys" , keysTotal , dbName )
84
84
e .registerConstMetricGauge (ch , "db_keys_expiring" , keysEx , dbName )
85
+ e .registerConstMetricGauge (ch , "db_keys_expired" , keysExpired , dbName )
85
86
86
87
if avgTTL > - 1 {
87
88
e .registerConstMetricGauge (ch , "db_avg_ttl_seconds" , avgTTL , dbName )
@@ -105,6 +106,7 @@ func (e *Exporter) extractInfoMetrics(ch chan<- prometheus.Metric, info string,
105
106
if _ , exists := handledDBs [dbName ]; ! exists {
106
107
e .registerConstMetricGauge (ch , "db_keys" , 0 , dbName )
107
108
e .registerConstMetricGauge (ch , "db_keys_expiring" , 0 , dbName )
109
+ e .registerConstMetricGauge (ch , "db_keys_expired" , 0 , dbName )
108
110
}
109
111
}
110
112
@@ -127,9 +129,11 @@ func (e *Exporter) extractInfoMetrics(ch chan<- prometheus.Metric, info string,
127
129
}
128
130
129
131
/*
130
- valid example: db0:keys=1,expires=0,avg_ttl=0
132
+ valid examples:
133
+ - db0:keys=1,expires=0,avg_ttl=0
134
+ - db0:keys=1,expires=10,avg_ttl=0,expired=2
131
135
*/
132
- func parseDBKeyspaceString (inputKey string , inputVal string ) (keysTotal float64 , keysExpiringTotal float64 , avgTTL float64 , ok bool ) {
136
+ func parseDBKeyspaceString (inputKey string , inputVal string ) (keysTotal float64 , keysExpiringTotal float64 , avgTTL float64 , keysExpiredTotal float64 , ok bool ) {
133
137
log .Debugf ("parseDBKeyspaceString inputKey: [%s] inputVal: [%s]" , inputKey , inputVal )
134
138
135
139
if ! strings .HasPrefix (inputKey , "db" ) {
@@ -138,7 +142,7 @@ func parseDBKeyspaceString(inputKey string, inputVal string) (keysTotal float64,
138
142
}
139
143
140
144
split := strings .Split (inputVal , "," )
141
- if len (split ) != 3 {
145
+ if len (split ) < 2 || len ( split ) > 4 {
142
146
log .Debugf ("parseDBKeyspaceString strings.Split(inputVal) invalid: %#v" , split )
143
147
return
144
148
}
@@ -162,6 +166,14 @@ func parseDBKeyspaceString(inputKey string, inputVal string) (keysTotal float64,
162
166
avgTTL /= 1000
163
167
}
164
168
169
+ keysExpiredTotal = 0
170
+ if len (split ) > 3 {
171
+ if keysExpiredTotal , err = extractVal (split [3 ]); err != nil {
172
+ log .Debugf ("parseDBKeyspaceString extractVal(split[3]) invalid, err: %s" , err )
173
+ return
174
+ }
175
+ }
176
+
165
177
ok = true
166
178
return
167
179
}
0 commit comments