forked from sensu/sensu-community-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcached-graphite.rb
executable file
·54 lines (45 loc) · 1.29 KB
/
memcached-graphite.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env ruby
#
# Push Memcached stats into graphite
#
# Dependencies
# -----------
# - Ruby gem `memcached`
#
# ===
#
# TODO: HitRatio percent and per second calculations
#
# Copyright 2012 Pete Shima <[email protected]>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/metric/cli'
require 'memcached'
require 'socket'
class MemcachedGraphite < Sensu::Plugin::Metric::CLI::Graphite
option :host,
:short => "-h HOST",
:long => "--host HOST",
:description => "Memcached Host to connect to",
:default => 'localhost'
option :port,
:short => "-p PORT",
:long => "--port PORT",
:description => "Memcached Port to connect to",
:proc => proc { |p| p.to_i },
:default => 11211
option :scheme,
:description => "Metric naming scheme, text to prepend to metric",
:short => "-s SCHEME",
:long => "--scheme SCHEME",
:default => "#{::Socket.gethostname}.memcached"
def run
cache = Memcached.new("#{config[:host]}:#{config[:port]}")
cache.stats.each do |k, v|
output "#{config[:scheme]}.#{k}", v
end
ok
end
end