[prometheus-node-exporter] Monitor mailq

certbot_on_virtu
Alexandre Iooss 2020-01-31 12:40:00 +01:00
parent b59a0d0b0a
commit 0c8aa9c103
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
5 changed files with 56 additions and 0 deletions

View File

@ -57,3 +57,8 @@
- hosts: fyre.adm.crans.org
roles:
- ninjabot
# Monitor mailq with a special text exporter
- hosts: redisdead.adm.crans.org
roles:
- prometheus-node-exporter-postfix

View File

@ -0,0 +1,11 @@
#!/bin/bash
#
# Description: Expose metrics from postfix.
#
# Author: Alexandre Iooss <erdnaxe@crans.org>
mailq_length="$(/usr/bin/mailq | grep "[^ ]*@crans.org" | wc -l)"
echo '# HELP postfix_mailq_length Pending mails in mailq.'
echo '# TYPE postfix_mailq_length gauge'
echo "postfix_mailq_length ${mailq_length}"

View File

@ -0,0 +1,6 @@
[Unit]
Description=Collect postfix metrics for prometheus-node-exporter
[Service]
Type=oneshot
ExecStart=/bin/bash -c "/usr/share/prometheus-node-exporter/postfix.sh | sponge /var/lib/prometheus/node-exporter/postfix.prom"

View File

@ -0,0 +1,9 @@
[Unit]
Description=Run postfix metrics collection every 15 minutes
[Timer]
OnBootSec=0
OnUnitActiveSec=15min
[Install]
WantedBy=timers.target

View File

@ -0,0 +1,25 @@
---
# Install Postfix textfile collector, in bullseye you will have postfix exporter
- name: Install Postfix textfile collector
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: "{{ item.mode }}"
loop:
- src: postfix.sh
dest: /usr/share/prometheus-node-exporter/postfix.sh
mode: "0755"
- src: prometheus-node-exporter-postfix.service
dest: /etc/systemd/system/prometheus-node-exporter-postfix.service
mode: "0644"
- src: prometheus-node-exporter-postfix.timer
dest: /etc/systemd/system/prometheus-node-exporter-postfix.timer
mode: "0644"
- name: Activate prometheus-node-exporter-postfix timer
systemd:
name: prometheus-node-exporter-postfix.timer
enabled: true
state: started