Postfix Delivered Emails chart for netdata

Netdata is a lightweight and powerful monitoring tool with beautiful dashboards. It supports auto-detection for almost anything and collects thousands of metrics automatically, one of which is Postfix mail server’s queue.

netdata-postfix-queue

Above charts provide insight about how many emails are stuck in the queue for a reason and are waiting to be delivered. Another chart is needed to display the number of emails that are delivered to the next hop. Postfix doesn’t provide such metrics and the only way to obtain such information is to dig into the maillog.

There are a number of tools that provide information regarding the deliverability, including pflogsumm, and mailgraph. However, what we need is just a number which is the number of emails that are delivered and throw that number into netdata to have it displayed in a chart.

Below python script will continuously monitor the mail log and increment an internal counter when a “status=sent” is found. The counter will then be displayed to a client via a unix socket, and reset to zero. This will ensure that the number of emails that were delivered within the last few seconds will be obtained by netdata when it periodically reads from the socket (usually every 5-10 seconds).

Download the script here and place it under /usr/bin (or your favorite bin directory).

The script monitors /var/log/maillog and creates a unix socket at /etc/postfix/postfix_delivered.sock. You should modify these in the script if you desire to use different paths.

The next step is to automate the script. Place below initctl script under /etc/init directory and run initctl start postfix_delivered.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# /etc/init/postfix_delivered.conf

start on runlevel [345]
stop on runlevel [06]

respawn
respawn limit unlimited

normal exit 0 1 TERM HUP

env HOME=/root
env USER=root

exec /usr/bin/postfix_delivered.py

Now we need to plug it into netdata. Place below python script under /usr/libexec/netdata/python.d (this path may be different for your installation) and name it postfix_delivered.chart.py. This script will be called by netdata to connect to the unix socket and obtain the number of emails that were delivered since the last check.

Below configuration file needs to be placed under /etc/netdata/python.d as postfix_delivered.conf. In this file we set the socket address for above script to read from.

1
2
3
4
5
6
7
# netdata python.d.plugin configuration for postfix_delivered
# /etc/netdata/python.d/postfix_delivered.conf
# ----------------------------------------------------------------------

via_socket:
 update_every: 5
 socket: '/etc/postfix/postfix_delivered.sock'

Finally, add below line to /etc/netdata/python.d.conf to enable this plugin, and restart netdata.

1
postfix_delivered: yes

The new chart should be on your dashboard.

netdata-postfix-delivered

Tags: 

Related Notes: