Explore "limit_maxbytes" and "bytes" individually
This commit is contained in:
parent
039fc80ed7
commit
b86d789abe
|
@ -30,6 +30,8 @@ var sendAsIs = []string{
|
|||
"get_hits",
|
||||
"get_misses",
|
||||
"evictions",
|
||||
"limit_maxbytes",
|
||||
"bytes",
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
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() {
|
||||
plugins.Add("memcached", func() plugins.Plugin {
|
||||
return &Memcached{}
|
||||
|
|
|
@ -18,14 +18,9 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
|||
err := m.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
|
||||
intMetrics := []string{"get_hits", "get_misses", "evictions"}
|
||||
floatMetrics := []string{"usage"}
|
||||
intMetrics := []string{"get_hits", "get_misses", "evictions", "limit_maxbytes", "bytes"}
|
||||
|
||||
for _, metric := range intMetrics {
|
||||
assert.True(t, acc.HasIntValue(metric), metric)
|
||||
}
|
||||
|
||||
for _, metric := range floatMetrics {
|
||||
assert.True(t, acc.HasFloatValue(metric), metric)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue