This repository has been archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
redis_databases_
executable file
·54 lines (46 loc) · 1.57 KB
/
redis_databases_
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
require 'rubygems'
require 'redis'
require 'yaml'
redis_contructor_info = {}
configFilePath = File.join(File::SEPARATOR,"etc","munin","plugin-conf.d","redis.conf")
if (File.exists?(configFilePath))
redis_constructor_info = YAML.load(File.open(configFilePath))
else
$0 =~ /_(\d+_\d+_\d+_\d+)_(\d+)$/
ip, port = $1, $2
ip = ip.nil? ? '127.0.0.1' : ip.gsub!(/_/, '.')
port = port.nil? ? 6379 : port
redis_constructor_info = { :host => ip, :port => port, :password => "your_password" }
end
config = ARGV.any? { |a| a =~ /config/ }
infos = Redis.new(redis_constructor_info).info.inject({}) { |h, (k, v)| h[k] = v if k.to_s =~ /^db\d+/; h }.inject({}) { |hash, (dbnum, out)| out =~ /keys=(\d+),expires=(\d+)/; hash.update(dbnum => {:keys => $1.to_i, :expires => $2.to_i}) }
if config
puts "graph_title Redis Keys, port #{port}"
puts "graph_category redis"
puts "graph_info Display the number of keys by DB"
puts "graph_args -l 0"
area_done = false
infos.each_key do |db|
type = 'STACK'
if !area_done
type = 'AREA'
area_done = true
end
puts "#{db}_keys.label #{db}_keys"
puts "#{db}_keys.info db #{db}"
puts "#{db}_keys.type GAUGE"
puts "#{db}_keys.min 0"
puts "#{db}_keys.draw #{type}"
puts "#{db}_expires.label #{db}_expires"
puts "#{db}_expires.info db #{db}"
puts "#{db}_expires.type GAUGE"
puts "#{db}_expires.min 0"
puts "#{db}_expires.draw STACK"
end
else
infos.each do |db, infos|
puts "#{db}_keys.value #{infos[:keys]}"
puts "#{db}_expires.value #{infos[:expires]}"
end
end