stats panel
The stats panel is a web page for the people who run the network. It answers the questions an IRC admin asks every day: is everything linked, how many people are on, when did that leaf split and why, are services up, is the protection layer catching anything, and will a certificate expire soon. It keeps the history, so you can also see last week or last year.
It is optional and off by default. Nothing is collected, written or served until you turn it on, and it needs no extra software:
stats/netstats.py is plain Python (3.11 or newer, standard library only) and stores its history in SQLite.
what it shows
| Section | What you see |
|---|---|
| Overview | Users online, the 30-day peak, servers linked, link availability, channels, services status. A world map with every hub and leaf and the links between them (a split link turns red), users over 24 hours, 7 days, 30 days or a year, and every incident. |
| Links | Each link with a timeline of its outages, uptime for the range, how many times it split, and the last reason
(Ping timeout: 180 seconds, Connection closed by peer, SQUIT by <oper>: <reason>, ...). |
| Servers | Users and share per server, location, version, how long it has been up or linked, memory and CPU. |
| Users | Connections per hour of the week (a heatmap), and right now: TLS, logged in, away, opers. |
| Services | NickServ/ChanServ status, uptime and restarts, registered accounts and channels, new registrations per day. |
| Security (admin only) | The Protection bundle per server: DNSBL hits and bans, open proxies the scanner found, spam filter actions and how many rules are loaded. Bans per day by type and by who set them (DNSBL, scanner, spam filter, connect flood, opers), active K/G/Z-lines and the latest bans with their masks and reasons. |
| Health checks | netstats connects to every server from outside: each client port open or closed, how long the TLS handshake took, and how many days the TLS certificate has left. |
| Maintenance (admin only) | Tidying and running the panel (the servers and the network are never touched):
forget a server that was retired (its history, outages, health checks and location go; one that links again comes back on its own), or
every server that isn't linked at once; merge a renamed server's history into its new name; clear past incidents (uptime starts over) or the
ban history; run the health checks or look the locations up again right now; compact the database; plan maintenance (splits that start in a
window show as maintenance, cost no uptime and send no alert, and the next 7 days' windows are announced at the top of every page; tick
tell users on IRC and every user connected gets a notice now, reminders before it starts ([announce] reminders, 24 h and 1 h
by default) and a cancellation if you remove the window); set a server's
map position, location label or hide it (these override stats.toml [[servers]]); send a test alert; and the admin activity
log: logins, failed logins and every action, with who did it. From a shell: stats/netstats.py admin forget old.example.net,
forget-gone, merge OLD NEW, clear-incidents, clear-bans, reprobe, relocate, vacuum,
alert-test. |
how it works
There is no extra bot on your network and nothing to install on the leaves.
- The hub already knows the whole network. When services ask (a
SVCSTATSrequest over their link), it sends a snapshot (users, channels, every server and its uplink) and, from then on, every link, split (with its reason) and ban as it happens. - Every server sends its own numbers (CPU, memory, version, DNSBL, proxy scanner, spam filter) every
stats_intervalseconds, network-wide, as the stats line in the debug channel. The hub passes those on too. - Services (
bin/services, next to the hub) write all of it tostats/events.log: a snapshot every minute, events as they come. - netstats loads that log every minute into
stats/stats.db, probes the servers from outside, and shows the result.
The other way round, for planned maintenance told to IRC users: netstats appends the notice to stats/announce.queue, services
(checking it every few seconds) send it to the hub (SVCGLOBAL), and the hub gives it to its users as a server notice and passes it to
every other server (GNOTICE), which does the same. A server older than this ignores GNOTICE, so its users don't get it.
Since services run once per network, next to the hub, the panel runs there too. A leaf only needs stats_interval.
History is kept per minute for 7 days, per hour for 90 days and per day for retention_days (365 by default), so the database stays small.
turning it on
The quickest way is to answer yes in the config generator (sekurircd --makeconf or tools/makeconf.py), or tick it in the
web wizard. It writes stats/stats.toml with your admin login and sets stats_interval. By hand, on the hub:
./sekurircd enable-stats # writes stats/stats.toml from the template, collector on stats/netstats.py --user --admin --add yourname # a login for the panel (asks for its password) ./sekurircd start-stats # http://127.0.0.1:8089/admin/
Services notice stats/stats.toml within 30 seconds; nothing needs a restart and nobody is disconnected. Then, on every server
(hub and leaves), for CPU, memory, version, the protection numbers and the heatmap:
[debug_channel] enabled = false # the channel itself is optional stats_interval = 300
Apply that with /REHASH.
day to day
| Command | What it does |
|---|---|
./sekurircd start-stats / stop-stats / restart-stats | The panel alone. ./sekurircd start, stop and restart include it. |
./sekurircd status | Shows netstats: running (pid N), stopped or disabled. |
./sekurircd disable-stats | Everything off: stops the panel and renames stats.toml to stats.toml.disabled, so services stop collecting. History and logins are kept. |
./sekurircd enable-stats | Back on, exactly as it was. |
The panel logs to logs/netstats.log. With systemd, systemctl --user enable --now netstats runs it instead of the wrapper
(see install).
logins
There are two kinds of login. An admin sees everything. A viewer sees the same page without the Security section and without server IP addresses.
stats/netstats.py --user --admin --add alice # asks for the password stats/netstats.py --user --viewer --add staff stats/netstats.py --user --status # lists them stats/netstats.py --user --viewer --del staff stats/netstats.py --mkpasswd # just print a hash, for a [[users]] entry written by hand
They edit the [[users]] entries in stats/stats.toml (passwords are stored as scrypt hashes, like operator passwords) and the
running panel picks the change up at once. After 10 wrong passwords in 10 minutes, an address has to wait.
The logged-in page is at /admin/. The page at / sends you to the login form (/login) too, unless you set public = true:
then anyone gets the viewer page there, with a Log in button for the rest. Once logged in, the button on the right of the section bar (under the
Light/Dark toggle) says Log out: it ends the session at once. A session lasts 12 hours, and removing a login with --user --del (or changing its
password) ends its sessions too. Scripts can still use HTTP Basic: curl -u alice:password http://127.0.0.1:8089/admin/.
who sees what
| Public (no login) | Viewer login | Admin login | |
|---|---|---|---|
| Users, map, links and uptime, servers, services, health checks | yes | yes | yes |
| Software versions, CPU and memory per server | no | yes | yes |
| Why a link split | the kind only (Ping timeout, Closed by an operator, Connection lost) | in full, e.g. SQUIT by <oper>: <reason> | in full |
| Server IPs, probe errors, Security, Maintenance | no | no | yes |
"Public" is the page at / with public = true, and the [export] public_html file.
alerts
Set [alerts] webhook in stats.toml to a Discord, Slack, Mattermost or Rocket.Chat webhook (format = "json") or an ntfy
topic (format = "text") and the panel posts when a link has been down for down_minutes, services stop reporting, a probed port stops
answering, or a TLS certificate has fewer than cert_days left. Each problem is posted once, and once more when it's fixed; nothing is posted
during a planned maintenance window. Send a test alert on the Maintenance section checks the setup.
putting it online
By default the panel listens on 127.0.0.1:8089 only. To reach it from outside, either:
- put it behind Caddy (recommended): Caddy gets and renews a Let's Encrypt certificate by itself, so the panel is on
https://stats.example.net/with no certificate to manage and nothing but ports 80 and 443 open. Set the name instats/stats.toml(makeconf and the wizard ask for it):[http] bind = "127.0.0.1" port = 8089 hostname = "stats.example.net"
andnetstats.py checkprints the block for/etc/caddy/Caddyfile:stats.example.net { reverse_proxy 127.0.0.1:8089 }Thensudo systemctl reload caddy, an A/AAAA record forstats.example.netpointing at the hub, and TCP 80 and 443 open. Caddy passes the login through and tells the panel who the visitor is (X-Forwarded-For, believed only fromtrusted_proxies, which is127.0.0.1and::1oncehostnameis set), so a wrong password only locks out the address that typed it. - or behind nginx, if it already serves your website with HTTPS (set
hostnametoo, fortrusted_proxies):server { listen 443 ssl; server_name stats.example.net; # its own name: the panel's links start at / ssl_certificate /etc/letsencrypt/live/stats.example.net/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/stats.example.net/privkey.pem; location / { proxy_pass http://127.0.0.1:8089; proxy_set_header X-Forwarded-For $remote_addr; } } - or let it serve HTTPS itself: set
bind = "0.0.0.0"and pointtls_cert/tls_keyat a certificate (the ircd's works, for example"../config/tls/cert.pem"), and open the port in your firewall (below). - or just look at it over SSH:
ssh -L 8089:127.0.0.1:8089 yourhub, then openhttp://127.0.0.1:8089/admin/.
the port and the firewall
The port is port under [http] in stats/stats.toml (8089 by default; makeconf and the wizard ask for it).
After changing it, ./sekurircd restart-stats.
With bind = "127.0.0.1" (the default) the firewall needs nothing: only the reverse proxy or your SSH tunnel talk to the panel.
With any other address, nobody can reach the panel until the port is open in the server's firewall. Use the one your system runs
(replace 8089 with your port):
sudo ufw allow 8089/tcp # Ubuntu, Debian with ufw sudo firewall-cmd --permanent --add-port=8089/tcp # Fedora, RHEL, Rocky, Alma sudo firewall-cmd --reload sudo iptables -I INPUT -p tcp --dport 8089 -j ACCEPT # plain iptables sudo netfilter-persistent save # ...kept across reboots # pf (FreeBSD, OpenBSD, macOS): add to /etc/pf.conf, then: sudo pfctl -f /etc/pf.conf pass in proto tcp to port 8089
Cloud servers (AWS, Hetzner, OVH, DigitalOcean, ...) often have a second firewall in the provider's control panel (a "security group"
or "cloud firewall"): open the port there too. When the panel starts bound publicly, ./sekurircd start-stats,
netstats.py check and logs/netstats.log print these same commands with your port.
Without tls_cert, a public panel sends its logins in clear text (the login form), and netstats warns about it. Use HTTPS, or keep
127.0.0.1 behind a reverse proxy that has it.
static pages for a website
If you'd rather not run a web server at all, set [http] enabled = false and the paths under [export], and run
netstats.py render from cron. It writes a viewer page (public_html) and an admin page (admin_html, protect it with your
web server); each is a single self-contained HTML file.
*/5 * * * * cd /home/irc/SekurIRCd && python3 stats/netstats.py render
the map
The map is built into the page (Natural Earth, public domain), so it works without any outside request. Each server is placed by its address:
- run
stats/netstats.py geoip-updateonce a month to download the free DB-IP Lite city database (CC BY 4.0). Lookups are made locally: no server address is ever sent anywhere. - or place a server yourself, which also fixes a wrong guess:
[[servers]] name = "irc.example.net" # as in /LINKS location = "Amsterdam, NL" lat = 52.37 lon = 4.90
The same [[servers]] entry can set host (what to probe and locate, when the server name doesn't resolve), ports
(which ports the health checks try) and hide = true (leave it off the page).
configuration
stats/stats.toml, with every option explained in stats.template.toml:
| Section | What it sets |
|---|---|
[collector] | enabled (services collect), sample_seconds (snapshot interval, 60), log. |
[storage] | database, retention_days (7 to 3650). |
[http] | enabled, network_name, bind, port, tls_cert, tls_key, public,
hostname, trusted_proxies. |
[export] | public_html, admin_html: what render writes. |
[geoip] | file: the DB-IP database geoip-update downloads. |
[health] | ports, tls_ports, interval, timeout. |
[alerts] | webhook (off when empty), format (json or text), down_minutes (5),
cert_days (14). See alerts. |
[announce] | reminders (["24h", "1h"]): when users told about planned maintenance are reminded. |
[[users]], [[servers]] | Logins (managed with --user) and per-server overrides. |
tools/confcheck.py checks this file along with the others, tools/backup-config.sh backs it up with the database, and
tools/upgrade.py keeps both and restarts the panel after an upgrade.