From adcc3f6e33f061f3bcd8aa6f2870ac0fc772195f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 23 Sep 2020 17:15:17 +0000 Subject: [PATCH] Configure SMART collector for prometheus --- cookbooks/hardware/metadata.rb | 1 + cookbooks/hardware/recipes/default.rb | 13 +++++++++++++ .../hardware/templates/default/smart.devices.erb | 9 +++++++++ 3 files changed, 23 insertions(+) create mode 100644 cookbooks/hardware/templates/default/smart.devices.erb diff --git a/cookbooks/hardware/metadata.rb b/cookbooks/hardware/metadata.rb index c7891e909..35dd20ed8 100644 --- a/cookbooks/hardware/metadata.rb +++ b/cookbooks/hardware/metadata.rb @@ -10,6 +10,7 @@ depends "apt" depends "chef" depends "git" depends "munin" +depends "prometheus" depends "ohai" depends "tools" depends "sysfs" diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index c5b5ac226..27046a1f7 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -20,6 +20,7 @@ include_recipe "apt" include_recipe "git" include_recipe "munin" +include_recipe "prometheus" include_recipe "sysfs" include_recipe "tools" @@ -450,6 +451,18 @@ if disks.count.positive? conf_variables :disk => disk end end + + template "/etc/prometheus/collectors/smart.devices" do + source "smart.devices.erb" + owner "root" + group "root" + mode "644" + variables :disks => disks + end + + prometheus_collector "smart" do + interval "15m" + end else service "smartd" do action [:stop, :disable] diff --git a/cookbooks/hardware/templates/default/smart.devices.erb b/cookbooks/hardware/templates/default/smart.devices.erb new file mode 100644 index 000000000..36498d74e --- /dev/null +++ b/cookbooks/hardware/templates/default/smart.devices.erb @@ -0,0 +1,9 @@ +<% @disks.each do |disk| -%> +<% if disk[:smart] -%> +/dev/<%= disk[:device] %>|<%= disk[:smart] %> +<% elsif disk[:device] =~ /nvme/ -%> +/dev/<%= disk[:device] %>|nvme +<% else -%> +/dev/<%= disk[:device] %>|sat +<% end -%> +<% end -%> -- 2.39.5