]> git.openstreetmap.org Git - chef.git/commitdiff
Add support for monitoring files with filestat_exporter
authorTom Hughes <tom@compton.nu>
Wed, 17 Nov 2021 08:31:12 +0000 (08:31 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 17 Nov 2021 08:46:39 +0000 (08:46 +0000)
cookbooks/prometheus/attributes/default.rb
cookbooks/prometheus/recipes/default.rb
cookbooks/prometheus/templates/default/filestat.yml.erb [new file with mode: 0644]

index dba44a6b13ff739d98e54911b95d3554134fae64..a239c6a198b85dd30789eb4146e25b53cec6bae7 100644 (file)
@@ -2,6 +2,7 @@ default[:prometheus][:addresses] = {}
 default[:prometheus][:exporters] = {}
 default[:prometheus][:snmp] = {}
 default[:prometheus][:metrics] = {}
+default[:prometheus][:files] = []
 
 if node[:recipes].include?("prometheus::server")
   default[:apt][:sources] |= ["grafana"]
index 6e88362a40ba80bb8dc009b7886c832d474afc1f..85c5ec3129363a7da21b5bc0ff07f5198043911a 100644 (file)
@@ -121,3 +121,26 @@ unless node[:prometheus][:snmp].empty?
     register_target false
   end
 end
+
+if node[:prometheus][:files].empty?
+  prometheus_exporter "filestat" do
+    action :delete
+  end
+
+  file "/etc/prometheus/filestat.yml" do
+    action :delete
+  end
+else
+  template "/etc/prometheus/filestat.yml" do
+    source "filestat.yml.erb"
+    owner "root"
+    group "root"
+    mode "644"
+  end
+
+  prometheus_exporter "filestat" do
+    port 9943
+    options "--config.file=/etc/prometheus/filestat.yml"
+    subscribes :restart, "template[/etc/prometheus/filestat.yml]"
+  end
+end
diff --git a/cookbooks/prometheus/templates/default/filestat.yml.erb b/cookbooks/prometheus/templates/default/filestat.yml.erb
new file mode 100644 (file)
index 0000000..f77ecab
--- /dev/null
@@ -0,0 +1,6 @@
+exporter:
+  files:
+    - patterns:
+<% node[:prometheus][:files].each do |file| -%>
+        - <%= file %>
+<% end -%>