Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed Dovecot maildir stats into Prometheus #505

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- opendmarc
- sasl
- dovecot
- dovecot-monitoring
- spamassassin
- postfix
- prometheus-postfix-exporter
Expand Down
3 changes: 3 additions & 0 deletions ansible/roles/dovecot-monitoring/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dovecot_monitoring_cron_filename: ansible_dovecot_prometheus_textfile_exporter
dovecot_monitoring_scripts_directory: /opt/pydis/dovecot-monitoring
4 changes: 4 additions & 0 deletions ansible/roles/dovecot-monitoring/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies:
- dovecot
- prometheus-node-exporter
52 changes: 52 additions & 0 deletions ansible/roles/dovecot-monitoring/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
- name: Create dovecot monitoring directory
ansible.builtin.file:
path: "{{ dovecot_monitoring_scripts_directory }}"
state: directory
owner: root
group: root
mode: "0755"
tags:
- role::dovecot-monitoring

- name: Create dovecot monitoring scripts
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ dovecot_monitoring_scripts_directory }}/{{ item }}"
owner: root
group: root
mode: "0544"
tags:
- role::dovecot-monitoring
loop:
- maildir-mails.sh
- maildir-sizes.sh

- name: Create Maildir size monitoring cronjobs
ansible.builtin.cron:
name: "{{ item.name }}"
minute: "*/20"
hour: "*"
job: "{{ item.job }}"
cron_file: "{{ dovecot_monitoring_cron_filename }}"
user: root
tags:
- role::dovecot-monitoring
register: dovecot_monitoring_cron_file
loop_control:
label: "{{ item.name }}"
loop:
- name: Dovecot maildir size Prometheus exporter
job: "{{ dovecot_monitoring_scripts_directory }}/maildir-sizes.sh"
- name: Dovecot maildir mail count Prometheus exporter
job: "{{ dovecot_monitoring_scripts_directory }}/maildir-mails.sh"

- name: Report to DevOps when Maildir size exporter fails
ansible.builtin.cron:
name: MAILTO
env: true
job: [email protected]
cron_file: "{{ dovecot_monitoring_cron_filename }}"
user: vmail
tags:
- role::dovecot-monitoring
19 changes: 19 additions & 0 deletions ansible/roles/dovecot-monitoring/templates/maildir-mails.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
# Ansible managed

cd /var/vmail && \
find . \
| awk -F / '
# Maildir e-mails have the hostname contained in them
$0 ~ "{{ ansible_fqdn }}" {
total[$2] += 1
}
END {
print "# HELP dovecot_maildir_mail_count Count of e-mails by user"
print "# TYPE dovecot_maildir_mail_count gauge"
for (user in total) {
print "dovecot_maildir_mail_count{user=\"" user "\"} " total[user]
}
}
' \
| sponge > /var/lib/prometheus/node-exporter/dovecot-maildir-mails.prom
15 changes: 15 additions & 0 deletions ansible/roles/dovecot-monitoring/templates/maildir-sizes.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# Ansible managed

cd /var/vmail && \
du --bytes --summarize -- * \
| awk '
BEGIN {
print "# HELP dovecot_maildir_size_bytes Maildir size of e-mail users"
print "# TYPE dovecot_maildir_size_bytes gauge"
}
{
print "dovecot_maildir_size_bytes{user=\"" $2 "\"} " $1
}
' \
| sponge > /var/lib/prometheus/node-exporter/dovecot-maildir-sizes.prom
2 changes: 1 addition & 1 deletion ansible/roles/git-mirrors/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
git_mirrors_base_dir: "/srv/git-mirrors"
git_mirrors_user: "git-mirrors"
git_mirrors_error_email: "[email protected]"
git_mirrors_error_email: "devops+cron@pydis.wtf"

git_mirrors_cgit_logo: "https://raw.githubusercontent.com/python-discord/ops-site/main/src/images/icon.png"
git_mirrors_cgit_title: PyDis DevOps Git Server
Expand Down
Loading