Skip to content

Commit

Permalink
Merge pull request #166 from EriconYu/master
Browse files Browse the repository at this point in the history
add slow logs count
  • Loading branch information
oliver006 authored Jun 13, 2018
2 parents b1a4128 + c462618 commit ce489e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions exporter/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (e *Exporter) initGauges() {
Name: "command_call_duration_seconds_sum",
Help: "Total amount of time in seconds spent per command",
}, []string{"addr", "alias", "cmd"})
e.metrics["slowlog_lenth"] = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: e.namespace,
Name: "slowlog_lenth",
Help: "Total slowlog",
}, []string{"addr", "alias"})
}

// NewRedisExporter returns a new exporter of Redis metrics.
Expand Down Expand Up @@ -732,6 +737,12 @@ func (e *Exporter) scrapeRedisHost(scrapes chan<- scrapeResult, addr string, idx
}
}

if reply, err := c.Do("SLOWLOG", "LEN"); err == nil {
e.metricsMtx.RLock()
e.metrics["slowlog_lenth"].WithLabelValues(addr, e.redis.Aliases[idx]).Set(float64(reply.(int64)))
e.metricsMtx.RUnlock()
}

log.Debugf("scrapeRedisHost() done")
return nil
}
Expand Down
1 change: 1 addition & 0 deletions exporter/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func TestExporterMetrics(t *testing.T) {
"loading_dump_file", // testing renames
"config_maxmemory", // testing config extraction
"config_maxclients", // testing config extraction
"slowlog_lenth",
}

for _, k := range wantKeys {
Expand Down

0 comments on commit ce489e3

Please sign in to comment.