]> git.openstreetmap.org Git - chef.git/commitdiff
Configure SMART collector for prometheus
authorTom Hughes <tom@compton.nu>
Wed, 23 Sep 2020 17:15:17 +0000 (17:15 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 23 Sep 2020 18:07:38 +0000 (19:07 +0100)
cookbooks/hardware/metadata.rb
cookbooks/hardware/recipes/default.rb
cookbooks/hardware/templates/default/smart.devices.erb [new file with mode: 0644]

index c7891e90939d5a19c71c2476cbc4ae5c732e83bf..35dd20ed892a9a55a7e223493ec07e752bfe0203 100644 (file)
@@ -10,6 +10,7 @@ depends           "apt"
 depends           "chef"
 depends           "git"
 depends           "munin"
+depends           "prometheus"
 depends           "ohai"
 depends           "tools"
 depends           "sysfs"
index c5b5ac226ef6d42c51a9c717d5e347ea0660da7f..27046a1f78c3e5fa067ad2fd644f2d6520f94d4c 100644 (file)
@@ -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 (file)
index 0000000..36498d7
--- /dev/null
@@ -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 -%>