Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Mar 15, 2020
2 parents c03fb49 + c74c73a commit 434fcf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
23 changes: 14 additions & 9 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,36 +550,40 @@ func parseClientListString(clientInfo string) (host string, port string, name st
/*
valid example: db0:keys=1,expires=0,avg_ttl=0
*/
func parseDBKeyspaceString(db string, stats string) (keysTotal float64, keysExpiringTotal float64, avgTTL float64, ok bool) {
ok = false
if !strings.HasPrefix(db, "db") {
func parseDBKeyspaceString(inputKey string, inputVal string) (keysTotal float64, keysExpiringTotal float64, avgTTL float64, ok bool) {
log.Debugf("parseDBKeyspaceString inputKey: [%s] inputVal: [%s]", inputKey, inputVal)

if !strings.HasPrefix(inputKey, "db") {
log.Debugf("parseDBKeyspaceString inputKey not starting with 'db': [%s]", inputKey)
return
}

split := strings.Split(stats, ",")
split := strings.Split(inputVal, ",")
if len(split) != 3 && len(split) != 2 {
log.Debugf("parseDBKeyspaceString strings.Split(inputVal) invalid: %#v", split)
return
}

var err error
ok = true
if keysTotal, err = extractVal(split[0]); err != nil {
ok = false
log.Debugf("parseDBKeyspaceString extractVal(split[0]) invalid, err: %s", err)
return
}
if keysExpiringTotal, err = extractVal(split[1]); err != nil {
ok = false
log.Debugf("parseDBKeyspaceString extractVal(split[1]) invalid, err: %s", err)
return
}

avgTTL = -1
if len(split) > 2 {
if avgTTL, err = extractVal(split[2]); err != nil {
ok = false
log.Debugf("parseDBKeyspaceString extractVal(split[2]) invalid, err: %s", err)
return
}
avgTTL /= 1000
}

ok = true
return
}

Expand Down Expand Up @@ -755,8 +759,9 @@ func (e *Exporter) extractInfoMetrics(ch chan<- prometheus.Metric, info string,
for _, line := range lines {
line = strings.TrimSpace(line)
log.Debugf("info: %s", line)
if len(line) > 0 && line[0] == '#' {
if len(line) > 0 && strings.HasPrefix(line, "# ") {
fieldClass = line[2:]
log.Debugf("set fieldClass: %s", fieldClass)
continue
}

Expand Down
3 changes: 1 addition & 2 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,9 +727,8 @@ func TestGetKeysFromPatterns(t *testing.T) {
})

if !reflect.DeepEqual(expectedKeys, expandedKeys) {
t.Errorf("When expanding keys:\nexpected: %v\nactual: %v", expectedKeys, expandedKeys)
t.Errorf("When expanding keys:\nexpected: %#v\nactual: %#v", expectedKeys, expandedKeys)
}

}

func TestGetKeyInfo(t *testing.T) {
Expand Down

0 comments on commit 434fcf8

Please sign in to comment.