riemann-tools 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/riemann-bench +8 -6
- data/bin/riemann-cloudant +58 -0
- data/bin/riemann-diskstats +86 -0
- data/bin/riemann-haproxy +52 -0
- data/bin/riemann-health +152 -50
- data/bin/riemann-kvminstance +22 -0
- data/bin/riemann-kvminstances +22 -0
- data/bin/riemann-redis +34 -0
- data/lib/riemann/tools.rb +10 -0
- metadata +39 -36
data/bin/riemann-bench
CHANGED
@@ -10,14 +10,16 @@ class Riemann::Bench
|
|
10
10
|
attr_accessor :client, :hosts, :services, :states
|
11
11
|
def initialize
|
12
12
|
@hosts = [nil] + (0...10).map { |i| "host#{i}" }
|
13
|
-
@hosts =
|
14
|
-
@services = %w(
|
13
|
+
@hosts = %w(a b c d e f g h i j)
|
14
|
+
@services = %w(test1 test2 test3 foo bar baz xyzzy attack cat treat)
|
15
15
|
@states = {}
|
16
16
|
@client = Riemann::Client.new(host: (ARGV.first || 'localhost'))
|
17
17
|
end
|
18
18
|
|
19
19
|
def evolve(state)
|
20
|
-
m = rand
|
20
|
+
m = state[:metric] + (rand - 0.5) * 0.1
|
21
|
+
m = [[0,m].max, 1].min
|
22
|
+
|
21
23
|
s = case m
|
22
24
|
when 0...0.75
|
23
25
|
'ok'
|
@@ -28,7 +30,7 @@ class Riemann::Bench
|
|
28
30
|
end
|
29
31
|
|
30
32
|
{
|
31
|
-
|
33
|
+
metric: m,
|
32
34
|
state: s,
|
33
35
|
host: state[:host],
|
34
36
|
service: state[:service],
|
@@ -46,7 +48,7 @@ class Riemann::Bench
|
|
46
48
|
def run
|
47
49
|
start
|
48
50
|
loop do
|
49
|
-
|
51
|
+
sleep 0.05
|
50
52
|
tick
|
51
53
|
end
|
52
54
|
end
|
@@ -54,7 +56,7 @@ class Riemann::Bench
|
|
54
56
|
def start
|
55
57
|
hosts.product(services).each do |host, service|
|
56
58
|
states[[host, service]] = {
|
57
|
-
|
59
|
+
metric: 0.5,
|
58
60
|
state: 'ok',
|
59
61
|
description: "Starting up",
|
60
62
|
host: host,
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Gathers load balancer statistics from Cloudant.com (shared cluster) and submits them to Riemann.
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
6
|
+
|
7
|
+
class Riemann::Tools::Cloudant
|
8
|
+
include Riemann::Tools
|
9
|
+
require 'net/http'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
opt :cloudant_username, "Cloudant username", :type => :string, :required => true
|
13
|
+
opt :cloudant_password, "Cloudant pasword", :type => :string, :required => true
|
14
|
+
|
15
|
+
def tick
|
16
|
+
json = JSON.parse(get_json().body)
|
17
|
+
json.each do |node|
|
18
|
+
return if node['svname'] == 'BACKEND' # this is just a sum of all nodes.
|
19
|
+
|
20
|
+
ns = "cloudant #{node['pxname']}"
|
21
|
+
cluster_name = node['tracked'].split('.')[0] # ie: meritage.cloudant.com
|
22
|
+
|
23
|
+
# report health of each node.
|
24
|
+
report(
|
25
|
+
:service => ns,
|
26
|
+
:state => (node['status'] == 'UP' ? 'ok' : 'critical'),
|
27
|
+
:tags => ['cloudant', cluster_name]
|
28
|
+
)
|
29
|
+
|
30
|
+
# report property->metric of each node.
|
31
|
+
node.each do |property, metric|
|
32
|
+
unless ['pxname', 'svname', 'status', 'tracked'].include?(property)
|
33
|
+
report(
|
34
|
+
:host => node['tracked'],
|
35
|
+
:service => "#{ns} #{property}",
|
36
|
+
:metric => metric.to_f,
|
37
|
+
:state => (node['status'] == 'UP' ? 'ok' : 'critical'),
|
38
|
+
:tags => ['cloudant', cluster_name]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_json
|
47
|
+
http = Net::HTTP.new('cloudant.com', 443)
|
48
|
+
http.use_ssl = true
|
49
|
+
http.start do |h|
|
50
|
+
get = Net::HTTP::Get.new('/api/load_balancer')
|
51
|
+
get.basic_auth opts[:cloudant_username], opts[:cloudant_password]
|
52
|
+
h.request get
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
Riemann::Tools::Cloudant.run
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
require 'rubygems'
|
4
|
+
require 'riemann/tools'
|
5
|
+
|
6
|
+
class Riemann::Tools::Diskstats
|
7
|
+
include Riemann::Tools
|
8
|
+
|
9
|
+
opt :devices, "Devices to monitor", :type => :strings, :default => nil
|
10
|
+
opt :ignore_devices, "Devices to ignore", :type => :strings, :default =>nil
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@old_state = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def state
|
17
|
+
f = File.read('/proc/diskstats')
|
18
|
+
state = f.split("\n").reject { |d| d =~ /(ram|loop)/ }.inject({}) do |s, line|
|
19
|
+
if line =~ /^(?:\s+\d+){2}\s+([\w\d]+) (.*)$/
|
20
|
+
dev = $1
|
21
|
+
|
22
|
+
['reads reqs',
|
23
|
+
'reads merged',
|
24
|
+
'reads sector',
|
25
|
+
'reads time',
|
26
|
+
'writes reqs',
|
27
|
+
'writes merged',
|
28
|
+
'writes sector',
|
29
|
+
'writes time',
|
30
|
+
'io reqs',
|
31
|
+
'io time',
|
32
|
+
'io weighted'
|
33
|
+
].map do |service|
|
34
|
+
"#{dev} #{service}"
|
35
|
+
end.zip(
|
36
|
+
$2.split(/\s+/).map { |str| str.to_i }
|
37
|
+
).each do |service, value|
|
38
|
+
s[service] = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
s
|
43
|
+
end
|
44
|
+
|
45
|
+
# Filter interfaces
|
46
|
+
if is = opts[:devices]
|
47
|
+
state = state.select do |service, value|
|
48
|
+
is.include? service.split(' ').first
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if ign = opts[:ignore_devices]
|
53
|
+
state = state.reject do |service, value|
|
54
|
+
ign.include? service.split(' ').first
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
state
|
59
|
+
end
|
60
|
+
|
61
|
+
def tick
|
62
|
+
state = self.state
|
63
|
+
|
64
|
+
if @old_state
|
65
|
+
state.each do |service, metric|
|
66
|
+
delta = metric - @old_state[service]
|
67
|
+
|
68
|
+
report(
|
69
|
+
:service => "diskstats " + service,
|
70
|
+
:metric => (delta.to_f / opts[:interval]),
|
71
|
+
:state => "ok"
|
72
|
+
)
|
73
|
+
|
74
|
+
if service =~ /io time$/
|
75
|
+
report(:service => "diskstats " + service.gsub(/time/, 'util'),
|
76
|
+
:metric => (delta.to_f / (opts[:interval]*1000)),
|
77
|
+
:state => "ok")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
@old_state = state
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
Riemann::Tools::Diskstats.run
|
data/bin/riemann-haproxy
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Gathers haproxy CSV statistics and submits them to Riemann.
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
6
|
+
|
7
|
+
class Riemann::Tools::Haproxy
|
8
|
+
include Riemann::Tools
|
9
|
+
require 'net/http'
|
10
|
+
require 'csv'
|
11
|
+
|
12
|
+
opt :stats_url, "Full url to haproxy stats (eg: https://user:password@host.com:9999/stats)", :required => true, :type => :string
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@uri = URI(opts[:stats_url]+';csv')
|
16
|
+
end
|
17
|
+
|
18
|
+
def tick
|
19
|
+
csv = CSV.parse(get_csv.body.split("# ")[1], { :headers => true })
|
20
|
+
csv.each do |row|
|
21
|
+
row = row.to_hash
|
22
|
+
ns = "haproxy #{row['pxname']} #{row['svname']}"
|
23
|
+
row.each do |property, metric|
|
24
|
+
unless property == 'pxname' || property == 'svname'
|
25
|
+
report(
|
26
|
+
:host => @uri.host,
|
27
|
+
:service => "#{ns} #{property}",
|
28
|
+
:metric => metric.to_f,
|
29
|
+
:state => (['UP', 'OPEN'].include?(row['status']) ? 'ok' : 'critical'),
|
30
|
+
:tags => ['haproxy']
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_csv
|
38
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
39
|
+
http.use_ssl = true if @uri.scheme == 'https'
|
40
|
+
http.start do |h|
|
41
|
+
get = Net::HTTP::Get.new(@uri.request_uri)
|
42
|
+
unless @uri.userinfo.nil?
|
43
|
+
userinfo = @uri.userinfo.split(":")
|
44
|
+
get.basic_auth userinfo[0], userinfo[1]
|
45
|
+
end
|
46
|
+
h.request get
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
Riemann::Tools::Haproxy.run
|
data/bin/riemann-health
CHANGED
@@ -6,7 +6,7 @@ require File.expand_path('../../lib/riemann/tools', __FILE__)
|
|
6
6
|
|
7
7
|
class Riemann::Tools::Health
|
8
8
|
include Riemann::Tools
|
9
|
-
|
9
|
+
|
10
10
|
opt :cpu_warning, "CPU warning threshold (fraction of total jiffies)", :default => 0.9
|
11
11
|
opt :cpu_critical, "CPU critical threshold (fraction of total jiffies)", :default => 0.95
|
12
12
|
opt :disk_warning, "Disk warning threshold (fraction of space used)", :default => 0.9
|
@@ -23,11 +23,33 @@ class Riemann::Tools::Health
|
|
23
23
|
:load => {:critical => opts[:load_critical], :warning => opts[:load_warning]},
|
24
24
|
:memory => {:critical => opts[:memory_critical], :warning => opts[:memory_warning]}
|
25
25
|
}
|
26
|
+
case (ostype = `uname -s`.chomp.downcase)
|
27
|
+
when 'darwin'
|
28
|
+
@cores = `sysctl -n hw.ncpu`.to_i
|
29
|
+
@cpu = method :darwin_cpu
|
30
|
+
@disk = method :disk
|
31
|
+
@load = method :darwin_load
|
32
|
+
@memory = method :darwin_memory
|
33
|
+
darwin_top
|
34
|
+
when 'freebsd'
|
35
|
+
@cores = `sysctl -n hw.ncpu`.to_i
|
36
|
+
@cpu = method :freebsd_cpu
|
37
|
+
@disk = method :disk
|
38
|
+
@load = method :freebsd_load
|
39
|
+
@memory = method :freebsd_memory
|
40
|
+
else
|
41
|
+
@cores = cores
|
42
|
+
puts "WARNING: OS '#{ostype}' not explicitly supported. Falling back to Linux" unless ostype == "linux"
|
43
|
+
@cpu = method :linux_cpu
|
44
|
+
@disk = method :disk
|
45
|
+
@load = method :linux_load
|
46
|
+
@memory = method :linux_memory
|
47
|
+
end
|
26
48
|
end
|
27
49
|
|
28
50
|
def alert(service, state, metric, description)
|
29
51
|
report(
|
30
|
-
:service => service,
|
52
|
+
:service => service.to_s,
|
31
53
|
:state => state.to_s,
|
32
54
|
:metric => metric.to_f,
|
33
55
|
:description => description
|
@@ -51,14 +73,26 @@ class Riemann::Tools::Health
|
|
51
73
|
end.size
|
52
74
|
end
|
53
75
|
|
54
|
-
def
|
76
|
+
def report_pct(service, fraction, report)
|
77
|
+
if fraction
|
78
|
+
if fraction > @limits[service][:critical]
|
79
|
+
alert service, :critical, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
80
|
+
elsif fraction > @limits[service][:warning]
|
81
|
+
alert service, :warning, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
82
|
+
else
|
83
|
+
alert service, :ok, fraction, "#{sprintf("%.2f", fraction * 100)}% #{report}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def linux_cpu
|
55
89
|
new = File.read('/proc/stat')
|
56
90
|
unless new[/cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/]
|
57
91
|
alert 'cpu', :unknown, nil, "/proc/stat doesn't include a CPU line"
|
58
92
|
return false
|
59
93
|
end
|
60
94
|
u2, n2, s2, i2 = [$1, $2, $3, $4].map { |e| e.to_i }
|
61
|
-
|
95
|
+
|
62
96
|
if @old_cpu
|
63
97
|
u1, n1, s1, i1 = @old_cpu
|
64
98
|
|
@@ -66,41 +100,14 @@ class Riemann::Tools::Health
|
|
66
100
|
total = used + i2-i1
|
67
101
|
fraction = used.to_f / total
|
68
102
|
|
69
|
-
|
70
|
-
alert "cpu", :critical, fraction, "#{sprintf("%.2f", fraction * 100)}% user+nice+sytem\n\n#{cpu_report}"
|
71
|
-
elsif fraction > @limits[:cpu][:warning]
|
72
|
-
alert "cpu", :warning, fraction, "#{sprintf("%.2f", fraction * 100)}% user+nice+sytem\n\n#{cpu_report}"
|
73
|
-
else
|
74
|
-
alert "cpu", :ok, fraction, "#{sprintf("%.2f", fraction * 100)}% user+nice+sytem\n\n#{cpu_report}"
|
75
|
-
end
|
103
|
+
report_pct :cpu, fraction, "user+nice+sytem\n\n#{`ps -eo pcpu,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
76
104
|
end
|
77
|
-
|
78
|
-
@old_cpu = [u2, n2, s2, i2]
|
79
|
-
end
|
80
105
|
|
81
|
-
|
82
|
-
`ps -eo pcpu,pid,args | sort -nrb -k1 | head -10`.chomp
|
106
|
+
@old_cpu = [u2, n2, s2, i2]
|
83
107
|
end
|
84
108
|
|
85
|
-
def
|
86
|
-
|
87
|
-
f = r.split(/\s+/)
|
88
|
-
next unless f[0] =~ /^\//
|
89
|
-
next if f[0] == 'Filesystem'
|
90
|
-
x = f[4].to_f/100
|
91
|
-
|
92
|
-
if x > @limits[:disk][:critical]
|
93
|
-
alert "disk #{f[5]}", :critical, x, "#{f[4]} used"
|
94
|
-
elsif x > @limits[:disk][:warning]
|
95
|
-
alert "disk #{f[5]}", :warning, x, "#{f[4]} used"
|
96
|
-
else
|
97
|
-
alert "disk #{f[5]}", :ok, x, "#{f[4]} used"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def load
|
103
|
-
load = File.read('/proc/loadavg').split(/\s+/)[2].to_f / cores
|
109
|
+
def linux_load
|
110
|
+
load = File.read('/proc/loadavg').split(/\s+/)[2].to_f / @cores
|
104
111
|
if load > @limits[:load][:critical]
|
105
112
|
alert "load", :critical, load, "15-minute load average/core is #{load}"
|
106
113
|
elsif load > @limits[:load][:warning]
|
@@ -110,7 +117,7 @@ class Riemann::Tools::Health
|
|
110
117
|
end
|
111
118
|
end
|
112
119
|
|
113
|
-
def
|
120
|
+
def linux_memory
|
114
121
|
m = File.read('/proc/meminfo').split(/\n/).inject({}) { |info, line|
|
115
122
|
x = line.split(/:?\s+/)
|
116
123
|
# Assume kB...
|
@@ -118,29 +125,124 @@ class Riemann::Tools::Health
|
|
118
125
|
info
|
119
126
|
}
|
120
127
|
|
121
|
-
free = m['MemFree'] + m['Buffers'] + m['Cached']
|
122
|
-
total = m['MemTotal']
|
128
|
+
free = m['MemFree'].to_i + m['Buffers'].to_i + m['Cached'].to_i
|
129
|
+
total = m['MemTotal'].to_i
|
123
130
|
fraction = 1 - (free.to_f / total)
|
124
131
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
132
|
+
report_pct :memory, fraction, "used\n\n#{`ps -eo pmem,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
133
|
+
end
|
134
|
+
|
135
|
+
def freebsd_cpu
|
136
|
+
u2, n2, s2, t2, i2 = `sysctl -n kern.cp_time 2>/dev/null`.split.map{ |e| e.to_i } #FreeBSD has 5 cpu stats
|
137
|
+
|
138
|
+
if @old_cpu
|
139
|
+
u1, n1, s1, t1, i1 = @old_cpu
|
140
|
+
|
141
|
+
used = (u2+n2+s2+t2) - (u1+n1+s1+t1)
|
142
|
+
total = used + i2-i1
|
143
|
+
fraction = used.to_f / total
|
144
|
+
|
145
|
+
report_pct :cpu, fraction, "user+nice+sytem+interrupt\n\n#{`ps -axo pcpu,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
146
|
+
end
|
147
|
+
|
148
|
+
@old_cpu = [u2, n2, s2, t2, i2]
|
149
|
+
end
|
150
|
+
|
151
|
+
def freebsd_load
|
152
|
+
m = `uptime`.split[-1].match(/^[0-9]*\.[0-9]*$/)
|
153
|
+
load = m[0].to_f / @cores
|
154
|
+
if load > @limits[:load][:critical]
|
155
|
+
alert "load", :critical, load, "15-minute load average/core is #{load}"
|
156
|
+
elsif load > @limits[:load][:warning]
|
157
|
+
alert "load", :warning, load, "15-minute load average/core is #{load}"
|
129
158
|
else
|
130
|
-
alert "
|
159
|
+
alert "load", :ok, load, "15-minute load average/core is #{load}"
|
131
160
|
end
|
132
161
|
end
|
133
162
|
|
134
|
-
def
|
135
|
-
|
163
|
+
def freebsd_memory
|
164
|
+
meminfo = `sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_wire_count vm.stats.vm.v_active_count 2>/dev/null`.chomp.split
|
165
|
+
fraction = (meminfo[1].to_f + meminfo[2].to_f) / meminfo[0].to_f
|
166
|
+
|
167
|
+
report_pct :memory, fraction, "used\n\n#{`ps -axo pmem,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
168
|
+
end
|
169
|
+
|
170
|
+
def darwin_top
|
171
|
+
raw = `top -l 1 | grep -i "^\\(cpu\\|physmem\\|load\\)"`.chomp
|
172
|
+
@topdata = {:stamp => Time.now.to_i }
|
173
|
+
raw.each_line do |ln|
|
174
|
+
if ln.match(/Load Avg: [0-9.]+, [0-9.]+, ([0-9.])+/i)
|
175
|
+
@topdata[:load] = $1.to_f
|
176
|
+
elsif ln.match(/CPU usage: [0-9.]+% user, [0-9.]+% sys, ([0-9.]+)% idle/i)
|
177
|
+
@topdata[:cpu] = 1 - ($1.to_f / 100)
|
178
|
+
elsif mdat = ln.match(/PhysMem: ([0-9]+)([BKMGT]) wired, ([0-9]+)([BKMGT]) active, ([0-9]+)([BKMGT]) inactive, ([0-9]+)([BKMGT]) used, ([0-9]+)([BKMGT]) free/i)
|
179
|
+
wired = mdat[1].to_i * (1024 ** "BKMGT".index(mdat[2]))
|
180
|
+
active = mdat[3].to_i * (1024 ** "BKMGT".index(mdat[4]))
|
181
|
+
inactive = mdat[5].to_i * (1024 ** "BKMGT".index(mdat[6]))
|
182
|
+
used = mdat[7].to_i * (1024 ** "BKMGT".index(mdat[8]))
|
183
|
+
free = mdat[9].to_i * (1024 ** "BKMGT".index(mdat[10]))
|
184
|
+
@topdata[:memory] = (wired + active + used).to_f / (wired + active + used + inactive + free)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def darwin_cpu
|
190
|
+
darwin_top unless (Time.now.to_i - @topdata[:stamp]) < opts[:interval]
|
191
|
+
unless @topdata[:cpu]
|
192
|
+
alert 'cpu', :unknown, nil, "unable to get CPU stats from top"
|
193
|
+
return false
|
194
|
+
end
|
195
|
+
report_pct :cpu, @topdata[:cpu], "usage\n\n#{`ps -eo pcpu,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
196
|
+
end
|
197
|
+
|
198
|
+
def darwin_load
|
199
|
+
darwin_top unless (Time.now.to_i - @topdata[:stamp]) < opts[:interval]
|
200
|
+
unless @topdata[:load]
|
201
|
+
alert 'load', :unknown, nil, "unable to get load ave from top"
|
202
|
+
return false
|
203
|
+
end
|
204
|
+
metric = @topdata[:load] / @cores
|
205
|
+
if metric > @limits[:load][:critical]
|
206
|
+
alert "load", :critical, metric, "15-minute load average per core is #{metric}"
|
207
|
+
elsif metric > @limits[:load][:warning]
|
208
|
+
alert "load", :warning, metric, "15-minute load average per core is #{metric}"
|
209
|
+
else
|
210
|
+
alert "load", :ok, metric, "15-minute load average per core is #{metric}"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def darwin_memory
|
215
|
+
darwin_top unless (Time.now.to_i - @topdata[:stamp]) < opts[:interval]
|
216
|
+
unless @topdata[:memory]
|
217
|
+
alert 'memory', :unknown, nil, "unable to get memory data from top"
|
218
|
+
return false
|
219
|
+
end
|
220
|
+
report_pct :memory, @topdata[:memory], "usage\n\n#{`ps -eo pmem,pid,comm | sort -nrb -k1 | head -10`.chomp}"
|
221
|
+
end
|
222
|
+
|
223
|
+
def disk
|
224
|
+
`df -P`.split(/\n/).each do |r|
|
225
|
+
f = r.split(/\s+/)
|
226
|
+
next unless f[0] =~ /^\//
|
227
|
+
next if f[0] == 'Filesystem'
|
228
|
+
x = f[4].to_f/100
|
229
|
+
|
230
|
+
if x > @limits[:disk][:critical]
|
231
|
+
alert "disk #{f[5]}", :critical, x, "#{f[4]} used"
|
232
|
+
elsif x > @limits[:disk][:warning]
|
233
|
+
alert "disk #{f[5]}", :warning, x, "#{f[4]} used"
|
234
|
+
else
|
235
|
+
alert "disk #{f[5]}", :ok, x, "#{f[4]} used"
|
236
|
+
end
|
237
|
+
end
|
136
238
|
end
|
137
239
|
|
138
240
|
def tick
|
139
|
-
cpu
|
140
|
-
memory
|
141
|
-
|
142
|
-
|
241
|
+
@cpu.call
|
242
|
+
@memory.call
|
243
|
+
@disk.call
|
244
|
+
@load.call
|
143
245
|
end
|
144
246
|
end
|
145
|
-
|
247
|
+
|
146
248
|
Riemann::Tools::Health.run
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
4
|
+
|
5
|
+
class Riemann::Tools::KVM
|
6
|
+
include Riemann::Tools
|
7
|
+
|
8
|
+
def tick
|
9
|
+
|
10
|
+
#determine how many instances I have according to libvirt
|
11
|
+
kvm_instances = %x[virsh list |grep i-|wc -l]
|
12
|
+
|
13
|
+
#submit them to riemann
|
14
|
+
report(
|
15
|
+
:service => "KVM Running VMs",
|
16
|
+
:metric => kvm_instances.to_i,
|
17
|
+
:state => "info"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Riemann::Tools::KVM.run
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
4
|
+
|
5
|
+
class Riemann::Tools::KVM
|
6
|
+
include Riemann::Tools
|
7
|
+
|
8
|
+
def tick
|
9
|
+
|
10
|
+
#determine how many instances I have according to libvirt
|
11
|
+
kvm_instances = %x[virsh list |grep i-|wc -l]
|
12
|
+
|
13
|
+
#submit them to riemann
|
14
|
+
report(
|
15
|
+
:service => "KVM Running VMs",
|
16
|
+
:metric => kvm_instances.to_i,
|
17
|
+
:state => "info"
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Riemann::Tools::KVM.run
|
data/bin/riemann-redis
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Gathers redis INFO statistics and submits them to Riemann.
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/riemann/tools', __FILE__)
|
6
|
+
|
7
|
+
class Riemann::Tools::Redis
|
8
|
+
include Riemann::Tools
|
9
|
+
require 'redis'
|
10
|
+
|
11
|
+
opt :redis_host, "Redis hostname", :default => 'localhost'
|
12
|
+
opt :redis_port, "Redis port", :default => 6379
|
13
|
+
opt :redis_password, "Redis password", :default => ''
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@redis = ::Redis.new(:host => opts[:redis_host], :port => opts[:redis_port])
|
17
|
+
@redis.auth(opts[:redis_password]) unless opts[:redis_password] == ''
|
18
|
+
end
|
19
|
+
|
20
|
+
def tick
|
21
|
+
@redis.info.each do |property, value|
|
22
|
+
report(
|
23
|
+
:host => opts[:redis_host],
|
24
|
+
:service => "redis #{property}",
|
25
|
+
:metric => value.to_f,
|
26
|
+
:state => 'ok',
|
27
|
+
:tags => ['redis']
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
Riemann::Tools::Redis.run
|
data/lib/riemann/tools.rb
CHANGED
@@ -29,6 +29,8 @@ module Riemann
|
|
29
29
|
opt :host, "Riemann host", :default => '127.0.0.1'
|
30
30
|
opt :port, "Riemann port", :default => 5555
|
31
31
|
opt :interval, "Seconds between updates", :default => 5
|
32
|
+
opt :tag, "Tag to add to events", :type => String, :multi => true
|
33
|
+
opt :ttl, "TTL for events", :type => Integer
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -52,6 +54,14 @@ module Riemann
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def report(event)
|
57
|
+
if options[:tag]
|
58
|
+
event[:tags] = options[:tag]
|
59
|
+
end
|
60
|
+
|
61
|
+
if options[:ttl]
|
62
|
+
event[:ttl] = options[:ttl]
|
63
|
+
end
|
64
|
+
|
55
65
|
riemann << event
|
56
66
|
end
|
57
67
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riemann-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,27 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: riemann-client
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &10179640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.0.
|
21
|
+
version: 0.0.8
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.0.7
|
24
|
+
version_requirements: *10179640
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: trollop
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &10178820 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,15 +32,10 @@ dependencies:
|
|
37
32
|
version: 1.16.2
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.16.2
|
35
|
+
version_requirements: *10178820
|
46
36
|
- !ruby/object:Gem::Dependency
|
47
37
|
name: munin-ruby
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &10177620 !ruby/object:Gem::Requirement
|
49
39
|
none: false
|
50
40
|
requirements:
|
51
41
|
- - ! '>='
|
@@ -53,15 +43,10 @@ dependencies:
|
|
53
43
|
version: 0.2.1
|
54
44
|
type: :runtime
|
55
45
|
prerelease: false
|
56
|
-
version_requirements:
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ! '>='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.2.1
|
46
|
+
version_requirements: *10177620
|
62
47
|
- !ruby/object:Gem::Dependency
|
63
48
|
name: yajl-ruby
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirement: &10176660 !ruby/object:Gem::Requirement
|
65
50
|
none: false
|
66
51
|
requirements:
|
67
52
|
- - ! '>='
|
@@ -69,33 +54,51 @@ dependencies:
|
|
69
54
|
version: 1.1.0
|
70
55
|
type: :runtime
|
71
56
|
prerelease: false
|
72
|
-
version_requirements:
|
57
|
+
version_requirements: *10176660
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: redis
|
60
|
+
requirement: &10606920 !ruby/object:Gem::Requirement
|
73
61
|
none: false
|
74
62
|
requirements:
|
75
63
|
- - ! '>='
|
76
64
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
65
|
+
version: 3.0.2
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *10606920
|
78
69
|
description:
|
79
70
|
email: aphyr@aphyr.com
|
80
71
|
executables:
|
81
|
-
- riemann-net
|
82
|
-
- riemann-riak-ring
|
83
|
-
- riemann-riak-keys
|
84
72
|
- riemann-munin
|
85
|
-
- riemann-riak
|
86
73
|
- riemann-bench
|
74
|
+
- riemann-riak
|
87
75
|
- riemann-health
|
76
|
+
- riemann-haproxy
|
77
|
+
- riemann-riak-keys
|
78
|
+
- riemann-diskstats
|
79
|
+
- riemann-riak-ring
|
80
|
+
- riemann-cloudant
|
81
|
+
- riemann-kvminstances
|
82
|
+
- riemann-kvminstance
|
83
|
+
- riemann-net
|
84
|
+
- riemann-redis
|
88
85
|
extensions: []
|
89
86
|
extra_rdoc_files: []
|
90
87
|
files:
|
91
88
|
- lib/riemann/tools.rb
|
92
|
-
- bin/riemann-net
|
93
|
-
- bin/riemann-riak-ring
|
94
|
-
- bin/riemann-riak-keys
|
95
89
|
- bin/riemann-munin
|
96
|
-
- bin/riemann-riak
|
97
90
|
- bin/riemann-bench
|
91
|
+
- bin/riemann-riak
|
98
92
|
- bin/riemann-health
|
93
|
+
- bin/riemann-haproxy
|
94
|
+
- bin/riemann-riak-keys
|
95
|
+
- bin/riemann-diskstats
|
96
|
+
- bin/riemann-riak-ring
|
97
|
+
- bin/riemann-cloudant
|
98
|
+
- bin/riemann-kvminstances
|
99
|
+
- bin/riemann-kvminstance
|
100
|
+
- bin/riemann-net
|
101
|
+
- bin/riemann-redis
|
99
102
|
- LICENSE
|
100
103
|
- README.markdown
|
101
104
|
homepage: https://github.com/aphyr/riemann-tools
|
@@ -118,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
121
|
version: '0'
|
119
122
|
requirements: []
|
120
123
|
rubyforge_project: riemann-tools
|
121
|
-
rubygems_version: 1.8.
|
124
|
+
rubygems_version: 1.8.10
|
122
125
|
signing_key:
|
123
126
|
specification_version: 3
|
124
127
|
summary: Utilities which submit events to Riemann.
|