shell脚本利用gnuplot绘制图片
2013-10-23 14:15
429 查看
我们都知道gnuplot可以绘制图片,但是时候,我们的数据是以date文件的形式存在,如何编写一个脚本帮助我们绘制出相应的图片:
以某个进程的CPU使用情况为例:
catprocessX_CPU_Usage.log
WedOct1614:47:35CST2013:ProcessCPUsage(%)Total
WedOct1614:47:37CST2013:1828172008
WedOct1614:47:39CST2013:1828171706
WedOct1614:47:42CST2013:1828121689
WedOct1614:47:44CST2013:1828211673
WedOct1614:47:46CST2013:1828151668
WedOct1614:47:48CST2013:182881699
WedOct1614:47:50CST2013:1828171699
WedOct1614:47:53CST2013:1828172148
WedOct1614:47:55CST2013:1828151815
WedOct1614:47:57CST2013:1828321727
WedOct1614:47:59CST2013:1828111669
WedOct1614:48:01CST2013:182841667
WedOct1614:48:03CST2013:182881678
WedOct1614:48:05CST2013:1828161694
WedOct1614:48:08CST2013:182891669
WedOct1614:48:10CST2013:1828261750
WedOct1614:48:12CST2013:182861792
WedOct1614:48:14CST2013:1828141720
WedOct1614:48:17CST2013:1828121800
WedOct1614:48:19CST2013:1828241921
WedOct1614:48:21CST2013:1828111749
WedOct1614:48:23CST2013:182891708
WedOct1614:48:25CST2013:1828151665
WedOct1614:48:27CST2013:182831751
WedOct1614:48:30CST2013:1828101692
WedOct1614:48:32CST2013:1828151678
WedOct1614:48:34CST2013:1828191708
WedOct1614:48:36CST2013:1828141707
WedOct1614:48:38CST2013:1828151680
WedOct1614:48:40CST2013:1828181678
我们看到了输出是这么个情况,我们希望绘制一张简单的图片,把CPUusage的情况绘制出来:每一行的第八列是我们想要的数据,我们可以绘制一个时间序列:
manu@manu-hacks:~/code/shell/gnuplot$catwork.sh
我这个方法比较简单,title就是数据来源的文件名字,ylabel是字段名字,实际上,由用户输入titleylabel以及图例的title会更加合适。我这只是一个简单的sample,来分享如何在shell脚本利用gnuplot绘制图片。
使用命令如下:
./work.sh/home/manu/processX_CPU_Usage.log8
输出图片如下:
我这是一个简单的例子,实际上,我们实际可能会跑出来40个进程的CPU使用情况,我们可以将参数写入配置文件,然后每一行去执行work.sh,这样的话,我们就可以直接维护配置文件就可以了。当然了,我的脚本还很简陋很粗糙粗,远远不能在工程中实际使用。毕竟是晚上捣鼓出来的小玩意儿。
以某个进程的CPU使用情况为例:
catprocessX_CPU_Usage.log
WedOct1614:47:35CST2013:ProcessCPUsage(%)Total
WedOct1614:47:37CST2013:1828172008
WedOct1614:47:39CST2013:1828171706
WedOct1614:47:42CST2013:1828121689
WedOct1614:47:44CST2013:1828211673
WedOct1614:47:46CST2013:1828151668
WedOct1614:47:48CST2013:182881699
WedOct1614:47:50CST2013:1828171699
WedOct1614:47:53CST2013:1828172148
WedOct1614:47:55CST2013:1828151815
WedOct1614:47:57CST2013:1828321727
WedOct1614:47:59CST2013:1828111669
WedOct1614:48:01CST2013:182841667
WedOct1614:48:03CST2013:182881678
WedOct1614:48:05CST2013:1828161694
WedOct1614:48:08CST2013:182891669
WedOct1614:48:10CST2013:1828261750
WedOct1614:48:12CST2013:182861792
WedOct1614:48:14CST2013:1828141720
WedOct1614:48:17CST2013:1828121800
WedOct1614:48:19CST2013:1828241921
WedOct1614:48:21CST2013:1828111749
WedOct1614:48:23CST2013:182891708
WedOct1614:48:25CST2013:1828151665
WedOct1614:48:27CST2013:182831751
WedOct1614:48:30CST2013:1828101692
WedOct1614:48:32CST2013:1828151678
WedOct1614:48:34CST2013:1828191708
WedOct1614:48:36CST2013:1828141707
WedOct1614:48:38CST2013:1828151680
WedOct1614:48:40CST2013:1828181678
我们看到了输出是这么个情况,我们希望绘制一张简单的图片,把CPUusage的情况绘制出来:每一行的第八列是我们想要的数据,我们可以绘制一个时间序列:
manu@manu-hacks:~/code/shell/gnuplot$catwork.sh
#!/bin/sh file=$1 field=$2 yfield=`cat $file |awk '{if(NR==1) print $'''$field'''}'` title=`basename $file` if [ $# -eq 2 ] then echo " set terminal pngcairo lw 2 set title \"$title\" set ylabel \"$yfield\" set output './output/$title-$yfield.png' plot \"$file\" using $field w lp pt 7 title \"$yfield\" set output set terminal wxt " | gnuplot fi
我这个方法比较简单,title就是数据来源的文件名字,ylabel是字段名字,实际上,由用户输入titleylabel以及图例的title会更加合适。我这只是一个简单的sample,来分享如何在shell脚本利用gnuplot绘制图片。
使用命令如下:
./work.sh/home/manu/processX_CPU_Usage.log8
输出图片如下:
我这是一个简单的例子,实际上,我们实际可能会跑出来40个进程的CPU使用情况,我们可以将参数写入配置文件,然后每一行去执行work.sh,这样的话,我们就可以直接维护配置文件就可以了。当然了,我的脚本还很简陋很粗糙粗,远远不能在工程中实际使用。毕竟是晚上捣鼓出来的小玩意儿。
相关文章推荐
- Shell脚本利用gnuplot绘制图片
- 利用shell脚本抽取ipa中的图片资源
- 利用oprofile分析fortran并用gnuplot画图的shell脚本
- openGL学习笔记1(入门----如何绘制 直线、多边形、圆、利用图片绘制图形等)
- 在Windows、Linux下,分别利用BAT批处理文件和Shell脚本,生成类似“20150605_111327.txt”命名的文件
- 利用shell脚本监控网站状态 推荐
- 写一个shell脚本利用wget抓取股票历史数据
- 带客户端脚本的图片控件,可利用后台代码修改图片显示(C#代码)
- 利用shell脚本来监控linux系统的负载与CPU占用情况
- 利用shell脚本监控网站状态
- 利用Shell开发跳板机功能脚本案例
- 【COCOS2DX-LUA 脚本开发之十二】Hybrid模式-利用AssetsManager实现在线更新脚本文件lua、js、图片等资源(免去平台审核周期)
- shell脚本实现图片文件的重命名之修订版本~
- shell脚本二(图片重命名)
- openstack shell脚本 利用curl 删除实例 API
- 创建shell脚本,利用for循环箱向日志文件中插入n条数据
- 利用脚本将文字插入到图片或进行多个图片拼接
- 利用shell脚本统计代码行数
- shell脚本写的一个图片抓取器
- 利用SHELL脚本自动拦截DDOS攻击