热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

10DatabasePerformanceMonitoringToolsYouCanGetForFre_MySQL

10DatabasePerformanceMonitoringToolsYouCanGetForFree
Database performance monitoring is something every DBA worth their salt should be doing on a regular basis.

It should be adopted as a proactive task to help identify issues early on before they become too serious and be part of a post code deployment monitoring process.

Bundled in with linux based operating systems are a heap of great tools that you can use as a DBA to help performance monitor your database server. If you are not happy with what you get “out of the box”, you can also find some great database monitoring tools online that are available to download for free.

For this post, I’m going to talk about both MySQL and Linux operating system performance monitoring tools. In many scenarios, you’ll need both types in order to get a complete understanding of where the delays are in your system.

MySQL Performance Monitoring Tools

1/ MySQL slow query log

The mysql slow query log is absolutely brilliant for capturing slow queries hitting your MySQL databases.

You can log queries whose durations match the number you specify in my.cnf. So you can analyze queries which take more than 3 seconds for example.

Activate in my.cnf with customizable settings for log location, long query time and whether to log queries that do not use any indexes.

#slow query loggingslow-query-log = 1slow-query-log-file = /var/log/mysql/slow-loglong-query-time = 3log-queries-not-using-indexes = 0

Once you have been logging for a while you can aggregate the results with the mysqldumpslow utility, optimize them and then monitor for improvements! :)

2/ MySQL Performance Schema

Introduced in version 5.5, the performance_schema database provides a way of querying internal execution of the server at run-time.

To enable add “performance_schema” to my.cnf

There are many objects to query, too many to talk about in this post. Check out the documentation here .

3/ The MySQL process list

To get an idea of how many processes are connected to your MySQL instance, what they are running and for how long, you can run SHOW FULL PROCESSLIST or alternatively read from the information_schema.processlist table.

mysql> SELECT user, host, time, info FROM information_schema.processlist;+-------------+------------+-------+-------------------------------------------------------------------+| user| host | time| info|+-------------+------------+-------+-------------------------------------------------------------------+| root| localhost| 0 | SELECT user, host, time, info FROM information_schema.processlist || replication | srv1:46892 | 11843 | NULL|+-------------+------------+-------+-------------------------------------------------------------------+2 rows in set (0.00 sec)

4/ mtop

I love this utility, it provides a real-time view of the MySQL process list and updates according to the number of seconds your specify when you run it.

What I really like about it is that you can have it running on one screen and as problems occur, the colours of the threads change colour with red indicating that something has been running for some time.

There is a great article here about how to install it on different flavours of Linux as well as some detail on how to run it.

5/ SHOW STATUS

Like other command line tools, such as SHOW PROCESSLIST, you run these to get moment in time reports on different variable status’s.

For example, if you want to get information about the query cache, you can run :

mysql> SHOW STATUS LIKE 'Qcache%';+-------------------------+------------+| Variable_name | Value|+-------------------------+------------+| Qcache_free_blocks| 9353 || Qcache_free_memory| 93069936 || Qcache_hits | 9719103977 || Qcache_inserts| 1451857238 || Qcache_lowmem_prunes| 897050960|| Qcache_not_cached | 222234089|| Qcache_queries_in_cache | 20856|| Qcache_total_blocks | 52497|+-------------------------+------------+8 rows in set (0.00 sec)

This type of reporting can help you monitor specific areas of your MySQL instance. For example, if you wanted to know the query cache hit rate, you could get the numbers from above and calculate based on this formula:

((Qcache_hits/(Qcache_hits+Qcache_inserts+Qcache_not_cached))*100)

For more information, see this link .

Operating System Performance Monitoring Tools

6/ TOP

This will list running processes and the resources that they are consuming. It updates real-time and you can quickly gage if there are processes which are consuming large areas of resource in CPU and memory at a very high level.

