-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmetrics-redis-graphite.rb
executable file
·100 lines (89 loc) · 2.56 KB
/
metrics-redis-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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env ruby
#
# Push Redis INFO stats into graphite
# ===
#
# Copyright 2012 Pete Shima <[email protected]>
# Brian Racer <[email protected]>
#
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
require 'sensu-plugin/metric/cli'
require 'redis'
require_relative '../lib/redis_client_options'
class Redis2Graphite < Sensu::Plugin::Metric::CLI::Graphite
include RedisClientOptions
# redis.c - sds genRedisInfoString(char *section)
SKIP_KEYS_REGEX = [
'^role',
'^slave',
'aof_last_bgrewrite_status',
'aof_last_write_status',
'arch_bits',
'config_file',
'executable',
'gcc_version',
'master_host',
'master_link_status',
'master_port',
'mem_allocator',
'multiplexing_api',
'maxmemory_human',
'maxmemory_policy',
'os',
'process_id',
'rdb_last_bgsave_status',
'redis_build_id',
'redis_git_dirty',
'redis_git_sha1',
'redis_mode',
'redis_version',
'run_id',
'tcp_port',
'total_system_memory_human',
'used_memory_human',
'used_memory_lua_human',
'used_memory_peak_human',
'used_memory_rss_human'
].freeze
option :scheme,
description: 'Metric naming scheme, text to prepend to metric',
short: '-S SCHEME',
long: '--scheme SCHEME',
default: "#{Socket.gethostname}.redis"
option :skip_keys_regex,
description: 'a comma seperated list of keys to be skipped',
short: '-k KEYS',
long: '--skipkeys KEYS',
default: nil
def run
redis = Redis.new(default_redis_options)
skip_keys = if !config[:skip_keys_regex].nil?
config[:skip_keys_regex].split(',')
else
SKIP_KEYS_REGEX
end
redis.info.each do |k, v|
next unless skip_keys.map { |re| k.match(/#{re}/) }.compact.empty?
# "db0"=>"keys=123,expires=12"
if k =~ /^db/
keys, expires = v.split(',')
keys.gsub!('keys=', '')
expires.gsub!('expires=', '')
output "#{config[:scheme]}.#{k}.keys", keys
output "#{config[:scheme]}.#{k}.expires", expires
else
output "#{config[:scheme]}.#{k}", v
end
end
# Loop thru commandstats entries for perf metrics
redis.info('commandstats').each do |k, v|
%w[calls usec_per_call usec].each do |x|
output "#{config[:scheme]}.commandstats.#{k}.#{x}", v[x]
end
end
ok
rescue StandardError
send(config[:conn_failure_status], "Could not connect to Redis server on #{redis_endpoint}")
end
end