SlideShare a Scribd company logo
Geert Vanderkelen
MySQL Senior Support Engineer
Sun Microsystems
Monitoring MySQL
Copyright © 2008 Sun Microsystems, Inc.
Agenda
• Short intro into MySQL, the company
• Monitoring MySQL: some examples
• Nagios plugins for MySQL
• MySQL Enterprise Monitor
Copyright © 2008 Sun Microsystems, Inc.
From MySQL
to Sun
Whoohoo!
Copyright © 2008 Sun Microsystems, Inc.
What Makes MySQL Special
• OpenSource!
• Commercial and Community Support
• Storage engines
• Simplicity
• Sun Microsystems
• MySQL 5.1 is coming! MySQL Cluster 6.2 is here!
Copyright © 2008 Sun Microsystems, Inc.
Monitoring MySQL
Basics and Some examples..
Copyright © 2008 Sun Microsystems, Inc.
Getting Status Information
• SHOW GLOBAL STATUS
> Global keyword is important!
• Snapshot regularly
> mysqladmin -i 20 extended-status >> status.log
• Also available as information_schema.global_status
• For example:
> Com_xxx counter variables
> Questions for Queries/Sec
Copyright © 2008 Sun Microsystems, Inc.
Index usage
• Find out if you do lots of table scans
mysql> SHOW GLOBAL STATUS
LIKE ‘Handler_read%’;
Handler_read_first 83574685
Handler_read_key 11274900036
Handler_read_next 31376780526
Handler_read_prev 34482622
Handler_read_rnd 265239832
Handler_read_rnd_next 307182727076
((Handler_read_rnd + Handler_read_rnd_next)
/ (∑(Handler_read_%))*100 = 87.8
Copyright © 2008 Sun Microsystems, Inc.
Temp. Tables Going To Disk?
mysql> SHOW GLOBAL STATUS
LIKE ‘Created_tmp%’;
Created_tmp_disk_tables 5032520
Created_tmp_files 71
Created_tmp_tables 13117923
(Created_tmp_disk_tables
/ Created_tmp_tables) *100 = 38.3
Copyright © 2008 Sun Microsystems, Inc.
Check # Of Processes
• To much long running process: mostly trouble
• SHOW PROCESSLIST or:
mysql> USE information_schema;
mysql> SELECT COUNT(*) FROM processlist
WHERE user <> 'replication' AND
id <> CONNECTION_ID() AND
time > 60 AND
command <> 'Sleep';
Copyright © 2008 Sun Microsystems, Inc.
Check uptime
• MySQL might crash and restart quickly
• Other checks might miss it
mysql> USE information_schema;
mysql> SELECT DATE_SUB(NOW(),
INTERVAL variable_value SECOND) AS started,
variable_value AS uptime
FROM global_status WHERE variable_name = 'UPTIME';
+---------------------+--------+
| STARTED | UPTIME |
+---------------------+--------+
| 2008-09-08 10:58:24 | 36604 |
+---------------------+--------+
Copyright © 2008 Sun Microsystems, Inc.
InnoDB Table Size
• Usually auto-extends
• innodb_data_file_path = ibdata1:200M
• Before MySQL 5.1 in table comments!
mysql> USE information_schema;
mysql> SELECT data_free*1024 AS 'InnoDB free space'
FROM tables WHERE table_name = 'innotest';
+-------------------+
| InnoDB free space |
+-------------------+
| 201326592 |
+-------------------+
Copyright © 2008 Sun Microsystems, Inc.
InnoDB Buffer Pool Hit Rate
• Is the buffer still big enough?
mysql> SHOW GLOBAL STATUS
LIKE 'InnoDB_buffer_pool_read%';
+-----------------------------------+------------+
| Variable_name | Value |
+-----------------------------------+------------+
..
| Innodb_buffer_pool_read_requests | 2226519108 |
| Innodb_buffer_pool_reads | 74845 |
+-----------------------------------+------------+
100 * ( 1 - (Innodb_buffer_pool_reads
/ Innodb_buffer_pool_read_requests)) = 99.99%
Copyright © 2008 Sun Microsystems, Inc.
Checking configuration
• SHOW GLOBAL VARIABLES
> Also information_schema.global_variables
• What version is running?
• Default storage engine still InnoDB?
• Global character set is still UTF-8?
• Logs enabled?
> slow and general query log (online as of 5.1)
Copyright © 2008 Sun Microsystems, Inc.
Logging Enabled?
• General log
> Log every statement, useful for debugging
> SHOW GLOBAL VARIABLES LIKE 'general_log';
• Slow query log
> Show long running queries, or not using indexes
> SHOW GLOBAL VARIABLES LIKE 'slow_query_log';
• As of MySQL 5.1
> Can be toggled online, and logged to tables
• Should not be running all the time
Copyright © 2008 Sun Microsystems, Inc.
Monitoring Replication
• On Master
> Check number of binary logs
> Limit number of slaves
• On Slave
> Use SHOW SLAVE STATUS
> Check seconds behind master
> Check if still reading from Master
> etc.
Copyright © 2008 Sun Microsystems, Inc.
Master And Her Slaves
• Master can handle lots of slave
> But it’s good to set a limit
• SHOW SLAVE HOSTS
> Does list registered hosts, not connected ones
mysql> SHOW SLAVE HOSTS;
+-----------+--------+------+...+-----------+
| Server_id | Host | Port |...| Master_id |
+-----------+--------+------+...+-----------+
| 2 | cent02 | 3306 |...| 1 |
+-----------+--------+------+...+-----------+
1 row in set (0.00 sec)
Copyright © 2008 Sun Microsystems, Inc.
Number Of Binary Logs
• Regularly causing disk space issues
> Can use PURGE MASTER LOGS
• SHOW BINARY LOGS
mysql> SHOW BINARY LOGS;
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| cent01bin.000001 | 125 |
| cent01bin.000002 | 1021 |
| cent01bin.000004 | 125 |
| cent01bin.000005 | 462 |
+------------------+-----------+
Copyright © 2008 Sun Microsystems, Inc.
Slave status
mysql> SHOW SLAVE STATUSG
..
Master_Host: 192.168.14.100
Master_User: replication
Master_Port: 3306
..
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
..
Seconds_Behind_Master: 0
..
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Copyright © 2008 Sun Microsystems, Inc.
Seconds Behind Master
• Number of seconds elapsed since timestamp of last
statement received from Master
• Only useful in fast networks
> Slow I/O gives bad approximation
• Use a heartbeat table
> INSERT INTO replication_ping VALUES (NOW())
> Check on slave when table is updated
> Calculate time difference
> Or use mk-heartbeat from Maatkit
Copyright © 2008 Sun Microsystems, Inc.
Monitoring Cluster
• Still not easy to do
• Using NDB API
• Parse logs
• Using ndb_mgm
shell> ndb_mgm -e "SHOW"
Connected to Management Server at: localhost:1406
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=3 @10.100.9.8 (mysql-5.1.27 ndb-6.3.17, Nodegroup: 0, Master)
id=4 @10.100.9.9 (mysql-5.1.27 ndb-6.3.17, Nodegroup: 0)
[ndb_mgmd(MGM)] 2 node(s)
id=1 @10.100.9.6 (mysql-5.1.27 ndb-6.3.17)
id=2 (not connected, accepting connect from ndbsup-priv-2)
[mysqld(API)] 7 node(s)
id=5 @10.100.9.6 (mysql-5.1.27 ndb-6.3.17)
id=6 (not connected, accepting connect from any host)
Copyright © 2008 Sun Microsystems, Inc.
Useful Tools
• MySQL client tools and SQL!
• MySQL Enterprise Monitor
> http://www.mysql.com/products/enterprise/
• innotop
> http://innotop.sourceforge.net/
• Maatkit
> http://www.maatkit.org/
Copyright © 2008 Sun Microsystems, Inc.
Nagios + MySQL
Monitoring MySQL with Nagios
Copyright © 2008 Sun Microsystems, Inc.
Configuration tips
• Using hostgroups
> Useful for replication setups or Cluster
define hostgroup { hostgroup_name mysql-masters }
define hostgroup { hostgroup_name mysql-slaves }
define host {
use generic-virtualbox
host_name cent02
alias cent02 (VMWare)
address 192.168.14.101
hostgroups virtualboxes,vmware,mysql-slaves
}
define service {
use generic-service
hostgroup_name mysql-slaves
service_description Slave SQL Thread
check_command mysql_repl_sqlthread
}
Copyright © 2008 Sun Microsystems, Inc.
Configuration tips (2)
• Secure your setup: SSL or SSH
• Don’t use MySQL root user for checks
• Could use NRPE (Nagios add-on)
Copyright © 2008 Sun Microsystems, Inc.
Some plugins..
• Oli Sennhauser
> http://www.shinguz.ch/MySQL/mysql_monitoring.html
Copyright © 2008 Sun Microsystems, Inc.
Some plugins.. (2)
• check_mysql_perf
> http://www.consol.com/opensource/nagios/check-mysql-perf/
• Checks various buffers
> hit rates for qcache, keycache
• InnoDB checks
> bufferpool, etc..
• Checks for slow queries
• and more..
Copyright © 2008 Sun Microsystems, Inc.
Write your own!
• http://nagiosplug.sourceforge.net/developer-guidelines.html
• Quite easy: here a very simple plugin
#!/bin/sh
mysql -e "SELECT NOW()" -NB -h $1 -u$2 -p$3 2>/dev/null
if [ $? != 0 ];
then
echo "Oops!" ; exit 2 # Criticial
fi
exit 0 # OK
shell> ./simple.sh cent02.kemuri.net agent cop
2008-09-08 13:37:09
shell> ./simple.sh cent02.kemuri.net agent cap
Oops!
Copyright © 2008 Sun Microsystems, Inc.
Write Your Own with Python
def get_uptime():
global OPTIONS
db = MySQLdb.connection(host=OPTIONS['hostname'],
user=OPTIONS['user'],passwd=OPTIONS['password'])
db.query("SHOW GLOBAL STATUS LIKE 'Uptime'")
res = db.store_result()
row = res.fetch_row(1)
return int(row[0][1])
def check_uptime(uptime):
global OPTIONS, ERRORS
line = 'Uptime %ds' % uptime
err = ERRORS['OK']
if uptime < OPTIONS['critical']:
err = ERRORS['CRITICAL']
elif uptime < OPTIONS['warning']:
err = ERRORS['WARNING']
print line
sys.exit(err)
• Email geert@mysql.com for the full version
Copyright © 2008 Sun Microsystems, Inc.
MySQL Enterprise Monitor
What is it, and how combining it with Nagios?
Copyright © 2008 Sun Microsystems, Inc.
MySQL Enterprise Monitor (MEM)
• Single, consolidated view
• Auto discovery of MySQL Servers, Replication
Topologies
• Problem Query Detection, Analysis and Tuning – New!
• Customizable rules-based monitoring and alerts
• Identifies problems before they occur
• Reduces risk of downtime
• Easier to scale-out without requiring more DBAs
Copyright © 2008 Sun Microsystems, Inc.
Copyright © 2008 Sun Microsystems, Inc.
Advisors/Rules
• Comparable with Nagios plugins
• Possible using Nagios plugins making custom
Advisors for MEM
• Can use SNMP Traps
Copyright © 2008 Sun Microsystems, Inc.
MEM, Nagios and SNMP
• Using Passive Service Checks
• Handle SNMP traps
> Using traphandle in snmptrapd configuration
• Nagios and MEM host names must match
MEMView
NagiosView
Copyright © 2008 Sun Microsystems, Inc.
MEM, Nagios and SNMP (cont.)
• Configure snmptrapd to handle MEM traps
# Usually /etc/snmp/snmptrapd.conf
traphandle default /path/to/handle_mysql_memtrap.sh
• Setup Nagios
define service {
use generic-service
service_description MEM SNMP Trap
hostgroup_name mysql-masters,mysql-slaves
register 0
check_command check_no
is_volatile 1
max_check_attempts 1
retry_check_interval 1
normal_check_interval 4
active_checks_enabled 0
passive_checks_enabled 1
}
Copyright © 2008 Sun Microsystems, Inc.
SNMP Handler Script (part 1)
read host
read ip
while read oid val
do
val=`expr "$val" : '"(.*)"'`
vars="$vars;; $oid: $val"
case "$oid" in
MYSQLTRAP-MIB::advisor.0)
hostname=$val
;;
MYSQLTRAP-MIB::advisor.1)
memstate=$val
;;
MYSQLTRAP-MIB::advisor.4)
message=$val
;;
esac
done
• Reading SNMP trap information
Copyright © 2008 Sun Microsystems, Inc.
SNMP Handler Script (part 2)
• Translate and send it to Nagios.
state=$STATE_OK
case "$memstate" in
critical)
state=$STATE_CRITICAL
;;
warning|info|success)
state=$STATE_WARNING
;;
esac
datetime=`date +%s`
cmd="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$hostname;
$service;$state;$message"
echo $cmd >> $nagioscmdfile
Copyright © 2008 Sun Microsystems, Inc.
Some Links..
• MySQL Enterprise
> http://www.mysql.com/products/enterprise/
• Nagios documentation
> http://nagios.sourceforge.net/docs/2_0/passivechecks.html
> http://www.nagios.org/faqs/viewfaq.php?faq_id=29
• Email Geert for the handler script
Monitoring MySQL
Geert Vanderkelen
geert.vanderkelen@sun.com

