MK-LOADAVG(1)
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:
- those created by the nature of the tool (e.g. read-only tools vs. read-write tools), and
- 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 STATUSSHOW 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--watchitems 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 isutf8, it sets Perl'sbinmodeonSTDOUTtoutf8, passes themysql_enable_utf8option toDBD::mysql, and runsSET NAMES UTF8after connecting to MySQL. Any other value setsbinmodeonSTDOUTwithout theutf8layer, and runsSET NAMESafter 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-commandis 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. Causesmk-loadavgto stop after the specified time has elapsed. Optional suffix:s=seconds,m=minutes,h=hours,d=days; if no suffix,sis 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 toSETand executed.--socketβshort form: -S; type: stringβ Socket file to use for connection.--stopβ Stop running instances by creating the--sentinelfile.--userβshort form: -u; type: stringβ User for login if not current user.--verboseβshort form: -vβ Print information toSTDOUTabout what is being done. This can be used as a heartbeat to see that mk-loadavg is still properly watching all its values. If--logis 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--watchServer: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--intervalchecks, 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 (likearg: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 filehβ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=1environment variable.
π Bestie I'm begging you, include all of it. It makes fixing things so much faster.
π COPYRIGHT, LICENSE AND WARRANTY π
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
- fedora 43: maatkit 7540-39.fc43 Β· GPL-2.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms