From d6aa4663cf978ed6db3e34c8c7d63dc13b430305 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 17 Sep 2015 00:11:20 +0100 Subject: [PATCH] Add munin plugin to monitor chef node status --- cookbooks/chef/metadata.rb | 1 + cookbooks/chef/recipes/server.rb | 2 ++ .../munin/files/default/plugin-conf.d/chef | 2 ++ .../munin/files/default/plugins/chef_status | 29 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 cookbooks/munin/files/default/plugin-conf.d/chef create mode 100755 cookbooks/munin/files/default/plugins/chef_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 -- 2.43.2