Nagios can remotely monitor a Proxmox server by running custom scripts via the NRPE agent. For backups, the goal is to calculate the total size of files in the backup directory modified in the last 7 days and alert if the backup size falls below or exceeds desired thresholds.

Step 1: Install NRPE on Proxmox#

On your Proxmox host (Debian-based), install NRPE and Nagios plugins:

apt update
apt install nagios-nrpe-server monitoring-plugins

Configure /etc/nagios/nrpe.cfg to allow your Nagios server IP:

allowed_hosts=127.0.0.1,<nagios_server_ip>

Restart NRPE:

systemctl restart nagios-nrpe-server
systemctl enable --now nagios-nrpe-server

Step 2: Create the Backup Size Check Script#

Create a script /usr/lib/nagios/plugins/check_backups_size.sh on the Proxmox host:

#!/bin/bash

DIR="/mnt/usb"
DAYS=7
THRESHOLD=10

TOTAL_BYTES=$(find "$DIR" -type f -mtime -$DAYS -print0 | xargs -0 du -b 2>/dev/null | awk '{sum+=$1} END {print sum}')
TOTAL_GB=$(awk -v bytes="$TOTAL_BYTES" 'BEGIN{printf "%.2f", bytes/1024/1024/1024}')

if (( $(echo "$TOTAL_GB > $THRESHOLD" | bc -l) )); then
  echo "OK - Backups size is ${TOTAL_GB}GB (threshold ${THRESHOLD}GB)"
  exit 0
else
  echo "CRITICAL - Backups size is ${TOTAL_GB}GB (below threshold ${THRESHOLD}GB)"
  exit 2
fi

Make it executable:

sudo chmod +x /usr/lib/nagios/plugins/check_backups_size.sh

Step 3: Configure NRPE to Use the Script#

Edit /etc/nagios/nrpe.cfg and add:

command[check_backups_size]=/usr/lib/nagios/plugins/check_backups_size.sh

Restart NRPE:

systemctl restart nagios-nrpe-server

Step 4: Define Nagios Command and Service on the Nagios Server#

Install nrpe plug-in

apt install nagios-plugins-basic nagios-nrpe-plugin

Define a service to monitor backups:

define service {
  use                     generic-service
  host_name               proxmox_server
  service_description     Backup Size Check
  check_command           check_nrpe!check_backups_size
  max_check_attempts      3
  check_interval          5
  retry_interval          1
}

Summary#

This setup enables Nagios to monitor backup sizes on Proxmox by remote execution of a custom script via NRPE. Alerts will notify if backups fall below a critical size, ensuring timely intervention.

This simple approach can be extended with additional checks or thresholds to fit more complex backup monitoring needs.