More Related Content

PDF
Troubleshooting MySQL Performance
PDF
New features in Performance Schema 5.7 in action
PDF
MySQL SQL Tutorial
PDF
Performance Schema for MySQL Troubleshooting
PDF
Moving to the NoSQL side: MySQL JSON functions
PDF
MySQL Performance Schema in Action
PDF
제 8회 엑셈 수요 세미나 자료 연구컨텐츠팀
PDF
Preparse Query Rewrite Plugins
Troubleshooting MySQL Performance
New features in Performance Schema 5.7 in action
MySQL SQL Tutorial
Performance Schema for MySQL Troubleshooting
Moving to the NoSQL side: MySQL JSON functions
MySQL Performance Schema in Action
제 8회 엑셈 수요 세미나 자료 연구컨텐츠팀
Preparse Query Rewrite Plugins

What's hot (20)

PDF
Using Apache Spark and MySQL for Data Analysis
PDF
Introducing new SQL syntax and improving performance with preparse Query Rewr...
PDF
Lab 1 my sql tutorial
PDF
Memcached Functions For My Sql Seemless Caching In My Sql
PDF
Managing MariaDB Server operations with Percona Toolkit
PDF
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
PDF
Performance schema 설정
PDF
New features in Performance Schema 5.7 in action
PDF
Basic MySQL Troubleshooting for Oracle Database Administrators
PPTX
MySQLinsanity
PDF
Why Use EXPLAIN FORMAT=JSON?
PDF
Introduction into MySQL Query Tuning
PDF
Second Step to the NoSQL Side: MySQL JSON Functions
PPTX
My sql failover test using orchestrator
PDF
Performance Schema for MySQL Troubleshooting
PDF
Troubleshooting MySQL Performance
PDF
Amazon aurora 1
PDF
Performance Schema for MySQL Troubleshooting
PDF
Curso de MySQL 5.7
PDF
Introduction to MySQL InnoDB Cluster
Using Apache Spark and MySQL for Data Analysis
Introducing new SQL syntax and improving performance with preparse Query Rewr...
Lab 1 my sql tutorial
Memcached Functions For My Sql Seemless Caching In My Sql
Managing MariaDB Server operations with Percona Toolkit
제 6회 엑셈 수요 세미나 자료 연구컨텐츠팀
Performance schema 설정
New features in Performance Schema 5.7 in action
Basic MySQL Troubleshooting for Oracle Database Administrators
MySQLinsanity
Why Use EXPLAIN FORMAT=JSON?
Introduction into MySQL Query Tuning
Second Step to the NoSQL Side: MySQL JSON Functions
My sql failover test using orchestrator
Performance Schema for MySQL Troubleshooting
Troubleshooting MySQL Performance
Amazon aurora 1
Performance Schema for MySQL Troubleshooting
Curso de MySQL 5.7
Introduction to MySQL InnoDB Cluster
Ad

