about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-01-18 20:49:27 +0100
committerLeah Neukirchen <leah@vuxu.org>2024-01-18 20:49:27 +0100
commit186bf1f894242c91e1877d3bfe11ae0623200450 (patch)
tree36881c0322a84746fe11dd8896cd21455b04960d
parent06743b7b4227a8613315eccf1a54c97e12d22fbf (diff)
downloadnitro-186bf1f894242c91e1877d3bfe11ae0623200450.tar.gz
nitro-186bf1f894242c91e1877d3bfe11ae0623200450.tar.xz
nitro-186bf1f894242c91e1877d3bfe11ae0623200450.zip
add contrib/nitro_exporter.rb
-rw-r--r--contrib/nitro_exporter.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/contrib/nitro_exporter.rb b/contrib/nitro_exporter.rb
new file mode 100644
index 0000000..eae3ba8
--- /dev/null
+++ b/contrib/nitro_exporter.rb
@@ -0,0 +1,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