nagios mysql

Nagios can be easily set up to handle graphing of mySQL database performance metrics. The set of indicators will be graphed by pnp4nagios, a performance data analyzer and grapher for Nagios.

After enabling graphing you will be able to observe trends over hour/day/week/month/year, identify degradation of your DB performance and with little tuning even issue alerts based on thresholds. The DB we're setting up monitoring for in this example is a mySQL DB used by DRUPAL, a popular CMS.


Some of the mySQL performance indicators provided by this set of plugins are:

  • database activity (selects/insert/delete/update..)
  • connections (how many of the max connections are used, number of threads running/connected)
  • command counters
  • files and tables
  • mySQL Handlers
  • mySQL Query Cache
  • Select Types
  • Sorts
  • Table Locks
  • Temporary Objects
  • Transaction Handler
  • InnoDB Buffer Pool
  • InnoDB Buffer Efficiency
  • InnoDB I/O (File Reads/Writes)
  • InnoDB I/O Pending
  • InnoDB Row Lock Time
  • InnoDB Row Lock Waits
  • InnoDB Row Operations

Shopping list

  • Nagios installation;
  • PHP4Nagios for graphing;
  • check_mysql_counters - nagios plugin and set of templates for pnp4nagios created by Jason Holtzapple;
  • mysql DB v5.6;
  • Access to your DB, if you want to create a dedicated user to be used for retrieving the stats;


1) Connect to your mySQL database and create a database user that will be used for monitoring

CREATE USER 'nagios_user'@'localhost' IDENTIFIED BY 'nagios_pass'; GRANT SELECT ON database.* TO 'nagios_user'@'localhost'; 

2) Copy the check_mysql_counters_56 plugin to your libexec folder


3) copy the pnp4nagios template corresponding to your DB system to the pnp4nagios template folder. Make sure the name of the template file is identical to the name of your check command (eg. check_dbstats) /usr/local/pnp4nagios/share/templates/check_dbstats.php

4) Check if the check_mysql_counters_56 script is able to retrieve the parameters needed for graphing. Note the user, pass and port have been replaced.

[nagios@vps52974 libexec]$ ./check_mysql_counters_56 -H -P 1000 -u nagios_user -p nagios_pass


5) Create the Nagios host, service and command definitions. Note the user, pass and port have been replaced.


define host{
use linux-server,host-pnp 

define service{ 
use local-service, srv-pnp 
service_description MYSQL_COUNTERS
check_command check_dbstats!1000!nagios_user!nagios_pass! 

define command{ 
command_name check_dbstats 
command_line $USER1$/check_mysql_counters_56 -H $HOSTADDRESS$ -P $ARG1$ -u $ARG2$ -p $ARG3$ 


Performance graphs plotted by PHP4Nagios

nagios mysql command counters

nagios mysql database activity

nagios mysql database connections

nagios mysql files and tables

nagios mysql innoDB buffer pool

nagios mysql innoDB buffer pool activity

nagios mysql innodb buffer pool efficiency

nagios mysql innodb IO

nagios mysql innodb IO pending

nagios mysql innodb row lock time

nagios mysql innodb row lock waits

nagios innodb row operations

nagios mysql handlers

nagios mysql query cache

nagios mysql select types

nagios mysql sorts

nagios mysql table locks

nagios mysql temporary objects

nagios mysql transaction handler