monitoring mysql - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf ·...

57
Monitoring MySQL Kristian Köhntopp Mittwoch, 28. Oktober 2009

Upload: lythien

Post on 12-Sep-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Monitoring MySQL

Kristian Köhntopp

Mittwoch, 28. Oktober 2009

Page 2: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

I am...

• Kristian Köhntopp

• Database architecture at a small travel agency in Amsterdam

• In previous lives: MySQL, web.de, NetUSE, MMC Kiel, PHP, PHPLIB, various FAQs and Howto

Mittwoch, 28. Oktober 2009

Page 3: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

You are• Job…

• DBA, Developer, General IT, IT Management

• Using version...

• 3.23, 4.0, 4.1, 5.0, 5.1

• Using MySQL for...

• Webapps, Enterprise, Embedded, ...

• Number of servers...

• 1, <3, <10, <25, <100, 100 or more

Mittwoch, 28. Oktober 2009

Page 4: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Why Monitoring?

• Audience

• Consumers of monitoring data

• Metrics

• What kind of data necessary?

• Toolbox

• Which kind of tool to use?

Mittwoch, 28. Oktober 2009

Page 5: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Why Monitoring?

• Who requires monitoring?

• Operations (Incident)

• Infrastructure Development (Capacity)

• Feature Development (Debug)

• Compliance (SLA, Legal)

Mittwoch, 28. Oktober 2009

Page 6: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Why Monitoring?

• Each kind of monitoring has different

• Purpose

• Metric

• Raw data, Notification latency

• Deliverable

• HA requirements

Mittwoch, 28. Oktober 2009

Page 7: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Incident detection

• Purpose: “Are we still online?”

• Metric: “High level availability test w/ binary outcome”

• Deliverable: Ticket to Helpdesk ➜ Operating ➜ Incident Management

• Latency: Seconds

• HA Requirement: Minutes, high

Mittwoch, 28. Oktober 2009

Page 8: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Capacity planning• Purpose: “When can I guarantee server

overload?” (Negative SLA)

• Metric: detailed records of variables in all subsystems

• Deliverable: weekly/monthly report to IT Management, general Management

• Latency: days

• HA Requirement: days/lowMittwoch, 28. Oktober 2009

Page 9: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Debugging• Purpose: “Which query crashes the

server? Why is this statement slow?”

• Metric: detailed records of variables while processing a single query

• Deliverable: individual report to single developer

• Latency: Seconds, Minutes

• HA Requirement: noneMittwoch, 28. Oktober 2009

Page 10: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Compliance• Purpose: “Are we fulfilling our

contracts?”

• Metric: “high level availability tests w/ binary outcome”, query times

• Deliverable: weekly/monthly report to IT management/customer

• Latency: Days

• HA Requirement: days, lowMittwoch, 28. Oktober 2009

Page 11: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

For Audit• Purpose:

• Detect tampering, alteration and access, create accountability records for changes and access

• Metric: high level event records with application semantics

• additionally: inescapable, unforgeable

• Deliverable: daily/weekly report

• HA Requirement: Out of pathMittwoch, 28. Oktober 2009

Page 12: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Metrics

• Data sources at OS level

• Data sources in MySQL

• Derived data sources

Mittwoch, 28. Oktober 2009

Page 13: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

OS Level

• Internal Availability Check:

• presence of PID file

• presence of process

• test -f linux.pid is not good enough

• “kill -0 $(cat linux.pid)” is better than “ps axuwww | grep mysql[d]”

Mittwoch, 28. Oktober 2009

Page 14: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

OS Level

• External Availability Check :

• ping check

• trivial query

• Set timeouts for the trivial query according to SLA

Mittwoch, 28. Oktober 2009

Page 15: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

OS Level

• Memory Checks:

• process size in memory

• VSIZE vs. RSS

• buffer cache size (“free -m”)

• swap check!

• vm.swappiness = 0

Mittwoch, 28. Oktober 2009

Page 16: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

OS Level

• “iostat -x 1 3” output

• In general, databases are limited by seek/sec, not MB/sec

• SSD, FusionIO

• Network I/O quality

• Smokeping? (Cluster!)

Mittwoch, 28. Oktober 2009

Page 17: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

OS Level

Mittwoch, 28. Oktober 2009

Page 18: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

MySQL

• General Counters and Config:

• SHOW /*!50000 GLOBAL */ STATUS;

• SHOW /*!50000 GLOBAL */ VARIABLES;

• What is running?

• SHOW FULL PROCESSLIST;

Mittwoch, 28. Oktober 2009

Page 19: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

MySQL

• File Handles:

• SHOW TABLE STATUS;

• SHOW OPEN TABLES;

Mittwoch, 28. Oktober 2009

Page 20: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

MySQL

• Replication:

• SHOW SLAVE STATUS;

• SHOW MASTER LOGS;

• SHOW MASTER STATUS;

Mittwoch, 28. Oktober 2009

Page 21: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

MySQL

• InnoDB:

• SHOW ENGINE INNODB STATUS;

• SHOW GLOBAL STATUS LIKE 'inno%';

Mittwoch, 28. Oktober 2009

Page 22: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: General•qps: questions/uptime

•COM_% Counters:

Mittwoch, 28. Oktober 2009

Page 23: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: General

• COM_% Counters

• Read/Writes:( select + qcache_hits ) / ( insert+update+delete+replace )

• Transactions:#commit, rollback/commit, writes/commit

Mittwoch, 28. Oktober 2009

Page 24: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

• Table Cache

• (opened_tables/sec )

• (table_cache_size – open_tables)

• Thread Cache

• (threads_created/sec)

• (thread_cache_size – threads_cached)

Mittwoch, 28. Oktober 2009

Page 25: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

Mittwoch, 28. Oktober 2009

Page 26: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

• Query-Cache Hit Ratio:

• qcache_hits*100 / ( qcache_hits + com_select )

• Hits vs. Inserts vs. Not Cached

Mittwoch, 28. Oktober 2009

Page 27: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

• Lowmem Prunes:

• qcache_lowmem_prunes / uptime

• qcache_lowmem_prunes per second

Mittwoch, 28. Oktober 2009

Page 28: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

• Increase query cache size:

• less prunes, higher hit ratio

• Sometimes it is better to delay writes or to split tables instead

Mittwoch, 28. Oktober 2009

Page 29: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Caches

Mittwoch, 28. Oktober 2009

Page 30: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Connections

• Connections

• max_connections – max_used_connections

• max_connections - threads_connected

Mittwoch, 28. Oktober 2009

Page 31: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Connections

Mittwoch, 28. Oktober 2009

Page 32: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: MyISAM

• Key Cache Hit Ratio:

• key_read_requests / key_read

• 300-1000 target

• 99.7% or better hit ratio

Mittwoch, 28. Oktober 2009

Page 33: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: MyISAM

• MyISAM Lock Contention

• table_locks_waited * 100 / table_locks_immediate

• <1% good, 1% warning, >3% you are currently dying

• distinctly nonlinear behavior

Mittwoch, 28. Oktober 2009

Page 34: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: MyISAM

Mittwoch, 28. Oktober 2009

Page 35: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: InnoDB

• Page Cache Usage:

• Innodb_buffer_pool_pages_free *100 / Innodb_buffer_pool_pages_total

• Cache Miss Ratio:

• (Innodb_buffer_pool_reads / Innodb_buffer_pool_read_requests)*100

• target: <3%, <1%

Mittwoch, 28. Oktober 2009

Page 36: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: InnoDB

• Cache Monitoring: Innodb_buffer_pool_wait_freemust not count up!

• Log-Monitoring: Innodb_log_waitsmust not count up!

Mittwoch, 28. Oktober 2009

Page 37: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: InnoDB

• InnoDB has many more stats

• See Innotop output, read up on theory

• Worth a talk of its own

