Astral 360 Astral Toolbox

Server Monitoring

A watchdog that measures the server every minute without PHP, alerts, and acts when Apache, MySQL, the memory or the disk fail; history, SSH logins, snapshots and a nightly dnf check.

Version 3.0.0 · Store extension, paid · requires PHP 7.4+ with sqlite3 + pdo_sqlite, and a core with the task scheduler (core 2.0.30 or later for Disable to stop the watchdog within the minute) A watchdog that measures the server every minute without PHP, e-mails when a threshold holds, and restarts Apache or MySQL or frees memory and disk when they fail; 30 days of history, post-mortem snapshots, SSH login tracking and a nightly dnf check.

Server Monitoring watches a cPanel server and acts when it fails. Since 3.0 it replaces Astral's cpanel_monitor.sh:

  1. A watchdog in bash, started every minute by a cron line of its own, measures the server, judges every alert and takes the automatic actions. It needs no PHP: when the memory or the processes run out, PHP cannot start, and that is when the server must still be watched.
  2. Metrics and alerts: CPU and I/O wait, load average, memory, memory pressure and swap, root-filesystem usage, Apache workers, Nginx connections and MySQL, stored for 30 days, with alerts on a threshold held for a duration.
  3. Automatic actions: restart Apache or MySQL when they are down, close MySQL's sleeping connections when it is full, restart the service holding the most memory when it runs out, free the disk when / is nearly full; each with its guards, delays and daily caps.
  4. Snapshots: what the server was doing, captured at the moment an alert fires or an action runs, then completed with a wide cross-section (processes, Apache scoreboard, MySQL processlist, dmesg, …).
  5. SSH logins: every successful SSH login from /var/log/secure is recorded and (optionally) e-mailed, with a risk status per source IP.
  6. A nightly dnf check: an e-mail when dnf update would not run cleanly.

On cPanel DNSOnly nodes it measures and alerts, but takes no action.

Everything runs as long as the extension is enabled. To stop it, disable the extension in Options → Extensions (the watchdog stops within the minute); to erase everything it recorded, Remove it (see Disable and Remove). If the core's task scheduler is missing (a core older than the extension), a banner says that nothing is stored, with a link to Options → Version.

Its pages and its e-mails speak the plugin's language: English or French, as set in Options → Settings → General → Language (on Automatic, your WHM language; the e-mails sent by the jobs use root's). This page uses the English names.


How it works

  • The watchdog (watchdog/sm-watchdog.sh), every minute, from /etc/cron.d/toolbox-server-monitoring-watchdog:
    • checks that the extension is enabled (the core's list of enabled extensions) and that its lease has not run out: PHP renews it at every pass, so a licence that holds the extension stops it within 24 hours;
    • reads /proc, df, Apache's and Nginx's status pages, systemd and MySQL;
    • judges every alert, takes the actions that are due, and captures what the server is doing when an alert fires or an action runs;
    • leaves its sample and its events in the extension's spool, for PHP. A normal pass logs nothing; its log is /var/log/toolbox-server-monitoring-watchdog.log (past 5 MB, its last half is kept).
  • The ingest job of the plugin's task scheduler, every minute, stores the samples in the history, turns the events into incidents, sends the e-mails and saves the snapshots. It also writes the watchdog's settings from your Configuration, renews its lease, and lays its cron line again if it went missing.
  • When PHP cannot run, the samples wait in the spool (7 days at most), and the charts show the minutes of the crisis once PHP is back. An action that PHP has not read for 10 minutes makes the watchdog send a short fallback e-mail itself, with sendmail, to its section's addresses.

Metrics tab

Server Monitoring — Metrics

  • Summary: the current values (CPU, load, RAM and swap, disk, Apache, Nginx), tinted by how close each is to its alert threshold: red at 90 % of it or while the alert fires, orange from 70 %.
  • Range: Live (the last 10 minutes, refreshed every 5 s with a countdown), 1h (every 30 s), 24h, 7d, 30d (each about twice per bucket: 2.5, 15 and 30 minutes).
  • Average and peaks: on ranges where samples get bucketed (24h and up), the line plots the bucket average and the translucent band behind it its maximum. Without it, a 5-minute CPU spike to 100 % buried in a 2-hour bucket reads as roughly 9 %: the longer the range, the more an average alone under-reports peaks. The tooltip gives both figures. On short ranges (one sample per bucket) the band collapses to nothing on its own, and it is skipped on charts with more than 3 series (Apache states, Nginx), where it would hurt readability.
  • Time axis: up to 24 h the ticks are hourly (HH:MM). Past that (7d, 30d) they snap to day boundaries: a date label and a grid line on every local midnight, so a spike lands on an identifiable day. 7d adds the weekday; 30d steps every 4 days.
  • Charts (one block per metric group):
    • CPU usage: CPU % and I/O wait %.
    • Load average: 1, 5 and 15 minutes.
    • Memory usage: RAM and swap, axis pinned 0–100 %. RAM is derived from MemAvailable (the kernel's own estimate of what a new process can get without swapping), not MemFree, which sits near zero on a healthy server because Linux fills spare RAM with cache. On a host with no swap the swap metric is not collected at all.
    • Apache workers: max, active and idle, plus a separate request states chart (reading, sending, keepalive, …).
    • Nginx connections: active, reading, writing, waiting, plus requests per second. nginx's counter is cumulative since its last start, so it is converted to a rate for display; an nginx restart leaves a one-point gap rather than a cliff.
    • Swap traffic: pages read back from swap and written out to it, in kB/s. This is the signal that matters: swap used stays high on a healthy server because the kernel parks idle pages there and never reclaims them, whereas sustained swap-in is never normal: it means the working set no longer fits in RAM, and it rises before the load average does. Rates come from cumulative counters (pswpin / pswpout in /proc/vmstat), so nothing is produced on the first pass after an install or a reboot.
    • Disk usage: the root filesystem /, axis pinned 0–100 %. Only / is measured: the other mounts of a cPanel server are small (boot, EFI) or remote (backup NFS).
  • Alert thresholds are drawn on the charts as a dashed line, once the data reaches 70 % of the threshold (a CPU at 5 % keeps a readable axis). Turning a metric group off in Configuration hides its chart and stops storing it.
  • Collection stopped: when no measurement is younger than 5 minutes, a banner says since when. Either the watchdog no longer runs (its log, /var/log/toolbox-server-monitoring-watchdog.log, and its cron line say why), or PHP cannot store its samples (the scheduler's log, /var/log/toolbox-scheduler.log; see Scheduled tasks).

SSH Logins tab

Server Monitoring — SSH Logins

Successful SSH logins of the last 30 days, grouped by source IP (default view), with:

  • One row per IP: IP and reverse-DNS hostname (looked up after the page loads), last login (time, user, method), a 30-day frequency bar, and a status:
    • New IP (red): first seen less than 24 h ago.
    • Trusted (green): seen on 5 or more distinct days.
    • Known (blue): everything else.
    • Excluded (gray): in the excluded IPs (row dimmed).
  • Exclude (on each row not excluded yet): opens the Configuration tab on its SSH logins part, with that address added to the excluded IPs, ready to save.
  • A click on a row (or its Sessions (N) button) opens its sessions with their raw syslog lines. A failed load says so; closing and opening the row tries again.
  • The 50 most recent IPs are listed; Show all N lists every one. The Filter by user, IP or host field filters the list as you type.
  • Show as a table: a classic table (When, User, Source IP, Method, Log line), filtered by user and IP, 50 per page; Group by IP goes back to the grouped view.

Every time on the tab is the server's clock. Every login is recorded regardless of the exclusions: exclusion only suppresses the notification email, never the history.

Snapshots tab

Server Monitoring — Snapshots

  • Take snapshot now captures on demand (usually under 2 s, up to a minute on a server in distress). Only one capture runs at a time. A badge at the top counts the snapshots kept (1 of 100 kept); when no alert and no action takes a snapshot any more, the tab says so, with a link to Configuration › Notifications.
  • An incident takes one automatically, when an alert or an action has its « Take snapshot » on (see Notifications): first the watchdog's own capture, taken at that very moment (the processes by memory, the HTTP connections by source IP, MySQL's processlist for MySQL), saved by PHP as soon as it reads the event; then, in the background, the full cross-section below, added to the same snapshot. The e-mail never waits for it. Several alerts of the same section share one snapshot, and two snapshots are at least the configured gap apart.
  • Each snapshot lists capture time, trigger (Alert or Manual), reason (e.g. CPU usage above 90.0 % (was 97.2 %); with the action taken and its result; once the incident is over, over after 12 minutes, peak 99.3 %; the file itself records it in English), section count and size, with View (in a window: one collapsible block per section; cPanel's services as a table with the ones that should run and don't first; Apache's status page as it printed it), Download (a ZIP, one file per section) and Delete (asks first; cannot be undone).

The full capture has ~29 sections across 8 groups, each command bounded by a 60-second timeout and 256 KB of output (a failing section never spoils the rest):

Group Contents
system uptime, free -m, df -h, df -i (inodes!), vmstat 1 3, dmesg tail
processes top by CPU, top by memory, full process tree
network socket summary (ss -s), established connections with PIDs, top HTTP source IPs
apache full mod_status HTML (per-worker detail)
nginx stub_status + per-connection detail
mysql processlist, status counters, InnoDB status, slow-query log tail
logs messages, maillog, OOM events from dmesg, Apache/Nginx error logs
cpanel service status (whmapi1), Exim queue length, journalctl errors, cPanel error log

Retention is count-based (default 100 snapshots; the oldest go after each new one, and right after a lower maximum is saved).

Configuration tab

Server Monitoring — Configuration

One form in five parts, picked from the menu at its top: Notifications, Metrics collection, Snapshots, SSH logins and Updates. The Save bar at the bottom of the screen saves all five at once and counts the unsaved changes; after a save the page comes back on the part you were on. Leaving the page with unsaved changes asks first. Under an option, « Default: … » gives the value it ships with.

Notifications

When an alert fires. The watchdog reads each metric once a minute. An alert fires when its readings stay beyond its threshold for its whole duration, one reading a minute in a row (a gap of more than 5 minutes starts the count again). One reading back on the right side recovers it. When its readings stop for 5 minutes, or when you turn it off, it ends. Two alerts are states rather than measures: Apache stopped and MySQL not answering have no threshold, only a duration.

Incidents. Every alert belongs to a section (CPU, Load average, Memory and swap, Disk usage, Apache, MySQL/MariaDB). The first alert that fires opens the section's incident; the other alerts and the actions of that section join it until every one has ended. An incident sends:

  • an e-mail for each alert that fires, when its row has « Send email »;
  • an e-mail for each action the watchdog takes, when that action has « Send email »;
  • one summary when it is over (Back to normal): start, end, each alert's peak and how it ended, the actions taken. It goes when something of the incident was e-mailed.

Minimum time between two notifications for the same threshold (default 30 min): an alert that fires again within it is followed and snapshotted, without a second e-mail. An e-mail that could not be sent is tried again the next minute (an hour at most for an action's).

The table has one block per section, with the same columns everywhere:

  • one row per alert: On, Threshold, For (minutes), Send email, Take snapshot;
  • Automated: one row per action of the watchdog in that section: On, its numbers, Send email, Take snapshot;
  • E-mails to: the section's addresses (several separated by commas). Left empty, its e-mails go to the plugin's recipient (Options › Settings). A section can so tell another administrator than the others: Astral's, on a managed server.
Section Alert Default threshold Default duration On by default
CPU Usage (% of total) 90 % 10 min yes
I/O wait (%) 20 % 10 min yes
Load average 1 min 3 × the CPU cores 1 min yes (early warning)
5 min 2 × the CPU cores 10 min yes
15 min 2 × the CPU cores 15 min no (long soak)
Memory and swap Memory used (% unavailable) 90 % 10 min yes
Swap used (% of swap) 50 % 15 min no (a healthy server keeps idle pages in swap)
Swap in (kB/s) 1000 10 min yes
Pressure (PSI, some over 60 s) 20 % 1 min yes (where the kernel has it: EL9 and later)
Available (under) 8 % 5 min yes
Disk usage Used, on / 90 % 5 min no (cPanel already monitors disk)
Apache Active workers (% of MaxRequestWorkers) 85 % 5 min yes
Stopped — 3 min yes
MySQL/MariaDB Not answering (its process alive) — 6 min yes
Connections used (% of max_connections) 90 % 1 min yes

Every alert sends its e-mail by default, and takes a snapshot, except the disk alert (a full disk stays full).

Load thresholds are plain loads: the field holds the load average that fires the alert (on 8 cores: 24, 16 and 16 by default). Until you set one, the default follows the server's cores; a load you type is kept as is, and typing the default back makes it follow the cores again.

The automatic actions (all on by default, with « Send email »; « Take snapshot » on, except for the disk):

Section Action When Limits
Memory and swap Free memory by restarting the service that holds the most (Apache with its PHP, PHP-FPM or MySQL) memory available under 5 % for 8 readings, or under 2 % for 4 30 minutes apart, 4 in 24 hours
Disk usage Free disk space: stop a running cPanel backup, delete the oldest files of /backup until enough is free; when /backup has none, the error_log and debug.log files of /home larger than 20 MB under 100 MB free on / none: a full disk takes everything else down. A /backup that is a link is left alone
Apache Restart Apache stopped for 3 minutes one an hour, 3 in 24 hours
MySQL/MariaDB Restart MySQL its process gone for 3 minutes (never a MySQL that is alive but does not answer: restarted under load, it comes back cold and slower) one an hour, 3 in 24 hours
Close MySQL's sleeping connections, then restart it if it stays full connections at 90 % of max_connections: those asleep longer than 60 s the restart's limits

The numbers in bold are the ones the table lets you set. The rest is fixed, as in cpanel_monitor.sh:

  • nothing on a DNS-only server, nor on a service that /etc/apachedisable or /etc/mysqldisable leaves alone, nor on a service that is starting or stopping;
  • restarts go through cPanel's /scripts/restartsrv_*, else systemd, and may take 300 s at most;
  • the delays and daily caps count only restarts that succeeded. Past its cap, a service is no longer restarted until fewer than three restarts are left in the last 24 hours: the watchdog says so once (Suspend the automatic restarts), with « Send email » of that restart;
  • a refusal or a failure that repeats is told once an hour.

An action with « Send email » off sends no e-mail, nor the fallback e-mail; with « Take snapshot » off it brings no capture.

Simulation. With "watchdog": {"dry_run": true} in config/settings.user.json (by hand: the tab does not show it), the watchdog does nothing and its e-mails say what it would have done. Remove the line, or set it to false, to let it act.

Metrics collection

  • Collected groups: CPU, Load, Memory, Disk, Apache, Nginx. A group turned off is no longer stored, its chart leaves the Metrics tab, and its alerts have nothing to read. The watchdog still reads the memory, the disk and the services for its actions.
  • History (days): default 30. Older measurements are deleted every night at 03:00.

Snapshots

Setting Default
Snapshots kept 100
Gap between alert snapshots (min) 5

Which alert or action takes a snapshot is set on its row, in Notifications. Snapshots are always available: Take snapshot now works whatever the settings, and an alert e-mail always says when a snapshot is being taken, with a link to the Snapshots tab.

SSH logins

Setting Default Notes
Send an e-mail on every login on Logins are still recorded when off. A login more than a day old (read late, after the extension or its task was off) only goes to the history, with no email. When its age cannot be worked out, the email goes out.
Administrators only on Only root and members of the wheel group are recorded; cPanel users are left out entirely.
E-mails to empty The SSH e-mails' addresses; empty, the plugin's recipient.
Excluded users empty One per line or comma-separated. Their logins are still recorded; only the email is suppressed.
Excluded source IPs empty IPv4 and IPv6, exact match (no range). The Exclude button of the SSH Logins tab adds one here.
Cooldown per user (min) 10 A user reconnecting within the window doesn't trigger a second email.
History (days) 45 Older logins are deleted every night at 03:00.

Updates

The nightly dnf check says when dnf update would not run cleanly. It changes nothing: dnf reads the RPM database, refreshes the repositories and works the upgrade out, then refuses it. It runs on AlmaLinux, Rocky Linux, RHEL, CentOS and CloudLinux 8, 9 and 10 only; elsewhere the part says so.

Setting Default Notes
Nightly check on
Time 04:30 Server time, after cPanel's own nightly update (upcp).
E-mails to empty Empty: the plugin's recipient.

In English (LC_ALL=C), each under its own time limit, it runs:

  1. dnf -q check: the RPM database, duplicates, missing dependencies;
  2. dnf makecache --refresh --setopt=skip_if_unavailable=False: a repository out of reach, metadata in error;
  3. dnf upgrade --assumeno --best: does the upgrade resolve? --best keeps dnf from hiding a conflict by taking an older version or leaving a package out (a repository out of reach is skipped here: step 2 reports it);
  4. only when step 3 does not resolve, dnf upgrade --assumeno without --best: the packages dnf would leave out.

A dnf, yum or rpm already running, or cPanel's upcp, is waited for 15 minutes; then the check gives up until the next night, with a line in the scheduler's log and no e-mail. An e-mail goes every night a problem is seen, with dnf's own lines and its full output attached; nothing is kept on the server.

Scheduled tasks

Besides the watchdog's cron line, the plugin's task scheduler runs these tasks while the extension is enabled; there is no Enable/Disable button:

  • Ingest, every minute: stores the watchdog's samples, turns its events into incidents, sends their e-mails, saves the snapshots; writes the watchdog's settings, renews its lease, lays its cron line again if it went.
  • SSH logins, every minute: reads /var/log/secure from where it stopped (rotation-aware), records the logins, sends their emails.
  • History clean-up, every day at 03:00: deletes what is past its retention, trims the snapshots to their count; compacts the database on the 1st of the month.
  • dnf check, every day at its time, while it is on.

Their output goes to the scheduler's log, /var/log/toolbox-scheduler.log (rotated by the plugin).


Notifications it sends

All through the core Notifier (see Core configuration → Settings › Email & notifications), in the plugin's language, to the section's addresses or the plugin's recipient. The email goes out at normal priority, like all of the plugin's; the importance of the notification only sets the level of the Contact Manager alert. In the inbox, the subject starts with [<hostname>] Astral Toolbox -. The subjects below are the English ones:

  • <Metric> exceeded on <hostname> (e.g. Memory used exceeded on …): metric, current value with its unit, threshold, duration; says when a snapshot is being taken, with a link to the Snapshots tab. Memory available says … under its threshold on <hostname>, and a state its name alone (Apache (httpd) stopped on <hostname>).
  • <Action>: <result> on <hostname> (e.g. Restart Apache (httpd): done on …): what the watchdog did and what came of it (the service, the connections closed, the memory held, the files deleted and the space freed, the command and its exit code); Simulation, … in simulation.
  • Back to normal: <Section> on <hostname>: the summary of an incident that is over.
  • SSH login: <user>@<hostname>: host, user, source IP, auth method, time, with an "investigate immediately" prompt.
  • dnf update would not run cleanly on <hostname>: the problems seen by the nightly check, with dnf's lines; its full output attached.
  • Server Monitoring: the watchdog acted on <hostname>, and PHP has not told it: the watchdog's own fallback e-mail (plain text, by sendmail), when PHP has not read an action for 10 minutes.

Disable and Remove

  • Disable (Options → Extensions): the tasks stop at once and the watchdog within the minute (within 15 minutes on a core older than 2.0.30); the history, the logins, the snapshots and the settings stay. Enabling it again resumes everything; the SSH task then records the logins it missed, and emails only those less than a day old.
  • Remove: removes the watchdog's cron line and log, stops the tasks still running, then erases the extension's folder: the metrics history, the SSH login history, the snapshots, the incidents and your settings, for good.

Updating from 2.1.x

3.0.0:

  • The watchdog replaces the PHP collection: a cron line of its own (/etc/cron.d/toolbox-server-monitoring-watchdog), written by the update. Astral's cpanel_monitor.sh is no longer needed: its actions are here, with their guards.
  • The alerts table is per section, with Send email and Take snapshot on every row, a new MySQL/MariaDB section, new alerts (memory pressure, memory available, Apache stopped, MySQL not answering, MySQL connections), the Automated actions, and E-mails to for each section and for the SSH logins.
  • The switches Send email on threshold trigger (Notifications) and Take a snapshot when an alert fires (Snapshots) are gone. The update carries them over: one that was off turns off that column on every alert row. The actions keep their defaults (2.x had none).
  • The Recovered e-mail of each alert is replaced by one summary per incident (Back to normal).
  • The Updates part and its nightly dnf check are new.

2.1.1:

  • The options lost their Restore link and the alerts table its ↺ buttons; « Default: … » stays under an option.

2.1.0:

  • The home tile is gone (the plugin has had no home page since core 2.0.26); the Metrics tab shows the same figures.
  • The SSH Logins tab lost its row of figures and its « New source IP » banner: the table already says it, and each row has an Exclude button.
  • The Configuration tab is in parts. Its Monitoring service part, the Current and Status columns of the alerts, and the switches « Take snapshots » and « Say so in the alert e-mail » are gone: snapshots are always available, and the alert email always says when one is being taken.
  • Load thresholds are plain loads. The defaults went from 8, 4 and 3 times the cores to 3, 2 and 2 times: the load alerts fire much sooner. A multiplier you had set shows as the load it gives (cores × multiplier) and is kept as that load when you save.

Updating from 1.x

The cron file of 1.x (/etc/cron.d/toolbox-server-monitoring) and its log are removed once the plugin's scheduler takes over; on a core without the scheduler, the old file stays until the core is updated. The collection is on from then on, whether or not the old cron file was enabled: the Enable cron / Disable buttons are gone.

Data & file map

Path Purpose
extensions/server-monitoring/var/monitoring.db SQLite: metrics (30 days), ssh_logins (45 days), ip_hostnames (reverse-DNS cache, 30 days)
extensions/server-monitoring/var/snapshots/ Snapshots, one JSON file each (max 100; downloaded as a ZIP)
extensions/server-monitoring/var/incidents.json The incidents still open, the e-mail cooldowns, the e-mails to try again
extensions/server-monitoring/var/spool/ The watchdog's samples and events waiting for PHP (7 days at most)
extensions/server-monitoring/var/watchdog/ The watchdog's settings, lease, fallback recipients and words (written by PHP), and its state: each alert's count, each service's restarts
extensions/server-monitoring/var/*.json SSH cursor and notification cooldowns
extensions/server-monitoring/config/settings.default.json + config/settings.user.json Defaults + your overrides (only what differs from the defaults is written)
/etc/cron.d/toolbox-server-monitoring-watchdog The watchdog's cron line, every minute
/var/log/toolbox-server-monitoring-watchdog.log The watchdog's log: its events and actions (5 MB, then its last half)
/var/log/toolbox-scheduler.log The plugin scheduler's log: one line per task run

var/ is root-only (0700, its files 0600).