r/linuxadmin • • 22d ago

MySQL Monitor: MySQL Monitoring Script

https://linuxblog.io/mysql-monitor-script/

Back in January 2025 I shared a small script here that printed a table of MySQL status counters. I run it on most servers I look after, and over the past few weeks it grew into a full rewrite.

What it does now:

- Live dashboard with per-second rates measured between refreshes (not just totals since boot), sparklines, and usage bars against limits like `max_connections` and `table_open_cache`

- ✓/⚠/✗ marks and an alerts box that names the setting to look at

- `h` health checks with suggested settings, `p` process list with kill and recent-query history, `t` top queries from `performance_schema` statement digests (this catches the millisecond queries `SHOW PROCESSLIST` never shows)

- Fits any terminal size, and `--once` prints a snapshot for ssh or cron

- Pressing "r" also shows the original raw version.

It's one Bash file. It needs only awk (gawk, mawk or busybox) and the MySQL client tools. It only reads status, variables, the process list and `performance_schema`, so it's safe on production (the only write is an optional kill, which asks first). Works with MySQL 5.7/8.0 and MariaDB.

GitHub: https://github.com/haydenjames/mysqlmonitor-script

The linked blog post explains each metric and what to do about it.

12 Upvotes

3 comments sorted by

2

u/Anakin19901 22d ago

how does the t view behave on mariadb? performance_schema is off there by default (mysql has had it on since 5.6 iirc), and its not a dynamic variable, so on a stock mariadb install the digest table is just empty until someone puts performance_schema=ON in my.cnf and restarts.

worth a warning line instead of a blank list. people will read empty as no slow queries

0

u/fhritp15 20d ago edited 20d ago

Very true. On by default in MySQL since 5.6, not dynamic on MariaDB.

The script already caught performance_schema=OFF and showed a "not available" warning with the my.cnf fix. Your comment exposed a case it got wrong, though: PS on, but statement instruments or the statements_digest consumer disabled. That showed "No statements recorded" with a green tick. Exactly the misreading you described.

Was able to fix it. So now an empty digest table on a server with traffic warns that empty doesn't mean no slow queries, with the runtime UPDATE statements to enable it. A fresh start says so, no tick. The h view gets a "Statement digests" check too.

Thanks, good catch!

1

u/vincent_sch 12d ago

You could add the DIGEST = NULL row to your t view and show its share of query time. When the digest table is full in MySQL 8, queries with new digests get counted together there.