Skip to content

Instantly share code, notes, and snippets.

@bernd
Created April 2, 2012 08:23
Show Gist options
  • Save bernd/2281643 to your computer and use it in GitHub Desktop.
Save bernd/2281643 to your computer and use it in GitHub Desktop.
collectd redis metrics in ruby
LoadPlugin exec
<Plugin exec>
Exec "nobody:nogroup" "/path/to/collectd-redis.rb" "127.0.0.1" "6379"
</Plugin>
#!/usr/bin/env ruby
require 'redis'
require 'socket'
# See: http://www.collectd.org/documentation/manpages/collectd-exec.5.shtml
hostname = ENV['COLLECTD_HOSTNAME'] || Socket.gethostname
interval = ENV['COLLECTD_INTERVAL'] || 60
host = ARGV.shift
port = ARGV.shift
redis = Redis.new(:host => host, :port => port)
while sleep(interval) do
mem = redis.info['used_memory']
puts "PUTVAL #{hostname}/exec-redis/memory-redis0 interval=#{interval} N:#{mem}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment