MK-LOADAVG(1)

πŸ“¦
version 7540 Β· 3 versions
, in fedora 43

MK-LOADAVG πŸ’…

the manual page, bestie edition β€” you're looking at mk-loadavg from the User Contributed Perl Documentation corner of the world. yes she's a Perl girlie and yes she's iconic.


✨ NAME ✨

mk-loadavg β€” watch MySQL load and take action when it gets too high. she's literally just standing there, watching, waiting, being observant πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

Usage: mk-loadavg [OPTION...] [DSN]

so mk-loadavg watches the load on a MySQL server and takes action if it is too high. vigilant queen behavior πŸ‘‘

like, say you wanna execute my_script.sh when Threads_running exceeds 10. you'd do:

mk-loadavg --watch "Status:status:Threads_running:>:10" \
  --execute-command my_script.sh

periodt. that's the whole vibe. no cap ✨


πŸ’€ RISKS πŸ’€

okay bestie, we HAVE to talk about risks. this section is here to inform you about the potential risks, whether known or unknown, of using this tool. the two main categories of risks are:

  1. those created by the nature of the tool (e.g. read-only tools vs. read-write tools), and
  2. those created by bugs. πŸ™ˆ

mk-loadavg merely reads and prints information by default, and is very low-risk πŸ“. the --execute-command option can execute user-specified commands β€” so like, that part is on you, girlie.

at the time of this release, we know of no bugs that could cause serious harm to users. we love a clean bill of health ✨

the authoritative source for updated information is always the online issue tracking system. issues that affect this tool will be marked as such. you can see a list of such issues at the following URL:

http://www.maatkit.org/bugs/mk-loadavg

see also BUGS for more information on filing bugs and getting help. 🫢


🌸 DESCRIPTION 🌸

mk-loadavg watches a MySQL server and takes action when a defined threshold is exceeded. it's giving guard dog but make it database πŸ’…

one or more items can be watched, including:

  • MySQL status values from SHOW STATUS
  • SHOW INNODB STATUS
  • SHOW SLAVE STATUS
  • the three system load averages from uptime
  • values from vmstat

watched items and their threshold values are specified by --watch. every item is checked at intervals (see --interval). ⏰

by default, if any one item's check returns true (i.e. its threshold is exceeded), then --execute-command is executed. but! specifying --and requires that every item has exceeded its threshold before --execute-command is executed. strict queen energy, we respect it πŸ‘‘


🌈 OUTPUT 🌈

if you specify --verbose, mk-loadavg prints information to STDOUT about each check for each watched item. πŸ“’

else, it prints nothing and --execute-command (if specified) is responsible for logging any information you want. silent but deadly, we stan 🀫


⭐ EXIT STATUS ⭐

an exit status of 0 (sometimes also called a return value or return code) indicates success βœ…. any other value represents the exit status of the Perl process itself, or of the last forked process that exited if there were multiple servers to monitor. iykyk πŸ’›


...and that's part one bestie, don't go anywhere, there's more πŸ’–

✨ OPTIONS ✨

okay bestie, so this tool also takes extra command-line args. Peep the SYNOPSIS and the usage info for the deets. πŸ’…


  • --and β€” group: Action β€” Only fire the actions when all your --watch items are past their thresholds. Normally it's "any one goes over and we move", but this makes it "every single watched item has to go over before any action happens". That's the whole vibe.
  • --ask-pass β€” Prompt for a password when connecting to MySQL. πŸ”
  • --charset β€” short form: -A; type: string β€” Default character set. If the value is utf8, it sets Perl's binmode on STDOUT to utf8, passes the mysql_enable_utf8 option to DBD::mysql, and runs SET NAMES UTF8 after connecting to MySQL. Any other value sets binmode on STDOUT without the utf8 layer, and runs SET NAMES after connecting to MySQL. No cap, that's the exact behavior. ✨
  • --config β€” type: Array β€” Read this comma-separated list of config files. If you use it, it has to be the first option on the command line. Like, first first. πŸ‘‘
  • --daemonize β€” Fork to the background and detach from the shell. POSIX operating systems only. 🧚
  • --database β€” short form: -D; type: string β€” Database to use. Simple.
  • --defaults-file β€” short form: -F; type: string β€” Only read mysql options from the given file. You must give an absolute pathname. Don't try relative, bestie. 🚫
  • --execute-command β€” type: string; group: Action β€” Execute this command when watched items exceed their threshold values.

This command runs every time a --watch item exceeds its threshold (or all items if --and is specified). Example: if you specify --watch "Server:vmstat:swpd:":0">, then this command executes when the server begins to swap, and again at each --interval so long as the server is still swapping.

After the command is executed, mk-loadavg has no control over it, so it is responsible for its own info gathering, logging, interval, etc. Since the command is spawned from mk-loadavg, its STDOUT, STDERR and STDIN are closed so it doesn't interfere with mk-loadavg. Therefore, the command must redirect its output to files or some other destination. For example, if you specify --execute-command 'echo Hello', you will not see Hello printed anywhere (neither to screen nor --log) because STDOUT is closed for the command.

