]> git.openstreetmap.org Git - chef.git/commitdiff
Add munin plugin to monitor chef node status
authorTom Hughes <tom@compton.nu>
Wed, 16 Sep 2015 23:11:20 +0000 (00:11 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 16 Sep 2015 23:11:20 +0000 (00:11 +0100)
cookbooks/chef/metadata.rb
cookbooks/chef/recipes/server.rb
cookbooks/munin/files/default/plugin-conf.d/chef [new file with mode: 0644]
cookbooks/munin/files/default/plugins/chef_status [new file with mode: 0755]

index 08f2c330e8871ea46489fe91a16e4d89a91a25fe..8db6f1bb96f4ced45cbea075b8ee095cb386fe6c 100644 (file)
@@ -9,3 +9,4 @@ depends           "apache"
 depends           "apt"
 depends           "git"
 depends           "ohai"
+depends           "munin"
index 54efa19e5531de7738b8da929117a40d6ee340be..31e7d13584fbcb8c2fdf14a10ed57c74372ec26d 100644 (file)
@@ -91,3 +91,5 @@ template "/etc/logrotate.d/chef-server" do
   group "root"
   mode 0644
 end
+
+munin_plugin "chef_status"
diff --git a/cookbooks/munin/files/default/plugin-conf.d/chef b/cookbooks/munin/files/default/plugin-conf.d/chef
new file mode 100644 (file)
index 0000000..33beecc
--- /dev/null
@@ -0,0 +1,2 @@
+[chef_*]
+user chefrepo
diff --git a/cookbooks/munin/files/default/plugins/chef_status b/cookbooks/munin/files/default/plugins/chef_status
new file mode 100755 (executable)
index 0000000..9d4c742
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/ruby
+
+require "json"
+
+nodes = JSON.parse(IO.popen(["knife", "status", "-c", "/var/lib/chef/.chef/knife.rb", "-F", "json"]).read).sort_by { |node| node["name"] }
+
+if ARGV[0] == "config"
+  puts "graph_title Chef node status"
+  puts "graph_args --base 1000 --logarithmic"
+  puts "graph_vlabel Time since last checkin"
+  puts "graph_category chef"
+
+  nodes.each do |node|
+    name = node["name"].split(".").first
+
+    puts "#{name}.label #{name}"
+    puts "#{name}.type GAUGE"
+    puts "#{name}.min 0"
+    puts "#{name}.warning 14400"
+    puts "#{name}.critical 43200"
+  end
+else
+  nodes.each do |node|
+    name = node["name"].split(".").first
+    time = Time.now.to_f - node["ohai_time"]
+
+    puts "#{name}.value #{time}"
+  end
+end