diff --git a/handlers/main.yml b/handlers/main.yml index 54b3ce0..942e4e9 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -88,3 +88,10 @@ state: restarted enabled: yes tags: ['prometheus'] + +- name: 'prometheus | proxmox exporter | restart service' + systemd: + name: prometheus-proxmox-exporter.service + state: restarted + enabled: yes + tags: ['prometheus'] diff --git a/tasks/exporter/proxmox.yml b/tasks/exporter/proxmox.yml new file mode 100644 index 0000000..8051cd6 --- /dev/null +++ b/tasks/exporter/proxmox.yml @@ -0,0 +1,48 @@ +--- +- name: 'proxmox exporter | check vars are defined' + assert: + that: + - prometheus_proxmox_exporter_user is defined + - prometheus_proxmox_exporter_password is defined + - prometheus_proxmox_exporter_node is defined + tags: ['prometheus_proxmox'] + +- name: 'proxmox exporter | install package through pip3' + pip: + name: + - prometheus-pve-exporter + executable: pip3 + tags: ['prometheus_proxmox'] + +- name: 'proxmox exporter | configuration' + template: + src: conf/prometheus-proxmox-exporter.j2 + dest: /etc/default/prometheus-proxmox-exporter + owner: root + group: root + mode: 0600 + register: prometheus_postgres_exporter_configuration + notify: + - 'prometheus | proxmox exporter | restart service' + tags: ['prometheus_proxmox'] + +- name: 'promox exporter | systemd | copy unit file' + template: + src: systemd/prometheus-promox-exporter.service.j2 + dest: /etc/systemd/system/prometheus-promox-exporter.service + owner: root + group: root + mode: 0600 + notify: + - 'prometheus | promox exporter | restart service' + when: not stat_result.stat.exists or exporter_upgrade == "yes" + tags: ['prometheus_proxmox'] + +- name: 'promox exporter | systemd | enable service' + systemd: + daemon_reload: yes + enabled: yes + name: prometheus-{{ exporter }}-exporter.service + ignore_errors: '{{ ansible_check_mode }}' + when: not stat_result.stat.exists or exporter_upgrade == "yes" + tags: ['prometheus_proxmox'] diff --git a/templates/conf/prometheus-proxmox-exporter.j2 b/templates/conf/prometheus-proxmox-exporter.j2 new file mode 100644 index 0000000..cf57ca6 --- /dev/null +++ b/templates/conf/prometheus-proxmox-exporter.j2 @@ -0,0 +1,5 @@ +# {{ ansible_managed }} +default: + user: {{ prometheus_proxmox_exporter_user }} + password: {{ prometheus_proxmox_exporter_password }} + verify_ssl: {{ prometheus_proxmox_exporter_verify_ssl | default('false') }} diff --git a/templates/conf/prometheus.yml.j2 b/templates/conf/prometheus.yml.j2 index 1d84781..d208c49 100644 --- a/templates/conf/prometheus.yml.j2 +++ b/templates/conf/prometheus.yml.j2 @@ -387,3 +387,20 @@ scrape_configs: regex: '(.*):8082' replacement: '${1}' {% endif %} + +{% if prometheus_pve_exporter_targets is defined %} + # proxmox # + - job_name: pve + scrape_interval: 30s + static_configs: + - targets: +{% for target in prometheus_pve_exporter_targets %} + - {{ target }}:9221 +{% endfor %} + metrics_path: /pve + relabel_configs: + - source_labels: [ __address__ ] + target_label: instance + regex: '(.*):9221' + replacement: '${1}' +{% endif %} diff --git a/templates/systemd/prometheus-proxmox-exporter.service.j2 b/templates/systemd/prometheus-proxmox-exporter.service.j2 new file mode 100644 index 0000000..a01e356 --- /dev/null +++ b/templates/systemd/prometheus-proxmox-exporter.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Proxmox VE Prometheus Exporter +After=network.target +Wants=network.target + +[Service] +Restart=on-failure +ExecStart=/usr/local/bin/pve_exporter /etc/default/prometheus-pve-exporter {{ prometheus_proxmox_exporter_port | default('9221') }} {{ prometheus_proxmox_exporter_node }} + +[Install] +WantedBy=multi-user.target