Using Cacti To Graph MySQL’s Metrics
Kenny Gryp
Principal Consultant @ Percona
Collaborate 2011
Percona
•
MySQL/LAMP Consulting•
MySQL Support•
Percona Server (XtraDB)•
Percona XtraBackup•
InnoDB Recovery Toolkit, tcprstat•
(maatkit, innotop, aspersa, mysql-mmm,mysql-cacti-templates)
•
...•
http://www.percona.com•
http://www.mysqlperformanceblog.comTopics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksTopics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksWhy Graph?
•
Troubleshooting-
behavior over time-
sudden spikes in graphs after application updates•
Capacity Planning-
traffic patterns-
predictions•
Not only for Operations, also for Development andManagement
Topics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksCacti?
•
open source graphing solution•
uses RRDTool•
advanced graphs, scriptable•
web interface•
quite complex to add graphs•
adding servers is a manual processmysql-cacti-templates?
•
collection of templates for cacti•
graph MySQL metrics•
Has a lot of non-MySQL Metrics too: IO stats,apache, memcache, mongodb, java...
Topics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksHow does Cacti work?
10 Database Server mysqld sshd snmpd /proc/ diskstats Cacti MySQL (contains cacti configuration) .rrd Files (contains rrd data) Apache (serves web interface) Poller (cronjob which fetches data fromTopics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksInstallation
•
Cacti•
Mysql-cacti-templates•
Configuring ServersInstallation
•
Cacti•
Mysql-cacti-templates•
Configuring ServersSetting up Cacti: Requirements
•
httpd•
php, php-mysql, php-snmp•
mysql-server (server and client utilities)•
net-snmp (snmpget)•
rrdtoolSetting up Cacti: Installation
•
Install rpm/deb/... package or extract yourself•
Configure webserver: php5, cacti scripts•
Create cacti mysql user•
Import cacti database•
Edit configuration•
Setup cronjob for poller•
Finish installation using your webbrowserSetup: Extract
•
Recommended is using apt/yum/... to install cacti•
if not:16
cacti# cd /var/www/html/ # may vary cacti# tar xzvf cacti-0.8.7g.tar.gz cacti# ln -s cacti-0.8.7g cacti
Setup: Webserver
•
Apache (may be something else)•
Enable php•
Set DirectoryIndex index.php17
LoadModule php5_module modules/libphp5.so AddHandler php5-script .php
Setup: MySQL
•
Create Cacti MySQL user:•
Import Cacti Schema•
Edit include/config.php18
cactimysql> GRANT ALL PRIVILEGES ON cacti.* TO
cactiuser@localhost IDENTIFIED BY 'password';
cacti# mysql -e ‘CREATE DATABASE cacti;’ cacti# mysql cacti < cacti.sql
$database_type = "mysql";
$database_default = "cacti";
Setup: Poller
•
Add cronjob (/etc/cron.d/cacti)19
Setup: UI
Setup: UI
Setup: UI
Setup: UI
Setup: UI
Setup: UI
Setup: UI
Installation
•
Cacti•
Mysql-cacti-templates•
Configuring Serversdownload & installation
28
cacti# wget
http://mysql-cacti- templates.googlecode.com/files/better-cacti-templates-1.1.8.tar.gz
cacti# tar -xzf better-cacti-templates-1.1.8.tar.gz cacti# cd better-cacti-templates-1.1.8/
cacti# cp \
install: generate ssh key
30
cacti# mkdir /etc/cacti cacti# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/ id_rsa): /etc/cacti/id_rsa
Enter passphrase (empty for no passphrase):
Your identification has been saved in /etc/cacti/ id_rsa.
Your public key has been saved in /etc/cacti/ id_rsa.pub.
cacti# chown -R www-data: /etc/cacti/
{id_rsa,id_rsa.pub}
install: ssh script
31
cacti# vi /var/www/html/cacti/scripts/
ss_get_by_ssh.php ...
$ssh_user= 'cacti'; # SSH username $ssh_port= 22; # SSH port
install: templates
install: templates
install: templates
Installation
•
Cacti•
Mysql-cacti-templates•
Configuring ServersConfigure Servers
•
configure net-snmpd•
add a cacti user in MySQL•
configure ssh accessConfigure Servers: snmpd
•
Install snmpd•
Make sure snmpd listens on the network and that acommunity password is set:
•
Verify on the cacti server if snmp is working remotely37
server# apt-get install snmpd
server# vi /etc/snmp/snmpd.conf: agentAddress udp:161
rocommunity public
server# /etc/init.d/snmpd restart
cacti# snmpget -v2c -c public
ubuntu-server-test iso.3.6.1.2.1.1.5.0
Configure Servers: mysql user
•
Add cacti user•
Verify if login works from cacti servers38
servermysql> GRANT SUPER, PROCESS ON *.* TO
'cactiuser'@'cactiserver' IDENTIFIED BY "password";
cacti# mysql -h ubuntu-server-test -e "SELECT
VERSION()" -u cactiuser -ppassword
Configure Servers: ssh access
•
Add shell user cacti•
Copy the public key•
Verify39
server# useradd cacti
server# getent passwd cacti
cacti:x:1001:1002::/home/cacti:/bin/sh server# mkdir /home/cacti/.ssh/
server# cat > /home/cacti/.ssh/authorized_keys <<
EOF
ssh-rsa AAA...r2E7z5 root@ubuntu-server-test EOF
server# chmod 0400 /home/cacti/.ssh/authorized_keys cacti# ssh -i /etc/cacti/id_rsa
Topics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksAdding Graphs
Adding Graphs
Adding Graphs
Adding Graphs
44
•
Apply wanted templates on the device-
MySQL & GNU/Linux templates•
Click on Create Graphs:•
Select graphs to create and Add!Adding Graphs
Adding Graphs
46
•
Assign ucd/net SNMP template to have:-
cpu usage/load-
memory used/available-
network statistics-
free disk spaceAdding Graphs
Adding Graphs
48
•
What if I have multiple disk devices to monitor?-
Go to ‘Create graphs for this host’-
Select graph to add in select menuAdding Graphs: Graph Trees
49
•
Tree to browse through graphsTopics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksTopics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksMySQL Handlers
MySQL Handlers
53
MySQL Handlers
MySQL Handlers
55
MySQL Connections
MySQL Connections
57
max_connections not reached yet
MySQL Replication
MySQL Replication
59
MySQL Replication
MySQL Replication
61
MySQL Temporary Objects
MySQL Temporary Objects
63
keep an eye on: * temp tables
* temp disk tables
MySQL Select Types
MySQL Select Types
65
MySQL Select Types
MySQL Select Types
67
MySQL Sorts
MySQL Sorts
69
MySQL Command Counters
MySQL Binary Logs
MySQL Binary Logs
72
Response Time Distribution
73
MySQL Query Response Time
MySQL Query Response Time
InnoDB Buffer Pool
InnoDB Buffer Pool
77
DB Restart
InnoDB Checkpoint Age
InnoDB Buffer Pool Activity
InnoDB I/O
InnoDB I/O
82
More read
InnoDB Row Operations
InnoDB Row Operations
84
86
87
89
CPU Usage
Memory
Disk Operations
Topics
•
Why Graph?•
What is Cacti and mysql-cacti-templates?•
How Cacti worksnon-MySQL mysql-cacti-templates
non-MySQL mysql-cacti-templates
non-MySQL mysql-cacti-templates
non-MySQL mysql-cacti-templates
Other Graphing solutions
•
Munin and munin-mysql•
OpenNMS and MySQL-SNMP•
Zabbix with appaloosa-zabbix-templatesCreating Your Own Graphs
•
Creating cacti graphs not trivial/portable•
mysql-cacti-templates to the rescue!http://code.google.com/p/mysql-cacti-templates/ wiki/CreatingGraphs
Using Cacti To Graph MySQL’s Metrics
•
Powerful Tool•
Easy to install•
Open source!Using Cacti To Graph MySQL’s Metrics
•
Cacti: http://www.cacti.net/•
RRDtool: http://oss.oetiker.ch/rrdtool/•
mysql-cacti-templates:http://code.google.com/p/mysql-cacti-templates/
•
IRC: Freenode #percona•
Mailinglist:http://groups.google.com/group/percona-discussion
•
http://www.percona.com•
http://www.mysqlperformanceblog.comPercona Live MySQL Conference NYC May 26, 2011
http://www.percona.com/live/nyc-2011/