Explore "limit_maxbytes" and "bytes" individually

This commit is contained in:
Maksim Naumov 2015-06-23 09:44:39 +02:00
parent 039fc80ed7
commit b86d789abe
2 changed files with 3 additions and 22 deletions

View File

@ -30,6 +30,8 @@ var sendAsIs = []string{
"get_hits", "get_hits",
"get_misses", "get_misses",
"evictions", "evictions",
"limit_maxbytes",
"bytes",
} }
// SampleConfig returns sample configuration message // SampleConfig returns sample configuration message
@ -122,25 +124,9 @@ func (m *Memcached) gatherServer(address string, acc plugins.Accumulator) error
} }
} }
} }
// Usage
acc.Add("usage", m.calcUsage(values), tags)
return nil return nil
} }
func (m *Memcached) calcUsage(values map[string]string) float64 {
maxBytes, maxOk := values["limit_maxbytes"]
bytes, bytesOk := values["bytes"]
if maxOk && bytesOk {
if fMax, errMax := strconv.ParseFloat(maxBytes, 64); errMax == nil && fMax > 0 {
if fBytes, errBytes := strconv.ParseFloat(bytes, 64); errBytes == nil {
return fBytes / fMax
}
}
}
return 0
}
func init() { func init() {
plugins.Add("memcached", func() plugins.Plugin { plugins.Add("memcached", func() plugins.Plugin {
return &Memcached{} return &Memcached{}

View File

@ -18,14 +18,9 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
err := m.Gather(&acc) err := m.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
intMetrics := []string{"get_hits", "get_misses", "evictions"} intMetrics := []string{"get_hits", "get_misses", "evictions", "limit_maxbytes", "bytes"}
floatMetrics := []string{"usage"}
for _, metric := range intMetrics { for _, metric := range intMetrics {
assert.True(t, acc.HasIntValue(metric), metric) assert.True(t, acc.HasIntValue(metric), metric)
} }
for _, metric := range floatMetrics {
assert.True(t, acc.HasFloatValue(metric), metric)
}
} }