Similar to OSMC 2008 | Monitoring MySQL by Geert Vanderkelen (20)

PDF
Nagios Conference 2012 - Sheeri Cabral - Alerting With MySQL and Nagios
PDF
MySQL highav Availability
PDF
Buytaert kris my_sql-pacemaker
PPTX
Percona Live UK 2014 Part III
PPT
2010 12 mysql_clusteroverview
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
PDF
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
PDF
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
PPTX
MySQL Tech Tour 2015 - Manage & Tune
PPT
MySQL Performance Tuning at COSCUP 2014
ODP
MySQL HA with PaceMaker
PDF
Has MySQL grown up?
PDF
Get mysql clusterrunning-windows
PPTX
Mysql-Basics.pptx
PDF
MySQL Performance for DevOps
PDF
Monitor some of the things
PDF
MySQL performance webinar
PDF
Mysql wp cluster_quickstart_windows
PDF
Sunshine php my sql 8.0 v2
PDF
Drupal Con My Sql Ha 2008 08 29
Nagios Conference 2012 - Sheeri Cabral - Alerting With MySQL and Nagios
MySQL highav Availability
Buytaert kris my_sql-pacemaker
Percona Live UK 2014 Part III
2010 12 mysql_clusteroverview
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
Nagios Conference 2013 - Sheeri Cabral - Alerting With MySQL and Nagios
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Tech Tour 2015 - Manage & Tune
MySQL Performance Tuning at COSCUP 2014
MySQL HA with PaceMaker
Has MySQL grown up?
Get mysql clusterrunning-windows
Mysql-Basics.pptx
MySQL Performance for DevOps
Monitor some of the things
MySQL performance webinar
Mysql wp cluster_quickstart_windows
Sunshine php my sql 8.0 v2
Drupal Con My Sql Ha 2008 08 29
Ad

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
history of c programming in notes for students .pptx
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
ai tools demonstartion for schools and inter college
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
medical staffing services at VALiNTRY
System and Network Administraation Chapter 3
Design an Analysis of Algorithms II-SECS-1021-03
VVF-Customer-Presentation2025-Ver1.9.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
history of c programming in notes for students .pptx
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
Operating system designcfffgfgggggggvggggggggg
ai tools demonstartion for schools and inter college
Reimagine Home Health with the Power of Agentic AI​
Softaken Excel to vCard Converter Software.pdf
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Transform Your Business with a Software ERP System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

