diff --git a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_disabled.yml b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_disabled.yml index 486fb8e6c0..62a5837db1 100644 --- a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_disabled.yml +++ b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_disabled.yml @@ -9,6 +9,11 @@ until: result is succeeded delay: "{{ packages_install_retries_delay | default(10) }}" +- name: Remove logrotate configuration for node-exporter + file: + path: /etc/logrotate.d/node-exporter + state: absent + - name: Remove consul agent service declaration for node-exporter file: path: "{{ consul_folder_conf }}/service-node-exporter.json" diff --git a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_enabled.yml b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_enabled.yml index 3e9c116819..eb126c6b25 100644 --- a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_enabled.yml +++ b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/tasks/prometheus_node_exporter_enabled.yml @@ -49,6 +49,30 @@ tags: - update_node_exporter_configuration +- name: Deploy systemd service file for node_exporter + template: + src: vitam-node-exporter.service.j2 + dest: "{{ '/lib/systemd/system' if ansible_distribution == 'Debian' else '/usr/lib/systemd/system' }}/vitam-node-exporter.service" + owner: root + group: root + mode: "0644" + notify: "prometheus-node-exporter - restart service" + +- name: Enable logrotate for node_exporter + template: + src: node-exporter.logrotate.j2 + dest: /etc/logrotate.d/node-exporter + owner: root + group: root + mode: 0644 + when: prometheus.node_exporter.logrotate | default('enabled') | lower == 'enabled' + +- name: Disable logrotate for node_exporter + file: + path: /etc/logrotate.d/node-exporter + state: absent + when: prometheus.node_exporter.logrotate | default('enabled') | lower == 'disabled' + #### Consul configuration #### - name: Ensure consul config dir is OK file: diff --git a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node-exporter.logrotate.j2 b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node-exporter.logrotate.j2 new file mode 100644 index 0000000000..d9809c2f8b --- /dev/null +++ b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node-exporter.logrotate.j2 @@ -0,0 +1,15 @@ +{{ ansible_managed | comment }} + +{{ vitam_defaults.folder.root_path }}/log/node_exporter/node-exporter.log { + daily + rotate {{ prometheus.node_exporter.history_days | default(30) }} + copytruncate + dateext + dateformat -%Y-%m-%d + dateyesterday + extension .log + compress + delaycompress + notifempty + missingok +} diff --git a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node_exporter.j2 b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node_exporter.j2 index 3a5ac63ed9..1039a80408 100644 --- a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node_exporter.j2 +++ b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/node_exporter.j2 @@ -1 +1 @@ -NODE_EXPORTER_OPTS='--web.listen-address={{ ip_admin }}:{{ prometheus.node_exporter.port | default(9101) }} --web.telemetry-path={{ prometheus.node_exporter.metrics_path | default('/metrics') }} --collector.textfile.directory /vitam/data/node_exporter/textfile_collector' +NODE_EXPORTER_OPTS='--web.listen-address={{ ip_admin }}:{{ prometheus.node_exporter.port | default(9101) }} --web.telemetry-path={{ prometheus.node_exporter.metrics_path | default('/metrics') }} --collector.textfile.directory /vitam/data/node_exporter/textfile_collector --log.level={{ prometheus.node_exporter.log_level | default('warn') }}' diff --git a/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/vitam-node-exporter.service.j2 b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/vitam-node-exporter.service.j2 new file mode 100644 index 0000000000..a493d221f1 --- /dev/null +++ b/deployment/ansible-vitam-extra/roles/prometheus-node-exporter/templates/vitam-node-exporter.service.j2 @@ -0,0 +1,18 @@ +# -*- mode: conf -*- + +[Unit] +Description=Prometheus Node Exporter. +Documentation=https://github.com/prometheus/node_exporter +After=network.target + +[Service] +EnvironmentFile=-/vitam/conf/node_exporter/sysconfig/node_exporter +User=vitam +Group=vitam +ExecStart=/bin/bash -c 'exec /vitam/bin/node_exporter/node_exporter $NODE_EXPORTER_OPTS 2>> {{ vitam_defaults.folder.root_path | default('/vitam') }}/log/node_exporter/node-exporter.log' +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/deployment/environments/group_vars/all/advanced/cots_vars.yml b/deployment/environments/group_vars/all/advanced/cots_vars.yml index 4aecf4ab0e..9b0f885326 100644 --- a/deployment/environments/group_vars/all/advanced/cots_vars.yml +++ b/deployment/environments/group_vars/all/advanced/cots_vars.yml @@ -158,6 +158,9 @@ prometheus: enabled: true port: 9101 metrics_path: /metrics + log_level: "warn" + logrotate: enabled # or disabled + history_days: 30 # How many days to store logs if logrotate is set to 'enabled' consul_exporter: enabled: true port: 9107