Linux gnuplot Drawing Performance Monitor chart use

Source: Internet
Author: User
Tags chmod save file cpu usage percona

First, installation

The current version is 4.6.5, where the source package is no longer listed, because the package is available from the most common Linux system sources:

The code is as follows Copy Code

Centos/redhat and other RPM package installation
Yum-y Install Gnuplot
Ubuntu/debian such as apt installation
sudo apt-get install gnuplot

Ii. Use and examples

Gnuplot has two kinds of drawing methods, one is interactive, one is directly configure the relevant parameters directly run. (This is similar to Python)

Interactive way If you want to directly display graphics, you need X11 terminal support. Here is no longer a specific example, you can refer to the Gnuplot Chinese manual for examples or official examples. The following is an example of the second way to show a complete example:

Example 1, gnuplot drawing CPU usage diagram

SAR obtains CPU information and outputs it to file

The code is as follows Copy Code

Sar-u 1 10 | Head-n-2 | tail-11 | Grep. >/var/www/html/monitor.data

The file content format is as follows:

The code is as follows Copy Code

#cat Monitor.data
06:24:52 CPU%user%nice%system%iowait%steal
06:24:53 All 0.00 0.00 1.00 1.00 0.00 98.00
06:24:54 All 0.00 0.00 1.01 0.00 0.00 98.99
06:24:55 All 5.00 0.00 2.00 0.00 0.00 93.00
06:24:56 All 1.00 0.00 2.00 6.00 0.00 91.00
06:24:57 All 0.00 0.00 1.02 2.04 0.00 96.94
06:24:58 All 31.68 0.00 9.90 0.00 0.00 58.42
06:24:59 All 76.77 0.00 23.23 0.00 0.00 0.00
06:25:00 All 73.00 0.00 27.00 0.00 0.00 0.00
06:25:01 All 76.00 0.00 24.00 0.00 0.00 0.00

Edit the monitor.conf configuration file for gnuplot read execution:

The code is as follows Copy Code

# Cat Monitor.conf
Set term PNG
Set XData time
Set style data lines
Set Output ' Cpu.png '
Set timefmt '%h:%m:%s '
Set format x '%h:%m:%s '
Set Xlabel ' time '
Set Ylabel ' CPU '
Plot ' Monitor.data ' using 1:3 title "%user", ' Monitor.data ' using 1:5 title '%sys ', ' monitor.data ' using 1:8 title '%idle ' Www.111cn.net

The graphics for the specific output are as follows:

Gnuplot

You can write a script that executes every minute:

The code is as follows Copy Code

# Cat Checkcpu.sh
#!/bin/sh
Sar-u 1 10 | Head-n-2 | tail-11 | Grep. >/var/www/html/monitor.data && gnuplot/var/www/html/monitor.conf [root@oracle html]# chmod +x checkcpu.sh

Can be combined with a simple HTML page, refresh every second, the HTML content is as follows:

The code is as follows Copy Code
<body>
<tablewidth= "border=" "0" cellpadding= "3" cellspacing= "0" >
<tr>
<td><strong><center>cpu monitor</center></strong></td>
</tr>
</table>
<br>
<p></p>
</body>
<scriptlanguage= "JavaScript" >
function Refresh () {
Window.location.reload ();
}
SetTimeout (' Refresh () ', 1000);
</script>

Example 2, gnuplot draw the load graph

The code is as follows Copy Code

[root@localhost~]# Cat/opt/cpuload.gnuplot
#!/bin/bash
Uptime | awk ' {print $1,$ (NF-2), $ (NF-1), $ (NF)} ' | Tr-d ', ' >>/opt/mydata
Gnuplot <<eof
Set terminal png tiny font '/USR/SHARE/FONTS/LIBERATION/LIBERATIONSANS-REGULAR.TTF '
Set Output '/var/www/html/loadavg.png '
Set XData time
Set timefmt '%h:%m:%s '
Set Xlabel ' time '
Set format x '%h:%m '
Set Xtics rotate
Set Ylabel ' Load average '
Plot '/opt/mydata ' u 1:2 t ' 1-min ' with lines, '/opt/mydata ' u 1:3 t ' 5-min ' with lines, '/opt/mydata ' u 1:4 t ' 15-min ' wit H lines
Eof
#chmod +x/opt/cpuload.gnuplot

Similarly, you can use HTML to display:

The code is as follows Copy Code

[Root@localhost ~]# cat/var/www/html/gnuplot.html
<a href= "/loadavg.png" >load acerage</a>

The above script can also be plotted using crontab.

Of course, if you want to control the platform, you can also cooperate with PHP, MySQL and other warehousing and graphic display. Here are just two small examples, and Gnuplot's use scenario is more than that.

Use Apache to do the stress test, you can also use its coordination, direct graphical display.

The code is as follows Copy Code

