diff --git a/cookbooks/prometheus-exporters/attributes.rb b/cookbooks/prometheus-exporters/attributes.rb new file mode 100644 index 0000000..221f13f --- /dev/null +++ b/cookbooks/prometheus-exporters/attributes.rb @@ -0,0 +1,48 @@ +# ------------------------------------------- +# Specifying the default settings: +# ------------------------------------------- +node.reverse_merge!({ + 'prometheus' => { + 'manager' => false, + 'url' => 'https://github.com/prometheus/prometheus/releases/download/', + 'prefix' => 'prometheus-', + 'postfix' => '.linux-amd64.tar.gz', + 'storage' => '/opt/prometheus/', + 'location' => '/usr/local/bin/' + }, + 'node_exporter' => { + 'url' => 'https://github.com/prometheus/node_exporter/releases/download/', + 'prefix' => 'node_exporter-', + 'postfix' => '.linux-amd64.tar.gz', + 'storage' => '/opt/node_exporter/bin/', + 'location' => '/usr/local/bin/' + }, + 'blackbox_exporter' => { + 'url' => 'https://github.com/prometheus/blackbox_exporter/releases/download/', + 'prefix' => 'blackbox_exporter-', + 'postfix' => '.linux-amd64.tar.gz', + 'storage' => '/opt/blackbox_exporter/bin/', + 'location' => '/usr/local/bin/' + }, + 'alertmanager' => { + 'url' => 'https://github.com/prometheus/alertmanager/releases/download/', + 'prefix' => 'alertmanager-', + 'postfix' => '.linux-amd64.tar.gz', + 'storage' => '/opt/prometheus/', + 'location' => '/usr/local/bin/' + }, + 'alertmanager_webhook' => { + 'url' => 'https://github.com/tomtom-international/alertmanager-webhook-logger/releases/download/', + 'prefix' => 'alertmanager-webhook-logger-', + 'postfix' => '.tar.gz', + 'storage' => '/opt/prometheus/', + 'location' => '/usr/local/bin/' + }, + 'filestat_exporter' => { + 'url' => 'https://github.com/michael-doubez/filestat_exporter/releases/download/', + 'prefix' => 'filestat_exporter-', + 'postfix' => '.linux-amd64.tar.gz', + 'storage' => '/opt/filestat_exporter/', + 'location' => '/usr/local/bin/' + }, +}) diff --git a/cookbooks/prometheus-exporters/default.rb b/cookbooks/prometheus-exporters/default.rb new file mode 100644 index 0000000..81ca436 --- /dev/null +++ b/cookbooks/prometheus-exporters/default.rb @@ -0,0 +1,21 @@ +# Loading the attributes: +include_recipe './attributes.rb' + +# Create `/etc/prometheus.d/`: +%w(/etc/prometheus_exporters.d).each do |d| + directory d do + owner 'root' + group 'root' + mode '0755' + end +end + +# Install the node_exporter here: +include_recipe './node_exporter_install.rb' +include_recipe './node_exporter_setup.rb' + +# Install the filestat_exporter here: +include_recipe './filestat_exporter_install.rb' +include_recipe './filestat_exporter_setup.rb' + +include_recipe './exporter_proxy.rb' diff --git a/cookbooks/prometheus/exporter_proxy.rb b/cookbooks/prometheus-exporters/exporter_proxy.rb similarity index 100% rename from cookbooks/prometheus/exporter_proxy.rb rename to cookbooks/prometheus-exporters/exporter_proxy.rb diff --git a/cookbooks/prometheus/files/etc/consul.d/service-filestat_exporter.json b/cookbooks/prometheus-exporters/files/etc/consul.d/service-filestat_exporter.json similarity index 100% rename from cookbooks/prometheus/files/etc/consul.d/service-filestat_exporter.json rename to cookbooks/prometheus-exporters/files/etc/consul.d/service-filestat_exporter.json diff --git a/cookbooks/prometheus/files/etc/consul.d/service-node_exporter.json b/cookbooks/prometheus-exporters/files/etc/consul.d/service-node_exporter.json similarity index 100% rename from cookbooks/prometheus/files/etc/consul.d/service-node_exporter.json rename to cookbooks/prometheus-exporters/files/etc/consul.d/service-node_exporter.json diff --git a/cookbooks/prometheus/files/etc/prometheus_exporters.d/exporter_proxy/config.yml b/cookbooks/prometheus-exporters/files/etc/prometheus_exporters.d/exporter_proxy/config.yml similarity index 100% rename from cookbooks/prometheus/files/etc/prometheus_exporters.d/exporter_proxy/config.yml rename to cookbooks/prometheus-exporters/files/etc/prometheus_exporters.d/exporter_proxy/config.yml diff --git a/cookbooks/prometheus/files/etc/prometheus_exporters.d/filestat.yml b/cookbooks/prometheus-exporters/files/etc/prometheus_exporters.d/filestat.yml similarity index 100% rename from cookbooks/prometheus/files/etc/prometheus_exporters.d/filestat.yml rename to cookbooks/prometheus-exporters/files/etc/prometheus_exporters.d/filestat.yml diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/exporter_proxy.conf b/cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/exporter_proxy.conf similarity index 100% rename from cookbooks/prometheus/files/etc/supervisor/conf.d/exporter_proxy.conf rename to cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/exporter_proxy.conf diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/filestat_exporter.conf b/cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/filestat_exporter.conf similarity index 100% rename from cookbooks/prometheus/files/etc/supervisor/conf.d/filestat_exporter.conf rename to cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/filestat_exporter.conf diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/node_exporter.conf b/cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/node_exporter.conf similarity index 100% rename from cookbooks/prometheus/files/etc/supervisor/conf.d/node_exporter.conf rename to cookbooks/prometheus-exporters/files/etc/supervisor/conf.d/node_exporter.conf diff --git a/cookbooks/prometheus-exporters/files/lib/systemd/system/promtail-prometheus.service b/cookbooks/prometheus-exporters/files/lib/systemd/system/promtail-prometheus.service new file mode 100644 index 0000000..a52887f --- /dev/null +++ b/cookbooks/prometheus-exporters/files/lib/systemd/system/promtail-prometheus.service @@ -0,0 +1,12 @@ +[Unit] +Description=Grafana Promtail for Prometheus +Documentation=https://github.com/grafana/loki +After=network-online.target + +[Service] +User=root +Restart=always +ExecStart=/usr/local/bin/promtail --config.file=/etc/promtail/prometheus.yaml + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/prometheus/filestat_exporter_install.rb b/cookbooks/prometheus-exporters/filestat_exporter_install.rb similarity index 100% rename from cookbooks/prometheus/filestat_exporter_install.rb rename to cookbooks/prometheus-exporters/filestat_exporter_install.rb diff --git a/cookbooks/prometheus/filestat_exporter_setup.rb b/cookbooks/prometheus-exporters/filestat_exporter_setup.rb similarity index 100% rename from cookbooks/prometheus/filestat_exporter_setup.rb rename to cookbooks/prometheus-exporters/filestat_exporter_setup.rb diff --git a/cookbooks/prometheus/node_exporter_install.rb b/cookbooks/prometheus-exporters/node_exporter_install.rb similarity index 100% rename from cookbooks/prometheus/node_exporter_install.rb rename to cookbooks/prometheus-exporters/node_exporter_install.rb diff --git a/cookbooks/prometheus/node_exporter_setup.rb b/cookbooks/prometheus-exporters/node_exporter_setup.rb similarity index 100% rename from cookbooks/prometheus/node_exporter_setup.rb rename to cookbooks/prometheus-exporters/node_exporter_setup.rb diff --git a/cookbooks/prometheus/default.rb b/cookbooks/prometheus/default.rb index a42c10e..32c478e 100644 --- a/cookbooks/prometheus/default.rb +++ b/cookbooks/prometheus/default.rb @@ -1,58 +1,36 @@ # Loading the attributes: include_recipe './attributes.rb' -# Install the Prometheus manager: -if node['prometheus']['manager'] - include_recipe './prometheus_install.rb' - include_recipe './prometheus_setup.rb' +include_recipe './prometheus_install.rb' +include_recipe './prometheus_setup.rb' - include_recipe './alertmanager_install.rb' - include_recipe './alertmanager_setup.rb' +include_recipe './alertmanager_install.rb' +include_recipe './alertmanager_setup.rb' - include_recipe './alertmanager_webhook_install.rb' - include_recipe './alertmanager_webhook_setup.rb' +include_recipe './alertmanager_webhook_install.rb' +include_recipe './alertmanager_webhook_setup.rb' - # Deploy /etc/hosts file: - HOSTNAME = run_command('uname -n').stdout.chomp +# Deploy /etc/hosts file: +HOSTNAME = run_command('uname -n').stdout.chomp - template '/etc/promtail/prometheus.yaml' do - owner 'root' - group 'root' - mode '644' +template '/etc/promtail/prometheus.yaml' do + owner 'root' + group 'root' + mode '644' - variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint']) + variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint']) - notifies :restart, 'service[promtail-prometheus]' - end - - # Deploy the `systemd` configuration: - remote_file '/lib/systemd/system/promtail-prometheus.service' do - owner 'root' - group 'root' - mode '644' - end - - # Service setting: - service 'promtail-prometheus' do - action [ :enable, :restart ] - end + notifies :restart, 'service[promtail-prometheus]' end -# Create `/etc/prometheus.d/`: -%w(/etc/prometheus_exporters.d).each do |d| - directory d do - owner 'root' - group 'root' - mode '0755' - end +# Deploy the `systemd` configuration: +remote_file '/lib/systemd/system/promtail-prometheus.service' do + owner 'root' + group 'root' + mode '644' end -# Install the node_exporter here: -include_recipe './node_exporter_install.rb' -include_recipe './node_exporter_setup.rb' - -# Install the filestat_exporter here: -include_recipe './filestat_exporter_install.rb' -include_recipe './filestat_exporter_setup.rb' - -include_recipe './exporter_proxy.rb' +# Service setting: +service 'promtail-prometheus' do + action [ :enable, :restart ] +end diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox-targets.conf b/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox-targets.conf deleted file mode 100644 index 53ee1f8..0000000 --- a/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox-targets.conf +++ /dev/null @@ -1,8 +0,0 @@ -[program:blackbox-targets] -command=/usr/local/bin/consul-template -consul-addr 127.0.0.1:8500 -template "/etc/consul-template.d/blackbox-targets.tmpl:/etc/prometheus.d/targets/servers.yml" -stdout_logfile=/var/log/supervisor/blackbox-targets.log -redirect_stderr=true -stdout_logfile_maxbytes=1MB -stdout_logfile_backups=5 -autorestart=true -stopsignal=INT diff --git a/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox_exporter.conf b/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox_exporter.conf deleted file mode 100644 index 75d8d05..0000000 --- a/cookbooks/prometheus/files/etc/supervisor/conf.d/blackbox_exporter.conf +++ /dev/null @@ -1,8 +0,0 @@ -[program:blackbox_exporter] -command=/usr/local/bin/blackbox_exporter --config.file="/etc/prometheus.d/blackbox.yml" -stdout_logfile=/var/log/supervisor/blackbox_exporter.log -redirect_stderr=true -stdout_logfile_maxbytes=1MB -stdout_logfile_backups=5 -autorestart=true -stopsignal=HUP diff --git a/roles/base.rb b/roles/base.rb index dc38639..ca8f14e 100644 --- a/roles/base.rb +++ b/roles/base.rb @@ -5,4 +5,4 @@ include_recipe '../cookbooks/monit/default.rb' include_recipe '../cookbooks/consul/default.rb' include_recipe '../cookbooks/fzf/default.rb' include_recipe '../cookbooks/promtail/default.rb' -include_recipe '../cookbooks/prometheus/default.rb' +include_recipe '../cookbooks/prometheus-exporters/default.rb' diff --git a/roles/prometheus.rb b/roles/prometheus.rb new file mode 100644 index 0000000..372fdc0 --- /dev/null +++ b/roles/prometheus.rb @@ -0,0 +1,3 @@ +include_recipe '../cookbooks/prometheus/default.rb' +include_recipe '../cookbooks/grafana/default.rb' +include_recipe '../cookbooks/loki/default.rb'