No information from mk-loadavg is passed to the command.

See also --and.

  • --help β€” Show help and exit.
  • --host β€” short form: -h; type: string β€” Connect to host.
  • --interval β€” type: time; default: 60s; group: Watch β€” How long to sleep between each check.
  • --log β€” type: string β€” Print all output to this file when daemonized. Output from --execute-command is not printed to this file. Important.
  • --password β€” short form: -p; type: string β€” Password to use when connecting.
  • --pid β€” type: string β€” Create the given PID file when daemonized. The file contains the process ID of the daemonized instance. The PID file is removed when the daemonized instance exits. The program checks for the existence of the PID file when starting; if it exists and the process with the matching PID exists, the program exits. So don't leave stale PID files lying around, periodt. πŸ’€
  • --port β€” short form: -P; type: int β€” Port number to use for connection.
  • --run-time β€” type: time β€” Time to run before exiting. Causes mk-loadavg to stop after the specified time has elapsed. Optional suffix: s=seconds, m=minutes, h=hours, d=days; if no suffix, s is used.
  • --sentinel β€” type: string; default: /tmp/mk-loadavg-sentinel β€” Exit if this file exists.
  • --set-vars β€” type: string; default: wait_timeout=10000 β€” Set these MySQL variables. Immediately after connecting to MySQL, this string will be appended to SET and executed.
  • --socket β€” short form: -S; type: string β€” Socket file to use for connection.
  • --stop β€” Stop running instances by creating the --sentinel file.
  • --user β€” short form: -u; type: string β€” User for login if not current user.
  • --verbose β€” short form: -v β€” Print information to STDOUT about what is being done. This can be used as a heartbeat to see that mk-loadavg is still properly watching all its values. If --log is specified, this information will be printed to that file instead.
  • --version β€” Show version and exit.
  • --vmstat β€” type: string; default: vmstat 1 2; group: Watch β€” vmstat command for --watch Server:vmstat:.... The vmstat output should look like:
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
0  0      0 590380 143756 571852    0    0     6     9  228  340  4  1 94  1
0  0      0 590400 143764 571852    0    0     0    28  751  818  4  2 90  3

The second line from the top needs to be column headers for subsequent lines. Values are taken from the last line.

The default, vmstat 1 2, gets current values. Running just vmstat would get average values since last reboot.

  • --wait β€” short form: -w; type: time; default: 60s β€” Wait this long to reconnect to MySQL. If the MySQL server goes away between --interval checks, mk-loadavg will attempt to reconnect to MySQL forever, sleeping this amount of time in between attempts.
  • --watch β€” type: string; group: Watch β€” A comma-separated list of watched items and their thresholds (required). Each watched item is a string of arguments separated by colons (like arg:arg). Each argument defines the watch item: what particular value is watched and how to compare the current value to a threshold value (N). Multiple watched items can be given by separating them with a comma, and the same watched item can be given multiple times (but, of course, it only makes sense to do this if the comparison and/or threshold values are different).

The first argument is the most important and is case-sensitive. It defines the module responsible for watching the value. For example,

--watch Status:...

causes the WatchStatus module to be loaded. The second and subsequent arguments are passed to the WatchStatus module which parses them. Each watch module requires different arguments. The watch modules included in mk-loadavg and what arguments they require are listed below.

This is a common error when specifying --watch on the command line:

mk-loadavg --watch Server:vmstat:swpd:>:0

Failed to load --watch WatchServer: Error parsing parameters vmstat:swpd:: No comparison parameter; expected >, < or = at ./mk-loadavg line 3100.

The --watch values need to be quoted:

mk-loadavg --watch "Server:vmstat:swpd:>:0"

πŸŽ€ Status πŸŽ€

Watch SHOW STATUS, SHOW INNODB STATUS, and SHOW SLAVE STATUS values. The value argument is case-sensitive.

--watch Status:[status|innodb|slave]:value:[><=]:N

Examples:

--watch "Status:status:Threads_connected:>:16"
--watch "Status:innodb:Innodb_buffer_pool_hit_rate:<:0.98"
--watch "Status:slave:Seconds_behind_master:>:300"

You can easily see what values are available for SHOW STATUS and SHOW SLAVE STATUS, but the values for SHOW INNODB STATUS are not apparent. Some common values are:

Innodb_buffer_pool_hit_rate
Innodb_buffer_pool_pages_created_sec
Innodb_buffer_pool_pages_dirty
Innodb_buffer_pool_pages_read_sec
Innodb_buffer_pool_pages_written_sec
Innodb_buffer_pool_pending_data_writes
Innodb_buffer_pool_pending_dirty_writes
Innodb_buffer_pool_pending_fsyncs
Innodb_buffer_pool_pending_reads
Innodb_buffer_pool_pending_single_writes
Innodb_common_memory_allocated
Innodb_data_fsyncs_sec
Innodb_data_pending_fsyncs
Innodb_data_pending_preads
Innodb_data_pending_pwrites
Innodb_data_reads_sec
Innodb_data_writes_sec
Innodb_insert_buffer_pending_reads
Innodb_rows_read_sec
Innodb_rows_updated_sec
lock_wait_time
mysql_tables_locked
mysql_tables_used
row_locks
io_avg_wait
io_wait
max_io_wait

