↓Skip to main content

P2PMon examples

A 3-host fleet #

Issue a demo license for the seeder on the P2PMon page (hostname mon01, its IP and MAC) and save it as p2pmon.lic next to each binary:

# seeder first
./p2pmon.Linux-x86_64 -web-server &
# then the members, same license file
./p2pmon.Linux-x86_64 -web-server &

After about a minute, http://localhost:5580 on any node shows all three hosts. Failures are acked from the dashboard; retired hosts are removed there (a host that reports again is restored automatically).

A custom disk check (shell) #

scripts/21disk.sh — numbered scripts are run every 60s in sorted order:

#!/bin/sh
# Warn above 80% full, critical above 90%, on any mounted filesystem.
df -P | awk 'NR>1 {print $5 " " $6}' | while read pct mnt; do
  used=${pct%%%*}
  if [ "$used" -ge 90 ]; then
    "$P2PMON_BIN" status "$P2PMON_HOST" crit disk "$mnt $pct full"
  elif [ "$used" -ge 80 ]; then
    "$P2PMON_BIN" status "$P2PMON_HOST" warn disk "$mnt $pct full"
  fi
done

Trialled without a daemon via p2pmon test scripts/21disk.sh.

A custom check (Python) #

Non-shell scripts print raw protocol lines instead:

#!/usr/bin/env python3
# scripts/22queue.py — report the mail queue length.
import os
import subprocess
host = os.environ.get("P2PMON_HOST", "")
n = len(subprocess.run(["mailq"], capture_output=True, text=True).stdout.splitlines())
status = "OK" if n < 10 else ("WARN" if n < 100 else "CRIT")
print(f"{status}\t{host}\tqueue\tmailq {n} messages")

External-monitor push #

With -external, built-in collection is disabled and a report file is pushed as this host’s status (numeric TSV lines, foreign subjects allowed):

printf 'db01\t0\tpostgres\treplicating\n' > /tmp/report.tsv
p2pmon -put /tmp/report.tsv

The -put file format is numeric (0=OK 1=WARN 2=CRIT), unlike the textual OK|WARN|CRIT lines printed by custom scripts.

Syslog to a collector #

One host per fleet forwards warnings and criticals:

P2PMON_SYSLOG=10.0.0.50:514 P2PMON_SYSLOG_LEVEL=warn,crit \
  ./p2pmon.Linux-x86_64

Seeder join events are added on the seeder with P2PMON_SYSLOG_LEVEL=name (or warn,crit,name for both).