top - 17:33:48 up 7 min,1 user,load average: 0.03, 0.04, 0.04Tasks:64 total,	1 running,63 sleeping,	0 stopped,	0 zombieCpu(s):0.0%us,0.0%sy,0.0%ni,100.0%id,0.0%wa,0.0%hi,0.0%si,0.0%stMem:	 604332k total,	379280k used,	225052k free,	 11724k buffersSwap:		0k total,		0k used,		0k free,	135064k cachedPID USER		PRNIVIRTRESSHR S %CPU %MEM	 TIME+COMMAND809 tomcat7	20	0 1407m 149m13m S0.3 25.4	0:10.99 java 1153 ubuntu	 20	0 81960 1592756 S0.30.3	0:00.01 sshd 1318 root		20	0 17320 1256972 R0.30.2	0:00.07 top	 1 root		20	0 24340 2284 1344 S0.00.4	0:00.39 init	 2 root		20	0	0	 0	 0 S0.00.0	0:00.00 kthreadd	 3 root		20	0	0	 0	 0 S0.00.0	0:00.03 ksoftirqd/0	 4 root		20	0	0	 0	 0 S0.00.0	0:00.00 kworker/0:0	 5 root		20	0	0	 0	 0 S0.00.0	0:00.01 kworker/u:0

7/ free

This utility helps to give you an idea whether you have a memory issue. Again this is another great tool for getting a high level view. I like to use “free -m” as it returns the numbers to me in megabytes instead of bytes. The information returned shows you in use, free and swap usage. It also shows what is in use by the kernel and buffers.

root@vm1:~# free -m total used free sharedbuffers cachedMem: 5903732160 11131-/+ buffers/cache:229360Swap:000

8/ vmstat

This utility is very useful for monitoring many areas of the system, CPU, IO blocks and swap. I find it particularly good to monitor swap file usage.

Whilst “free” might tell you if there are any pages in the swap file, vmstat will tell you if your system is actively swapping. Computers and servers do need to use their swap file but the less this happens, the better it is for your applications performance.

When you have a problem with swap, it is when it is being used constantly and can be a sign that you don’t have enough memory installed in your system.

By default, running vmstat will not give you a real time view of your system. So you need to add a figure to the command to give you a fresh read out in the number of seconds specified. In this example, I am specifying every 2 seconds.

root@vm1:~# vmstat 2procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- rb swpd free buffcache si sobibo in cs us sy id wa 000 22132412556 135252009319 40 7510 980 000 22132412556 13527600 0 0 34 6500 1000 000 22132412564 13528000 024 38 6400 1000 000 22132412564 13528000 0 0 32 5600 1000 000 22132412564 13528000 0 0 33 5600 1000 000 22132412564 13528000 0 0 30 5501 1000 000 22132412564 13528000 0 0 35 5900 1000

The columns you are interested in are swap si and so. Which stands for “swap in” and “swap out”. These figures tell you what is being read in from disk swap file (si) and what is being swapped out to the swap file (so). Swapping is very slow I/O intensive process and you want to be doing some optimization somewhere or adding more memory if this is a problem.

Run “man vmstat” for a full list of features and documentation.

9/ sar

I love sar! It will capture you a whole bunch of metrics based on CPU time, CPU queues, RAM, IO and network activity. It will give you a point in time view of the resource usage in the form of a historical report.

The default time between report lines is 10 minutes but you can change that. It’s great for seeing whether you have any particularly heavy areas of resource pressure at any time in the day. You can also use it as a performance monitoring tool to measure the effects of optimizations to your system.

Some examples, run “man sar” for a full list of features and documentation on what each column header means.

sar -q (check CPU queue length)

11:20:01 AM runq-szplist-sz ldavg-1 ldavg-5ldavg-1511:30:01 AM 1 2010.000.000.0011:40:01 AM 1 2000.000.000.0011:50:01 AM 1 2010.000.000.0012:00:01 PM 2 2010.000.000.00

sar -r (check RAM usage)

11:20:01 AM kbmemfree kbmemused%memused kbbufferskbcachedkbcommit %commit11:30:01 AM151308 3765480 96.14 91416 1054136 2961684 49.2511:40:01 AM151076 3765712 96.14 91664 1054136 2961012 49.2411:50:01 AM150680 3766108 96.15 91888 1054148 2961152 49.2412:00:01 PM150704 3766084 96.15 92104 1054152 2961340 49.24

10/ iostat

This tool will you give you statistics for CPU and I/O for devices, partitions and network file systems. Great for knowing where the busiest drives are for example.

root@vm1 ~# iostatLinux 2.6.32-431.11.2.el6.x86_64 (vm1)06/27/2014_x86_64_(4 CPU)avg-cpu:%user %nice %system %iowait%steal %idle	0.230.000.070.100.00 99.60Device:	 tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtnsda	 11.78 785.38 450.12 1437054564823620760dm-0	 1.00 1.35 6.672472280 12211040dm-1	64.52 783.30 441.42 1433252442807699512dm-2	 0.00 0.00 0.02 765829336dm-3	 0.27 0.53 2.01 9786263680440

Finally

So there you have it – 10 really useful tools which you can utilize in your database performance monitoring efforts. There are many more but I’ve run out of time now. :)

推荐阅读
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 本文介绍了在Hibernate配置lazy=false时无法加载数据的问题,通过采用OpenSessionInView模式和修改数据库服务器版本解决了该问题。详细描述了问题的出现和解决过程,包括运行环境和数据库的配置信息。 ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文介绍了Linux系统中正则表达式的基础知识,包括正则表达式的简介、字符分类、普通字符和元字符的区别,以及在学习过程中需要注意的事项。同时提醒读者要注意正则表达式与通配符的区别,并给出了使用正则表达式时的一些建议。本文适合初学者了解Linux系统中的正则表达式,并提供了学习的参考资料。 ... [详细]
  • Ubuntu 9.04中安装谷歌Chromium浏览器及使用体验[图文]
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
  • Ubuntu安装常用软件详细步骤
    目录1.GoogleChrome浏览器2.搜狗拼音输入法3.Pycharm4.Clion5.其他软件1.GoogleChrome浏览器通过直接下载安装GoogleChro ... [详细]
  • iOS Swift中如何实现自动登录?
    本文介绍了在iOS Swift中如何实现自动登录的方法,包括使用故事板、SWRevealViewController等技术,以及解决用户注销后重新登录自动跳转到主页的问题。 ... [详细]
  • MySQL语句大全:创建、授权、查询、修改等【MySQL】的使用方法详解
    本文详细介绍了MySQL语句的使用方法,包括创建用户、授权、查询、修改等操作。通过连接MySQL数据库,可以使用命令创建用户,并指定该用户在哪个主机上可以登录。同时,还可以设置用户的登录密码。通过本文,您可以全面了解MySQL语句的使用方法。 ... [详细]
  • 分享css中提升优先级属性!important的用法总结
    web前端|css教程css!importantweb前端-css教程本文分享css中提升优先级属性!important的用法总结微信门店展示源码,vscode如何管理站点,ubu ... [详细]
  • 2016 linux发行版排行_灵越7590 安装 linux (manjarognome)
    RT之前做了一次灵越7590黑苹果炒作业的文章,希望能够分享给更多不想折腾的人。kawauso:教你如何给灵越7590黑苹果抄作业​zhuanlan.z ... [详细]
  • PHP函数实现分页含文本分页和数字分页【PHP】
    后端开发|php教程PHP,分页后端开发-php教程最近,在项目中要用到分页。分页功能是经常使用的一个功能,所以,对其以函数形式进行了封装。影视网源码带充值系统,vscode配置根 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • SpringBoot整合SpringSecurity+JWT实现单点登录
    SpringBoot整合SpringSecurity+JWT实现单点登录,Go语言社区,Golang程序员人脉社 ... [详细]
  • 本文详细介绍了在Centos7上部署安装zabbix5.0的步骤和注意事项,包括准备工作、获取所需的yum源、关闭防火墙和SELINUX等。提供了一步一步的操作指南,帮助读者顺利完成安装过程。 ... [详细]
author-avatar
ha遗忘的密
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有