Monitoring pgBackRest with tail_n_mail

After a lively discussion at work today about monitoring tools and use cases, I decided to see if I could use tail_n_mail, which I already use to monitor my PostgreSQL logs, to monitor my pgBackRest logs. It turns out that it can, and can do so fairly trivially.

For reference, our .tail_n_mail.conf looks like this:

## This file is automatically updated
LOG_LINE_PREFIX: %t P%p
EMAIL: you@gme.com
MAILSUBJECT: HOST pgBackRest errors NUMBER

INCLUDE: WARN:
INCLUDE: ERROR:
INCLUDE: FATAL:
INCLUDE: PANIC:


FILE1: /var/log/pgbackrest/pgbackrest.log

You would need to change the EMAIL and FILE1 and the rest should just work.

To actually invoke the monitoring, simply add a cron entry that looks like:

* * * * * /path/to/tail_n_mail ~/.tailnmail.conf --pgmode=0

(Obviously, you should adjust the periodicity. I highly doubt you need to check every minute.)

Once you’ve saved the crontab, you should be all good. If you doubt the setup, you can add --mailzero to the invocation to get an email even if everything is OK.

See? Easy.