Files----> Keep.data nokeep.data keepalive.output
[Plain] View plaincopy

shell> yum install-y gnuplot///gnuplot---> Drawing software!
shell> ab-k-g/tmp/test/keep.data-n 10000-c 10000 http://10.1.1.235/template3/index.html
KeepAlive on, total concurrency 10000, tested 10,000 times!
shell> ab-g/tmp/test/nokeep.data-n 10000-c 10000 http://10.1.1.235/template3/index.html
KeepAlive off
Shell> Cd/tmp/test
Keep.data Nokeep.data Keepalive.output
Shell> gnuplot Keepalive.output
After the execution, the picture keepalive.png is generated in the current directory! And then according to the graph analysis!

--------------------------Keepalive.output---------------------------------------
[Plain] View plaincopy

The code is as follows Copy Code
#output as PNG image  
Set term png enhanced font '/USR/SHARE/FONTS/LIBERATION/LIBERATIONSANS-REGULAR.TTF '
# LS/USR /share/fonts/liberation/liberationsans-regular.ttf ==> Verify that the font is! 
#save file to  png file 
Set output "Keepalive.png"   ///output picture file name  
#graph title 
Set title "Lin-credibe"///picture title   ;
#nicer aspect ratio for image size 
Set size 1,0.7 
# y-axis grid 
Set grid y 
# x-axis label 
Set Xlabel "Request"  
#y-axis label 
Set Ylabel "Response Time (ms)"  
Plot "Keep.data" using 9 smooth Sbezier with lines title "Usingkeepalive",  
"Nokeep.data" Using 9 SM Ooth Sbezier with lines title "Nokeepalive"//no white space 

Similarly, using Tpcc-mysql to do MySQL performance testing, you can also use gnuplot to draw performance graphs. Example.

Load Tools

First, install the BZR client


# yum-y Install BZR

Issues encountered during download of Tpcc-mysql

The code is as follows Copy Code
# BZR Branch Lp:~percona-dev/perconatools/tpcc-mysql
Bzr:ERROR:Couldn ' t import bzrlib and dependencies.
Please check the directory containing bzrlib are on your pythonpath.
Traceback (most recent call last):
File "/USR/BIN/BZR", line 102, in <module>
Import Bzrlibpython
Importerror:no module named Bzrlib

Hint that the Bzrlib module could not be found because calling Python is recommended for upgrading to version 2.6

Workaround:

The code is as follows Copy Code
# Find/-name Bzrlib-print
/usr/lib64/python2.4/site-packages/bzrlib

To define an environment variable:

The code is as follows Copy Code


# Export Pythonpath=/usr/lib64/python2.4/site-packages

Download OK again.

The code is as follows Copy Code
#bzr Branch Lp:~percona-dev/perconatools/tpcc-mysql
Have not informed BZR of your Launchpad ID
Write to Launchpad or access private data. "Bzr help Launchpad-login".
Branched revision (s).
Bzr:warning:some compiled extensions could not to be loaded;

Second compilation installation

Access to the source directory

  code is as follows copy code


#cd TPCC-MYSQL/SRC
#make
Cc-w-o2-g-I. ' Mysql_config--include '-C LOAD.C
Cc-w-o2-g-I. ' Mysql_config--include '-C support.c
CC LOAD.O SUPPORT.O ' mysql_config--libs_r '-lrt-o. /tpcc_load
Cc-w-o2-g-I. ' Mysql_config--include '-C main.c
Cc-w-o2-g-I. ' Mysql_config--include '-C SPT_PROC.C
Cc-w-o2-g-I. ' Mysql_config--include '-C driver.c
Cc-w-o2-g-I. ' Mysql_config--include '-C sequence.c
Cc-w-o2-g-I. ' Mysql_config--include '-C rthist.c
Cc-w-o2-g-I. ' Mysql_config--include '-C NEWORD.C
Cc-w-o2-g-I. ' Mysql_config--include '-C payment.c
Cc-w-o2-g-I. ' Mysql_config--include '-C ordstat.c
Cc-w-o2-g-I. ' Mysql_config--include '-C delivery.c
Cc-w-o2-g-I. ' Mysql_config--include '-C slev.c
CC MAIN.O SPT_PROC.O driver.o support.o sequence.o rthist.o ' neword.o payment.o ordstat.o delivery.o slev.o ' Mysql_config- -libs_r '-lrt-o. /tpcc_start

Three Initialization test library environment

The make command generates the TPCC command-line tool tpcc_load in the Tpcc-mysql directory, Tpcc_start

Tpcc_load provides the ability to initialize data

Tpcc_start for stress testing

Usage:


#./tpcc_load--help
tpcc_load [Server] [DB] [user] [pass] [warehouse]
Server: Servers name
DB: Database name
User: Username
Pass: Password
Warehouse: Number of warehouses