Several of those values can appear multiple times in the SHOW INNODB STATUS output. The value used for comparison is always the highest value. So the value for io_wait is the highest io_wait value for all the IO threads.

🧚 Processlist 🧚

Watch aggregated SHOW PROCESSLIST values.

--watch Processlist:[db|user|host|state|command]:value:[count|time]:[><=]:N

Examples:

--watch "Processlist:state:Locked:count:>:5"
--watch "Processlist:command:Query:time:<:1"

⭐ Server ⭐

Watch server values.

--watch Server:loadavg:[1|5|15]:[><=]:N
--watch Server:vmstat:[r|b|swpd|free|buff|cache|si|so|bi|bo|in|cs|us|sy|id|wa]:[><=]:N

Examples:

--watch "Server:loadavg:5:>:4.00"
--watch "Server:vmstat:swpd:>:0"
--watch "Server:vmstat:free:=:0"

See --vmstat.


🌈 DSN OPTIONS 🌈

These DSN options are used to create a DSN. Each option is given like option=value. The options are case-sensitive, so P and p are not the same option. There cannot be whitespace before or after the = and if the value contains whitespace it must be quoted. DSN options are comma-separated. See the maatkit manpage for full details.

  • A β€” dsn: charset; copy: yes β€” Default character set.
  • D β€” dsn: database; copy: yes β€” Default database.
  • F β€” dsn: mysql_read_default_file; copy: yes β€” Only read default options from the given file
  • h β€” dsn: host; copy: yes β€” Connect to host.
  • p β€” dsn: password; copy: yes β€” Password to use when connecting.
  • P β€” dsn: port; copy: yes β€” Port number to use for connection.
  • S β€” dsn: mysql_socket; copy: yes β€” Socket file to use for connection.
  • u β€” dsn: user; copy: yes β€” User for login if not current user.

🌈 DOWNLOADING 🌈

Okay bestie, getting your hands on Maatkit is so easy, you can literally grab it from Google Code at <http://code.google.com/p/maatkit/>, or you can just snag any of the tools with a command like this:

wget http://www.maatkit.org/get/toolname
or
wget http://www.maatkit.org/trunk/toolname

Where "toolname" gets swapped out for the name β€” or even just a fragment of a name β€” of literally any Maatkit tool. And once it's downloaded? It's ready to run, no cap. No installation needed, zero setup era. πŸ’…

The first URL hands you the latest released version of the tool, and the second one gets you the latest trunk code from Subversion. Pick your fighter.


🌸 ENVIRONMENT 🌸

The environment variable MKDEBUG turns on verbose debugging output in all of the Maatkit tools. The way that one little variable unlocks the whole lore:

MKDEBUG=1 mk-....
✨ Turn this on when something's acting sus and you need to see everything.

πŸ¦‹ SYSTEM REQUIREMENTS πŸ¦‹

You need Perl, DBI, DBD::mysql, and some core packages that ought to already be installed in any reasonably new version of Perl. So like, if your Perl is even slightly recent, you're probably chilling. 🫢


πŸ’€ BUGS πŸ’€

For a list of known bugs, go look at <http://www.maatkit.org/bugs/mk-loadavg>.

Please use Google Code Issues and Groups to report bugs or request support: <http://code.google.com/p/maatkit/>. You can also join #maatkit on Freenode to discuss Maatkit. Come hang out, it's a vibe.

And when you report something, please include:

  • the complete command-line you used to reproduce the problem you're seeing,
  • the version of all MySQL servers involved,
  • the complete output of the tool when you run it with --version,
  • and if possible, the debugging output produced by running with the MKDEBUG=1 environment variable.
πŸŽ€ Bestie I'm begging you, include all of it. It makes fixing things so much faster.

This program is copyright 2008-2011 Baron Schwartz. Feedback and improvements are welcome. Truly, send them.

THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2; OR the Perl Artistic License. On UNIX and similar systems, you can issue man perlgpl or man perlartistic to read these licenses.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.


✨ AUTHOR ✨

Baron Schwartz, Daniel Nichter


πŸ’– ABOUT MAATKIT πŸ’–

This tool is part of Maatkit, a toolkit for power users of MySQL. Maatkit was created by Baron Schwartz; Baron and Daniel Nichter are the primary code contributors. Both are employed by Percona. Financial support for Maatkit development is primarily provided by Percona and its clients. Iconic support system honestly.


⭐ VERSION ⭐

This manual page documents Ver 0.9.7 Distrib 7540 $Revision: 7460 $.


And that's a wrap on the whole page, bestie! πŸŽ€ This lil doc was put together with perl v5.42.0, dated 2025-07-24, and it lives at MK-LOADAVG(1). Go check your load average, it's giving main character energy. πŸ’…βœ¨

πŸ“¦ where this page comes from