Skip to content

Commit 4ff5d5f

Browse files
committedJun 30, 2008
added adam jacob's munin-to-graphite script
1 parent dfe9f17 commit 4ff5d5f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
 

‎contrib/munin-graphite.rb

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env ruby
2+
#
3+
# Written by Adam Jacob <adam@hjksolutions.com>
4+
#
5+
# The latest version is available at:
6+
#
7+
# http://github.com/adamhjk/munin-graphite/tree/master/munin-graphite.rb
8+
9+
require 'socket'
10+
11+
class Munin
12+
def initialize(host='localhost', port=4949)
13+
@munin = TCPSocket.new(host, port)
14+
@munin.gets
15+
end
16+
17+
def get_response(cmd)
18+
@munin.puts(cmd)
19+
stop = false
20+
response = Array.new
21+
while stop == false
22+
line = @munin.gets
23+
line.chomp!
24+
if line == '.'
25+
stop = true
26+
else
27+
response << line
28+
stop = true if cmd == "list"
29+
end
30+
end
31+
response
32+
end
33+
34+
def close
35+
@munin.close
36+
end
37+
end
38+
39+
class Carbon
40+
def initialize(host='localhost', port=2003)
41+
@carbon = TCPSocket.new(host, port)
42+
end
43+
44+
def send(msg)
45+
@carbon.puts(msg)
46+
end
47+
48+
def close
49+
@carbon.close
50+
end
51+
end
52+
53+
while true
54+
metric_base = "servers."
55+
all_metrics = Array.new
56+
57+
munin = Munin.new(ARGV[0])
58+
munin.get_response("nodes").each do |node|
59+
metric_base << node.split(".").reverse.join(".")
60+
puts "Doing #{metric_base}"
61+
munin.get_response("list")[0].split(" ").each do |metric|
62+
puts "Grabbing #{metric}"
63+
mname = "#{metric_base}"
64+
has_category = false
65+
base = false
66+
munin.get_response("config #{metric}").each do |configline|
67+
if configline =~ /graph_category (.+)/
68+
mname << ".#{$1}"
69+
has_category = true
70+
end
71+
if configline =~ /graph_args.+--base (\d+)/
72+
base = $1
73+
end
74+
end
75+
mname << ".other" unless has_category
76+
munin.get_response("fetch #{metric}").each do |line|
77+
line =~ /^(.+)\.value\s+(.+)$/
78+
field = $1
79+
value = $2
80+
all_metrics << "#{mname}.#{metric}.#{field} #{value} #{Time.now.to_i}"
81+
end
82+
end
83+
end
84+
85+
carbon = Carbon.new(ARGV[1])
86+
all_metrics.each do |m|
87+
puts "Sending #{m}"
88+
carbon.send(m)
89+
end
90+
sleep 60
91+
end
92+

0 commit comments

Comments
 (0)
Please sign in to comment.