【gnuplot】收集系统资源,使用gnuplot进行简单绘图


前言

测试过程中,某些场景下会对服务器使用资源进行监控。测试结果可以使用gnuplot工具,对测试结果进行绘图整理。本文以对数据库指定进程内存占用监控结果进行说明。


一、gnuplot安装

1.1 安装过程

安装版本:gp548-win64-mingw.exe
安装路径:自定义(尽量不要包括中文)
安装选项:默认
添加环境变量:
电脑->属性->高级系统设置->环境变量->系统变量->Path->D:\01_tools\29_gnuplot\install\bin->确定
在这里插入图片描述

1.2 安装后验证

cmd -> gnuplot
在这里插入图片描述

二、采集数据

2.1 top监控采集

采集指定进程资源,并重定向到文件
nohup top -p 2254,2261,2264 -c -b -d 5 -n 240 >> db_pro_mem.log &
在这里插入图片描述

[test@localhost gnuplot]$ head -n 10 db_pro_mem.log
top - 04:34:39 up 22 min,  2 users,  load average: 0.02, 0.46, 0.49
Tasks:   3 total,   0 running,   3 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2897500 total,   542824 free,   460480 used,  1894196 buff/cache
KiB Swap:  2097148 total,  2097148 free,        0 used.  1990096 avail Mem

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
  2254 test      20   0  629048  71848  69892 S   0.0  2.5   0:00.11 /home/tes+
  2261 test      20   0  235048   3580    964 S   0.0  0.1   0:00.29 kingbase:+
  2264 test      20   0  629048   2828    852 S   0.0  0.1   0:00.00 kingbase:+

说明:采集周期5秒,共采集240次,共20分钟

2.2 处理数据

 grep "04:" db_pro_mem.log|awk {'print $3'} >> time.txt    #将时间过滤到文本
 grep "2254" db_pro_mem.log |awk {'print $5'} >> master_mem.txt    #master进程VIRT内存使用
 grep "2261" db_pro_mem.log |awk {'print $5'} >> stat_mem.txt    #stats collector进程VIRT内存使用
 grep "2264" db_pro_mem.log |awk {'print $5'} >> kwr_mem.txt    #kwr collector进程VIRT内存使用
 paste time.txt master_mem.txt stat_mem.txt kwr_mem.txt >> db_mem_20min.txt    #将三个文本合并

在这里插入图片描述

处理后数据如下:
*
[@localhost temp]$ head -n 10 mem_res_20min.txt
06:07:18 71572 4084 2804
06:07:23 71572 4084 2804
06:07:28 71572 4084 2804
06:07:33 71572 4084 2804
06:07:38 71572 4084 2804
06:07:43 71572 4084 2804
06:07:48 71572 4084 2804
06:07:53 71572 4084 2804
06:07:58 71572 4084 2804
06:08:03 71572 4084 2804

三、使用gunplot绘图

3.1 参数设置

set xlabel “time” #设定x轴标签
set ylabel “memory [kb]” #设定y轴标签
set ydata #设定y轴为数据
set yr[1000:1000000] #设定y轴为数据范围
set xdata time #设定x轴为时间格式
set format x “%H:%M:%S” #设定x轴为时间格式%H:%M:%S
set timefmt “%H:%M:%S”
set xr [“00-00-00”:“24-00-00”] #设定x轴为时间范围
show xr #查询x轴范围(range)
show timefmt #查询时间格式

gnuplot> set xlabel "time"
gnuplot> set ylabel "memory [kb]"
gnuplot> set ydata
gnuplot> set yr[1000:1000000]
gnuplot> set xdata time
gnuplot> set format x "%H:%M:%S"
gnuplot> set timefmt "%H:%M:%S"
gnuplot> set xr ["00-00-00":"24-00-00"]
gnuplot> show xr

        set xdata time
        set xrange [ "00:00:00" : "00:00:00" ] noreverse writeback

gnuplot> show timefmt

        Default format for reading time data is "%H:%M:%S"

在这里插入图片描述

3.2 绘图

  • 进入数据文件所在目录,执行:cmd -> gnuplot

  • 执行如下命令进行绘图
    plot "mem_res_20min.txt" using 1:2 title "postmaster" with l lt 6 lw 2,"" using 1:3 title "stats collector" with l lt 7 lw 2,""using 1:4 title "kwr collector" with l lt 9 lw 2;
    在这里插入图片描述

参数说明

参数名称说明
using使用数据文件第一列和第二列绘图
title图列名称
with图形选项
l(line)以线的样式绘图
p(point)以点的样式绘图
lt(line type)线条样式(在gnuplot中执行test可查询)
lw(line wide)线条粗细

test可以查看图例样式编号
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值