From 4d58dbbf44ec07022db6abfadc8a992a6496bc1b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 17 Nov 2021 08:31:12 +0000 Subject: [PATCH] Add support for monitoring files with filestat_exporter --- cookbooks/prometheus/attributes/default.rb | 1 + cookbooks/prometheus/recipes/default.rb | 23 +++++++++++++++++++ .../templates/default/filestat.yml.erb | 6 +++++ 3 files changed, 30 insertions(+) create mode 100644 cookbooks/prometheus/templates/default/filestat.yml.erb diff --git a/cookbooks/prometheus/attributes/default.rb b/cookbooks/prometheus/attributes/default.rb index dba44a6b1..a239c6a19 100644 --- a/cookbooks/prometheus/attributes/default.rb +++ b/cookbooks/prometheus/attributes/default.rb @@ -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"] diff --git a/cookbooks/prometheus/recipes/default.rb b/cookbooks/prometheus/recipes/default.rb index 6e88362a4..85c5ec312 100644 --- a/cookbooks/prometheus/recipes/default.rb +++ b/cookbooks/prometheus/recipes/default.rb @@ -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 index 000000000..f77ecab6d --- /dev/null +++ b/cookbooks/prometheus/templates/default/filestat.yml.erb @@ -0,0 +1,6 @@ +exporter: + files: + - patterns: +<% node[:prometheus][:files].each do |file| -%> + - <%= file %> +<% end -%> -- 2.39.5