Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
graphite-redis : monitor redis statistics with graphite across several hosts
#!/usr/bin/env ruby
require 'socket'
# graphite/carbon settings
GRAPHITE_HOST="graphite.intra.local.ch"
GRAPHITE_PORT=8125
def instrument_redis(redis_host)
namespace = "#{redis_host}"
redis = {}
`/usr/bin/redis-cli -h #{redis_host} info`.each_line do |line|
# `redis-cli -h #{redis_host} info`.each_line do |line|
key,value = line.chomp.split(/:/)
redis[key]=value
end
%w{used_memory total_commands_processed
total_connections_received keyspace_hits
changes_since_last_save
connected_clients keyspace_misses expired_keys}.each do |item|
send_data("#{namespace}.#{item}", redis[item].to_i)
end
frag1000 = redis['mem_fragmentation_ratio'].to_f*1000;
send_data("#{namespace}.mem_fragmentation_ratio", frag1000)
end
def send_data(path, value, time=nil)
time ||= Time.new
msg = "#{path}:#{value}|c\n"
$stdout.puts msg
@socket.send(msg, 0, GRAPHITE_HOST, GRAPHITE_PORT)
msg
end
@socket = UDPSocket.new
instrument_redis('localhost')
@socket.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.