From: Tom Hughes Date: Wed, 16 Sep 2015 23:11:20 +0000 (+0100) Subject: Add munin plugin to monitor chef node status X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/d6aa4663cf978ed6db3e34c8c7d63dc13b430305?ds=inline Add munin plugin to monitor chef node status --- diff --git a/cookbooks/chef/metadata.rb b/cookbooks/chef/metadata.rb index 08f2c330e..8db6f1bb9 100644 --- a/cookbooks/chef/metadata.rb +++ b/cookbooks/chef/metadata.rb @@ -9,3 +9,4 @@ depends "apache" depends "apt" depends "git" depends "ohai" +depends "munin" diff --git a/cookbooks/chef/recipes/server.rb b/cookbooks/chef/recipes/server.rb index 54efa19e5..31e7d1358 100644 --- a/cookbooks/chef/recipes/server.rb +++ b/cookbooks/chef/recipes/server.rb @@ -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 index 000000000..33beeccbc --- /dev/null +++ b/cookbooks/munin/files/default/plugin-conf.d/chef @@ -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 index 000000000..9d4c742fc --- /dev/null +++ b/cookbooks/munin/files/default/plugins/chef_status @@ -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