blob: eae3ba8580d632697e484429e89ad8f44861733b (
plain) (
blame)
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
|
#!/usr/bin/ruby
# nitro_exporter - Prometheus exporter for nitro state
require 'rack'
require 'rack/handler/thin'
class NitroExporter
HOSTNAME = `hostname -f`.strip
def call(env)
r = Rack::Response.new
r.content_type = 'text/plain'
state = `nitroctl`
if $?.exitstatus != 0
r.write %Q|nitro_up{hostname=#{HOSTNAME.dump}} 0\n|
else
r.write %Q|nitro_up{hostname=#{HOSTNAME.dump}} 1\n|
state.each_line { |line|
case line
when /^([A-Z]+) (.*?) (\(pid \d+\) )?\(wstatus (\d+)\) (\d+)s$/
r.write %Q|nitro_state{hostname=#{HOSTNAME.dump},service=#{$2.dump},state=#{$1.dump}} #{$5}\n|
r.write %Q|nitro_wstatus{hostname=#{HOSTNAME.dump},service=#{$2.dump}} #{$4}\n| if $4
end
}
end
r.finish
end
end
if __FILE__ == $0
Rack::Handler::Thin.run(NitroExporter.new, :Port => 9007, :Host => '::')
end
|