Mittwoch, 28. Oktober 2009

Page 38: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: temp tables

• Temp tables per second:

• created_tmp_tables

• Temp tables to Disk:

• created_disk_tmp_tables * 100 / created_tmp_tables

Mittwoch, 28. Oktober 2009

Page 39: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: temp tables

• Additional hints:

• What kind of filesystem is tmpdir pointing to?

• Are we selecting BLOB/TEXT types?

• tmp_table size and max_heap_table_size must match

Mittwoch, 28. Oktober 2009

Page 40: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: temp tables

Mittwoch, 28. Oktober 2009

Page 41: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Replication• Functionality:

• Slave_IO_running: YES, Slave_SQL_running: YES

• Lag:

• Seconds_behind_master

• Rate:

• Read_Master_Log_Pos/sec,

Mittwoch, 28. Oktober 2009

Page 42: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Replication

Mittwoch, 28. Oktober 2009

Page 43: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Status: Slow Queries

• Slow Queries in general:

• Slow_queries/sec

• Counting evil queries:

• select_full_join / sec

• select_full_join / com_select

Mittwoch, 28. Oktober 2009

Page 44: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Incidents

• Incident detection:

• Nagios family

• Load Balancer Live Check

• Post Mortem:

• A small shell script running per minute

Mittwoch, 28. Oktober 2009

Page 45: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Incidents

• Nagios Plugins Quality:

• Bad checks

• Scripts

• Not compliant w/ standards

• Incident monitors vs. Compliance monitors

Mittwoch, 28. Oktober 2009

Page 46: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Post Mortem• Record per minute, keep one week

• logged to /var/log/mysql_pl

• uptime, ps auxwww, df -Th, free -m

• show full processlist; show slave status;

• show engine innodb status

• if HAVE_INNODB == YES

Mittwoch, 28. Oktober 2009

Page 47: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Incidents

Mittwoch, 28. Oktober 2009

Page 48: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Capacity

• MySQL Enterprise Monitor

• Cacti or Munin

• Actual overload tests

• increase LB weights

• monitor latency of standardized probe to detect breakage

Mittwoch, 28. Oktober 2009

Page 49: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

MEM

Mittwoch, 28. Oktober 2009

Page 50: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Tools: Cacti

• Shiny, but creating templates is a pain!

• Ready-made templates from

• http://code.google.com /p/mysql-cacti-templates/

Mittwoch, 28. Oktober 2009

Page 51: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Tools: Capacity

• Free MySQL SNMP tools are rare

• Exporting Variables, Status and Slave Status to SNMP:

• Perl Coprocess (PoC at best)

• http://mysqldump.azundris.com/archives/63-guid.html

Mittwoch, 28. Oktober 2009

Page 52: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Console

• inntop (mytop is dead)

• maatkit (indispenseable)

• tuning-primer.sh

• http://www.day32.com/MySQL/

• Self-written tools

• Establish a culture of tool creation

Mittwoch, 28. Oktober 2009

Page 53: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Debug

• MEM w/ proxy

• Proxy sometimes problematic

• Alternative: Rig DB access class

• mk-query-digest

• w/ SPAN port at switch

Mittwoch, 28. Oktober 2009

Page 54: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Debug

Mittwoch, 28. Oktober 2009

Page 55: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Audit

• Trailing controls

• Agile development

• Dump comparison

• mysqldump --no-data & git & diff

• mk-show-grants & git & diff

• etc.

Mittwoch, 28. Oktober 2009

Page 56: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Toolbox: Audit

• We have very many servers

• Critical data on isolated servers

• Limited access

• Wonders of an unlimited license

Mittwoch, 28. Oktober 2009

Page 57: Monitoring MySQL - blog.koehntopp.deblog.koehntopp.de/uploads/monitoring_mysql_slides_en.pdf · Monitoring MySQL Kristian Köhntopp ... • Nagios family ... PowerPoint Presentation

Mittwoch, 28. Oktober 2009