OSMC 2008 | Monitoring MySQL by Geert Vanderkelen

  • 1. Geert Vanderkelen MySQL Senior Support Engineer Sun Microsystems Monitoring MySQL
  • 2. Copyright © 2008 Sun Microsystems, Inc. Agenda • Short intro into MySQL, the company • Monitoring MySQL: some examples • Nagios plugins for MySQL • MySQL Enterprise Monitor
  • 3. Copyright © 2008 Sun Microsystems, Inc. From MySQL to Sun Whoohoo!
  • 4. Copyright © 2008 Sun Microsystems, Inc. What Makes MySQL Special • OpenSource! • Commercial and Community Support • Storage engines • Simplicity • Sun Microsystems • MySQL 5.1 is coming! MySQL Cluster 6.2 is here!
  • 5. Copyright © 2008 Sun Microsystems, Inc. Monitoring MySQL Basics and Some examples..
  • 6. Copyright © 2008 Sun Microsystems, Inc. Getting Status Information • SHOW GLOBAL STATUS > Global keyword is important! • Snapshot regularly > mysqladmin -i 20 extended-status >> status.log • Also available as information_schema.global_status • For example: > Com_xxx counter variables > Questions for Queries/Sec
  • 7. Copyright © 2008 Sun Microsystems, Inc. Index usage • Find out if you do lots of table scans mysql> SHOW GLOBAL STATUS LIKE ‘Handler_read%’; Handler_read_first 83574685 Handler_read_key 11274900036 Handler_read_next 31376780526 Handler_read_prev 34482622 Handler_read_rnd 265239832 Handler_read_rnd_next 307182727076 ((Handler_read_rnd + Handler_read_rnd_next) / (∑(Handler_read_%))*100 = 87.8
  • 8. Copyright © 2008 Sun Microsystems, Inc. Temp. Tables Going To Disk? mysql> SHOW GLOBAL STATUS LIKE ‘Created_tmp%’; Created_tmp_disk_tables 5032520 Created_tmp_files 71 Created_tmp_tables 13117923 (Created_tmp_disk_tables / Created_tmp_tables) *100 = 38.3
  • 9. Copyright © 2008 Sun Microsystems, Inc. Check # Of Processes • To much long running process: mostly trouble • SHOW PROCESSLIST or: mysql> USE information_schema; mysql> SELECT COUNT(*) FROM processlist WHERE user <> 'replication' AND id <> CONNECTION_ID() AND time > 60 AND command <> 'Sleep';
  • 10. Copyright © 2008 Sun Microsystems, Inc. Check uptime • MySQL might crash and restart quickly • Other checks might miss it mysql> USE information_schema; mysql> SELECT DATE_SUB(NOW(), INTERVAL variable_value SECOND) AS started, variable_value AS uptime FROM global_status WHERE variable_name = 'UPTIME'; +---------------------+--------+ | STARTED | UPTIME | +---------------------+--------+ | 2008-09-08 10:58:24 | 36604 | +---------------------+--------+
  • 11. Copyright © 2008 Sun Microsystems, Inc. InnoDB Table Size • Usually auto-extends • innodb_data_file_path = ibdata1:200M • Before MySQL 5.1 in table comments! mysql> USE information_schema; mysql> SELECT data_free*1024 AS 'InnoDB free space' FROM tables WHERE table_name = 'innotest'; +-------------------+ | InnoDB free space | +-------------------+ | 201326592 | +-------------------+
  • 12. Copyright © 2008 Sun Microsystems, Inc. InnoDB Buffer Pool Hit Rate • Is the buffer still big enough? mysql> SHOW GLOBAL STATUS LIKE 'InnoDB_buffer_pool_read%'; +-----------------------------------+------------+ | Variable_name | Value | +-----------------------------------+------------+ .. | Innodb_buffer_pool_read_requests | 2226519108 | | Innodb_buffer_pool_reads | 74845 | +-----------------------------------+------------+ 100 * ( 1 - (Innodb_buffer_pool_reads / Innodb_buffer_pool_read_requests)) = 99.99%
  • 13. Copyright © 2008 Sun Microsystems, Inc. Checking configuration • SHOW GLOBAL VARIABLES > Also information_schema.global_variables • What version is running? • Default storage engine still InnoDB? • Global character set is still UTF-8? • Logs enabled? > slow and general query log (online as of 5.1)
  • 14. Copyright © 2008 Sun Microsystems, Inc. Logging Enabled? • General log > Log every statement, useful for debugging > SHOW GLOBAL VARIABLES LIKE 'general_log'; • Slow query log > Show long running queries, or not using indexes > SHOW GLOBAL VARIABLES LIKE 'slow_query_log'; • As of MySQL 5.1 > Can be toggled online, and logged to tables • Should not be running all the time
  • 15. Copyright © 2008 Sun Microsystems, Inc. Monitoring Replication • On Master > Check number of binary logs > Limit number of slaves • On Slave > Use SHOW SLAVE STATUS > Check seconds behind master > Check if still reading from Master > etc.
  • 16. Copyright © 2008 Sun Microsystems, Inc. Master And Her Slaves • Master can handle lots of slave > But it’s good to set a limit • SHOW SLAVE HOSTS > Does list registered hosts, not connected ones mysql> SHOW SLAVE HOSTS; +-----------+--------+------+...+-----------+ | Server_id | Host | Port |...| Master_id | +-----------+--------+------+...+-----------+ | 2 | cent02 | 3306 |...| 1 | +-----------+--------+------+...+-----------+ 1 row in set (0.00 sec)
  • 17. Copyright © 2008 Sun Microsystems, Inc. Number Of Binary Logs • Regularly causing disk space issues > Can use PURGE MASTER LOGS • SHOW BINARY LOGS mysql> SHOW BINARY LOGS; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | cent01bin.000001 | 125 | | cent01bin.000002 | 1021 | | cent01bin.000004 | 125 | | cent01bin.000005 | 462 | +------------------+-----------+
  • 18. Copyright © 2008 Sun Microsystems, Inc. Slave status mysql> SHOW SLAVE STATUSG .. Master_Host: 192.168.14.100 Master_User: replication Master_Port: 3306 .. Slave_IO_Running: Yes Slave_SQL_Running: Yes .. Seconds_Behind_Master: 0 .. Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:
  • 19. Copyright © 2008 Sun Microsystems, Inc. Seconds Behind Master • Number of seconds elapsed since timestamp of last statement received from Master • Only useful in fast networks > Slow I/O gives bad approximation • Use a heartbeat table > INSERT INTO replication_ping VALUES (NOW()) > Check on slave when table is updated > Calculate time difference > Or use mk-heartbeat from Maatkit
  • 20. Copyright © 2008 Sun Microsystems, Inc. Monitoring Cluster • Still not easy to do • Using NDB API • Parse logs • Using ndb_mgm shell> ndb_mgm -e "SHOW" Connected to Management Server at: localhost:1406 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=3 @10.100.9.8 (mysql-5.1.27 ndb-6.3.17, Nodegroup: 0, Master) id=4 @10.100.9.9 (mysql-5.1.27 ndb-6.3.17, Nodegroup: 0) [ndb_mgmd(MGM)] 2 node(s) id=1 @10.100.9.6 (mysql-5.1.27 ndb-6.3.17) id=2 (not connected, accepting connect from ndbsup-priv-2) [mysqld(API)] 7 node(s) id=5 @10.100.9.6 (mysql-5.1.27 ndb-6.3.17) id=6 (not connected, accepting connect from any host)
  • 21. Copyright © 2008 Sun Microsystems, Inc. Useful Tools • MySQL client tools and SQL! • MySQL Enterprise Monitor > http://www.mysql.com/products/enterprise/ • innotop > http://innotop.sourceforge.net/ • Maatkit > http://www.maatkit.org/
  • 22. Copyright © 2008 Sun Microsystems, Inc. Nagios + MySQL Monitoring MySQL with Nagios
  • 23. Copyright © 2008 Sun Microsystems, Inc. Configuration tips • Using hostgroups > Useful for replication setups or Cluster define hostgroup { hostgroup_name mysql-masters } define hostgroup { hostgroup_name mysql-slaves } define host { use generic-virtualbox host_name cent02 alias cent02 (VMWare) address 192.168.14.101 hostgroups virtualboxes,vmware,mysql-slaves } define service { use generic-service hostgroup_name mysql-slaves service_description Slave SQL Thread check_command mysql_repl_sqlthread }
  • 24. Copyright © 2008 Sun Microsystems, Inc. Configuration tips (2) • Secure your setup: SSL or SSH • Don’t use MySQL root user for checks • Could use NRPE (Nagios add-on)
  • 25. Copyright © 2008 Sun Microsystems, Inc. Some plugins.. • Oli Sennhauser > http://www.shinguz.ch/MySQL/mysql_monitoring.html
  • 26. Copyright © 2008 Sun Microsystems, Inc. Some plugins.. (2) • check_mysql_perf > http://www.consol.com/opensource/nagios/check-mysql-perf/ • Checks various buffers > hit rates for qcache, keycache • InnoDB checks > bufferpool, etc.. • Checks for slow queries • and more..
  • 27. Copyright © 2008 Sun Microsystems, Inc. Write your own! • http://nagiosplug.sourceforge.net/developer-guidelines.html • Quite easy: here a very simple plugin #!/bin/sh mysql -e "SELECT NOW()" -NB -h $1 -u$2 -p$3 2>/dev/null if [ $? != 0 ]; then echo "Oops!" ; exit 2 # Criticial fi exit 0 # OK shell> ./simple.sh cent02.kemuri.net agent cop 2008-09-08 13:37:09 shell> ./simple.sh cent02.kemuri.net agent cap Oops!
  • 28. Copyright © 2008 Sun Microsystems, Inc. Write Your Own with Python def get_uptime(): global OPTIONS db = MySQLdb.connection(host=OPTIONS['hostname'], user=OPTIONS['user'],passwd=OPTIONS['password']) db.query("SHOW GLOBAL STATUS LIKE 'Uptime'") res = db.store_result() row = res.fetch_row(1) return int(row[0][1]) def check_uptime(uptime): global OPTIONS, ERRORS line = 'Uptime %ds' % uptime err = ERRORS['OK'] if uptime < OPTIONS['critical']: err = ERRORS['CRITICAL'] elif uptime < OPTIONS['warning']: err = ERRORS['WARNING'] print line sys.exit(err) • Email geert@mysql.com for the full version
  • 29. Copyright © 2008 Sun Microsystems, Inc. MySQL Enterprise Monitor What is it, and how combining it with Nagios?
  • 30. Copyright © 2008 Sun Microsystems, Inc. MySQL Enterprise Monitor (MEM) • Single, consolidated view • Auto discovery of MySQL Servers, Replication Topologies • Problem Query Detection, Analysis and Tuning – New! • Customizable rules-based monitoring and alerts • Identifies problems before they occur • Reduces risk of downtime • Easier to scale-out without requiring more DBAs
  • 31. Copyright © 2008 Sun Microsystems, Inc.
  • 32. Copyright © 2008 Sun Microsystems, Inc. Advisors/Rules • Comparable with Nagios plugins • Possible using Nagios plugins making custom Advisors for MEM • Can use SNMP Traps
  • 33. Copyright © 2008 Sun Microsystems, Inc. MEM, Nagios and SNMP • Using Passive Service Checks • Handle SNMP traps > Using traphandle in snmptrapd configuration • Nagios and MEM host names must match MEMView NagiosView
  • 34. Copyright © 2008 Sun Microsystems, Inc. MEM, Nagios and SNMP (cont.) • Configure snmptrapd to handle MEM traps # Usually /etc/snmp/snmptrapd.conf traphandle default /path/to/handle_mysql_memtrap.sh • Setup Nagios define service { use generic-service service_description MEM SNMP Trap hostgroup_name mysql-masters,mysql-slaves register 0 check_command check_no is_volatile 1 max_check_attempts 1 retry_check_interval 1 normal_check_interval 4 active_checks_enabled 0 passive_checks_enabled 1 }
  • 35. Copyright © 2008 Sun Microsystems, Inc. SNMP Handler Script (part 1) read host read ip while read oid val do val=`expr "$val" : '"(.*)"'` vars="$vars;; $oid: $val" case "$oid" in MYSQLTRAP-MIB::advisor.0) hostname=$val ;; MYSQLTRAP-MIB::advisor.1) memstate=$val ;; MYSQLTRAP-MIB::advisor.4) message=$val ;; esac done • Reading SNMP trap information
  • 36. Copyright © 2008 Sun Microsystems, Inc. SNMP Handler Script (part 2) • Translate and send it to Nagios. state=$STATE_OK case "$memstate" in critical) state=$STATE_CRITICAL ;; warning|info|success) state=$STATE_WARNING ;; esac datetime=`date +%s` cmd="[$datetime] PROCESS_SERVICE_CHECK_RESULT;$hostname; $service;$state;$message" echo $cmd >> $nagioscmdfile
  • 37. Copyright © 2008 Sun Microsystems, Inc. Some Links.. • MySQL Enterprise > http://www.mysql.com/products/enterprise/ • Nagios documentation > http://nagios.sourceforge.net/docs/2_0/passivechecks.html > http://www.nagios.org/faqs/viewfaq.php?faq_id=29 • Email Geert for the handler script