Vc-mysql-sniffer statistics MySQL SQL distribution

Source: Internet
Author: User

Sometimes we need to count the SQL execution on the line, like to know which SQL performs the most frequently, we can turn on General_log, and then do statistics, but general_log turn on very lossy performance, then we can use Vc-mysql-sniffer instead , the tool is compiled binary, download can be used. :

Https://www.vividcortex.com/resources/network-analyzer-for-mysql

Here I have modified a script on the web to analyze the results of the Vc-mysql-sniffer crawl to statistics frequently executed SQL.

#!/usr/bin/python#Coding:utf8#python analysis-vc-log.py 3315 | sort | uniq-c | Sort-nr |head-nImportReImportSYSImportOSImportCommandsvc_sniffer_time=5Port=sys.argv[1]vc_cmd="""/usr/bin/timeout%s/data/software/vc-mysql-sniffer-binding= "[::]:%s" >/tmp/tmp_vc_mysql_%s.txt"""%(vc_sniffer_time,port,port) Outtext=commands.getoutput (vc_cmd) cmd="""Grep-ev ' # time:|# [email protected] '/tmp/tmp_vc_mysql_%s.txt |sed ' s/# query_time.*/myxxxxx/g ' |awk begin{rs=eof} ' {gsub (/\\n/, "");p rint} ' |awk begin{rs=eof} ' {gsub (/myxxxxx/, "\\n");p rint} ' >/tmp/vc_mysql_%s.txt"""%(port,port) Outtext=commands.getoutput (cmd) file="/tmp/vc_mysql_%s.txt"%(port) Logfo=open (file) forLineinchLogfo:line= Re.sub (r"\ n","", line) Linematch= Re.match (r".*", line)iflinematch:linetmp=linematch.group (0)#Remove Extra SpaceLinetmp = Re.sub (r"\s+"," ", linetmp)#Replace values (value) to values (x)Linetmp = Re.sub (r"values\s*\ (. *?\)","values (x)", linetmp)#Replace filed = ' value ' to filed = ' x 'Linetmp = Re.sub (r"(=|>|<|>=|<=) \s* (' |\ "). *?\2","\\1 ' x '", linetmp)#Replace filed = value to filed = xLinetmp = Re.sub (r"(=|>|<|>=|<=) \s*[0-9]+","\\1 x", linetmp)#replace like ' value ' to like ' X 'Linetmp = Re.sub (r"like\s+ (' |\ '). *?\1","Like ' x '", linetmp)#Replace in (value) to In (x)Linetmp = Re.sub (r"in\s+\ (. *?\)","In (x)", linetmp)#Replace limit x, y to limitLinetmp = Re.sub (r"limit.*","Limit", linetmp)Printlinetmplogfo.close ()
3310 Sort Uniq Sort -nr | Head Ten

Crawl the MySQL 3310 port and statistically perform the most frequent 10 sql. I'm not going to put it up here. Interested classmates to test themselves.

Resources:

https://www.centos.bz/2015/02/analysis-mysql-general-log/

Vc-mysql-sniffer statistics MySQL SQL distribution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.