The code is as follows Copy Code
#./tpcc_start--help
Tpcc_start-h server_host-p port-d database_name-u mysql_user-p mysql_password-w warehouses-c connections-r warmup_ Time-l running_time-i report_interval-f Report_file

Describe the use of each parameter
-H server_host: server name
-P Port: Port number defaults to 3306
-d database_name: Database name
-u mysql_user: User name
-P Mysql_password: password
-W Warehouses: number of warehouses
-C Connections: Number of threads, defaults to 1
-R Warmup_time: Warm-up time, Unit: s, the default is 10s, warm up is to load data into memory.
-L Running_time: Test time, Unit: s, default 20s
-I report_interval: Specifies the length of the build report interval
-F report_file: Test results output file

Attention

TPCC default will read/var/lib/mysql/mysql.sock this socket location, if your test environment MySQL socket is not the appropriate path, you need to make a soft connection, or TCP/IP way to connect the test server.

Preparatory work:

The code is as follows Copy Code


#mysql-uroot-p-E "Create DB TPCC" # Create a test database
#mysql-uroot-p TPCC < Create_table.sql # Create a test table
#mysql-uroot-p TPCC < Add_fkey_idx.sql # create FK and Index

1 Create five data warehouses

The code is as follows Copy Code
#./tpcc_load localhost TPCC root "123456" 5
*************************************
# # #easy ### tpc-c Data Loader * * *
*************************************
<Parameters>
[Server]: localhost
[Port]: 3306
[dbname]: TPCC
[User]: Root
[Pass]: 123456
[Warehouse]: 5
TPCC Data Load started ...
Loading Item
.................................................. 5000

.................................................. 10000
Ignore partial output results

Iv. Conducting testing

Use Tpcc_start for 5-thread testing, warm-up time is 120 seconds, test time is 1 hours!

The code is as follows Copy Code
#./tpcc_start-hlocalhost-d tpcc-u root-p "123456"-W 5-c 5-r 120-l->tpcc-output-log

V. Generate charts

First write a script to get the data source:

The code is as follows Copy Code


# cat tpcc-output-analyze.sh
#!/bin/sh
timeslot=1
If [-N $]
then
timeslot=$2
Fi
Cat | grep- V HY000 | Grep-v Payment | Grep-v Neword | Awk-v timeslot= $TIMESLOT ' BEGIN {fs= ' [, ():] '; s=0; cntr=0; aggr=0}/measuring start/{S=1}/stopping threads/{s=0}/0 /{if (s==1) {cntr++; aggr+=$2} if (Cntr==timeslot) {printf ("%d%3dn", $ (Aggr/timeslot)); cntr=0; aggr=0}} '

# cat tpcc-output-analyze.sh
#!/bin/sh
timeslot=1
If [-N ' $ ']
then
timeslot=$2
Fi
Cat $ | Grep-v HY000 | Grep-v Payment | Grep-v Neword | Awk-v timeslot= $TIMESLOT ' BEGIN {fs= ' [, ():] '; s=0; cntr=0; aggr=0}/measuring start/{S=1}/stopping threads/{s=0}/0 /{if (s==1) {cntr++; aggr+=$2} if (Cntr==timeslot) {printf ("%d%3dn", $ (Aggr/timeslot)); cntr=0; aggr=0}} '

This script is the first column and the second column of Tpcc-output-nobinlog.

The code is as follows Copy Code


#./tpcc-output-analyze.sh Tpcc-output-nobinlog > Tpcc-graphic-data.txt

Drawing process:

The code is as follows Copy Code

#cat log.conf
The set terminal gif small size 480,360 #指定输出成gif图片, and the picture size is 550x25
Set output "Tcpp.gif" #指定输出gif图片的文件名
Set title "MySQL Performance" #图片标题
Set style data lines #显示网格
Set Xlabel "time/s" #X轴标题
Set Ylabel "Data" #Y轴标题
Set Grid #显示网格
Plot
"Tpcc-graphic-data.txt" using 1:2 title "Total Throughput" with lines #从tpcc-graphic-data.txt

The first column and the second column are read in the file as x-axis and y-axis data, the example name "Total Throughput"

The code is as follows Copy Code
#cat log.conf
The set terminal gif small size 480,360 #指定输出成gif图片, and the picture size is 550x25
Set output "Tcpp.gif" #指定输出gif图片的文件名
Set title "MySQL Performance" #图片标题
Set style data lines #显示网格
Set Xlabel "time/s" #X轴标题
Set Ylabel "Data" #Y轴标题
Set Grid #显示网格
Plot
"Tpcc-graphic-data.txt" using 1:2 title "Total Throughput" and lines #从tpcc-graphic-data.txt file read the first column and the second column as x-axis and y-axis data, sample name "Total Throughput"

To run the build tcpp.gif:

  code is as follows copy code


#cat log.conf | Gnuplot

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.