From f963ff457182611c62036674840eb588b48fd704 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 13 Mar 2015 22:52:25 +0000 Subject: [PATCH] Update smart related munin plugins to handle all disks --- cookbooks/hardware/recipes/default.rb | 42 +++++++++++++++++++ .../templates/default/munin.hddtemp.erb | 10 +++++ .../templates/default/munin.smart.erb | 8 ++++ cookbooks/munin/recipes/default.rb | 29 ------------- cookbooks/munin/templates/default/hddtemp.erb | 4 -- cookbooks/munin/templates/default/smart.erb | 4 -- 6 files changed, 60 insertions(+), 37 deletions(-) create mode 100644 cookbooks/hardware/templates/default/munin.hddtemp.erb create mode 100644 cookbooks/hardware/templates/default/munin.smart.erb delete mode 100644 cookbooks/munin/templates/default/hddtemp.erb delete mode 100644 cookbooks/munin/templates/default/smart.erb diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 865578036..29a1fcd1e 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -353,6 +353,22 @@ if tools_packages.include?("areca") end end +disks.each do |disk| + if disk[:device] =~ /^cciss\/(.*)$/ + id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp + + disk[:munin] = "cciss-3#{id.downcase}" + else + disk[:munin] = disk[:device] + end + + if disk[:id] + disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}" + end + + disk[:hddtemp] = disk[:munin].tr("-:", "_") +end + if disks.count > 0 package "smartmontools" @@ -376,10 +392,36 @@ if disks.count > 0 service "smartmontools" do action [:enable, :start] end + + disks.each do |disk| + munin_plugin "smart_#{disk[:munin]}" do + target "smart_" + conf "munin.smart.erb" + conf_variables :disk => disk + end + end + + munin_plugin "hddtemp_smartctl" do + conf "munin.hddtemp.erb" + conf_variables :disks => disks + end else service "smartmontools" do action [:stop, :disable] end + + munin_plugin "hddtemp_smartctl" do + action :delete + end +end + +plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } - + disks.map { |d| "smart_#{d[:munin_name]}" } + +plugins.each do |plugin| + munin_plugin plugin do + action :delete + end end if File.exist?("/etc/mdadm/mdadm.conf") diff --git a/cookbooks/hardware/templates/default/munin.hddtemp.erb b/cookbooks/hardware/templates/default/munin.hddtemp.erb new file mode 100644 index 000000000..330be0630 --- /dev/null +++ b/cookbooks/hardware/templates/default/munin.hddtemp.erb @@ -0,0 +1,10 @@ +# DO NOT EDIT - This file is being maintained by Chef + +[hddtemp_smartctl] +env.drives <%= @disks.map { |d| d[:hddtemp] }.sort.join(" ") %> +<% @disks.sort_by { |d| d[:hddtemp] }.each do |disk| -%> +<% if disk[:driver] -%> +env.type_<%= disk[:hddtemp] %> <%= disk[:driver] %>,<%= disk[:id] %> +<% end -%> +env.dev_<%= disk[:hddtemp] %> <%= disk[:device] %> +<% end -%> diff --git a/cookbooks/hardware/templates/default/munin.smart.erb b/cookbooks/hardware/templates/default/munin.smart.erb new file mode 100644 index 000000000..8a09c838f --- /dev/null +++ b/cookbooks/hardware/templates/default/munin.smart.erb @@ -0,0 +1,8 @@ +# DO NOT EDIT - This file is being maintained by Chef + +[smart_<%= @disk[:munin] %>] +<% if @disk[:driver] -%> +env.smartargs -H -d <%= @disk[:driver] %>,<%= @disk[:id] %> +<% else -%> +env.smartargs -H +<% end -%> diff --git a/cookbooks/munin/recipes/default.rb b/cookbooks/munin/recipes/default.rb index 28c05006b..36ddd96b4 100644 --- a/cookbooks/munin/recipes/default.rb +++ b/cookbooks/munin/recipes/default.rb @@ -125,21 +125,6 @@ else end end -disks = node[:block_device].select do |_, attributes| - ["ATA", "FUJITSU", "SEAGATE", "DELL", "COMPAQ", "IBM-ESXS"].include?(attributes[:vendor]) -end - -if disks.empty? - munin_plugin "hddtemp_smartctl" do - action :delete - end -else - munin_plugin "hddtemp_smartctl" do - conf "hddtemp.erb" - conf_variables :disks => disks - end -end - if File.exist?("/sbin/hpasmcli") munin_plugin "hpasmcli2_temp" do target "hpasmcli2_" @@ -317,20 +302,6 @@ else end end -node[:block_device].each do |name, attributes| - if attributes[:vendor] == "ATA" - munin_plugin "smart_#{name}" do - target "smart_" - conf "smart.erb" - conf_variables :disk => name - end - else - munin_plugin "smart_#{name}" do - action :delete - end - end -end - munin_plugin "swap" munin_plugin "tcp" munin_plugin "threads" diff --git a/cookbooks/munin/templates/default/hddtemp.erb b/cookbooks/munin/templates/default/hddtemp.erb deleted file mode 100644 index 36a8bb5fb..000000000 --- a/cookbooks/munin/templates/default/hddtemp.erb +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef - -[hddtemp_smartctl] -env.drives <%= @disks.keys.sort.join(" ") %> diff --git a/cookbooks/munin/templates/default/smart.erb b/cookbooks/munin/templates/default/smart.erb deleted file mode 100644 index bcb813a21..000000000 --- a/cookbooks/munin/templates/default/smart.erb +++ /dev/null @@ -1,4 +0,0 @@ -# DO NOT EDIT - This file is being maintained by Chef - -[smart_<%= @disk %>] -env.smartargs -H -- 2.39.5