From 0bfd4a7d53b3cad7aaa3f3403b585ac5c5867e14 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sun, 5 Feb 2023 19:05:42 +0900 Subject: [PATCH] Deploy `systemd` config for `node_exporter`. --- .../files/etc/default/node_exporter | 1 + .../files/etc/systemd/system/node_exporter.service | 11 +++++++++++ .../prometheus-exporters/node_exporter_setup.rb | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 cookbooks/prometheus-exporters/files/etc/default/node_exporter create mode 100644 cookbooks/prometheus-exporters/files/etc/systemd/system/node_exporter.service diff --git a/cookbooks/prometheus-exporters/files/etc/default/node_exporter b/cookbooks/prometheus-exporters/files/etc/default/node_exporter new file mode 100644 index 0000000..abb1a6b --- /dev/null +++ b/cookbooks/prometheus-exporters/files/etc/default/node_exporter @@ -0,0 +1 @@ +OPTIONS=' --web.listen-address="127.0.0.1:9100" --collector.systemd' diff --git a/cookbooks/prometheus-exporters/files/etc/systemd/system/node_exporter.service b/cookbooks/prometheus-exporters/files/etc/systemd/system/node_exporter.service new file mode 100644 index 0000000..f3b7aa6 --- /dev/null +++ b/cookbooks/prometheus-exporters/files/etc/systemd/system/node_exporter.service @@ -0,0 +1,11 @@ +[Unit] +Description=Node Exporter + +[Service] +User=root +Group=root +EnvironmentFile=-/etc/default/node_exporter +ExecStart=/usr/local/bin/node_exporter $OPTIONS + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/prometheus-exporters/node_exporter_setup.rb b/cookbooks/prometheus-exporters/node_exporter_setup.rb index c907a3f..7bac76a 100644 --- a/cookbooks/prometheus-exporters/node_exporter_setup.rb +++ b/cookbooks/prometheus-exporters/node_exporter_setup.rb @@ -1,10 +1,18 @@ # Deploy the `supervisord` configuration: -remote_file '/etc/supervisor/conf.d/node_exporter.conf' do +remote_file '/etc/systemd/system/node_exporter.service' do owner 'root' group 'root' mode '644' +end - notifies :restart, 'service[supervisor]' +remote_file '/etc/default/node_exporter' do + owner 'root' + group 'root' + mode '644' +end + +service 'node_exporter' do + action [ :enable, :start] end # Deploy `consul` config for `node_exporter`: