Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memcached plugin #21

Merged
merged 2 commits into from
Jun 23, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Explore "limit_maxbytes" and "bytes" individually
  • Loading branch information
Maksim Naumov committed Jun 23, 2015
commit b86d789abe3f55ff611220fb87be12e42bc632dc
18 changes: 2 additions & 16 deletions plugins/memcached/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var sendAsIs = []string{
"get_hits",
"get_misses",
"evictions",
"limit_maxbytes",
"bytes",
}

// SampleConfig returns sample configuration message
Expand Down Expand Up @@ -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{}
Expand Down
7 changes: 1 addition & 6 deletions plugins/memcached/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}