利用 gnuplot 绘制图 sar搜集数据

1. 利用gnuplot工具对sar 搜集的数据绘图

[root@nd3 ~]# sar -b -f /var/log/sa/sa26 |gawk '/^[^a-z]+$/{print $1"\t"($NF+$(NF-1))}' >/tmp/block.tmp

[root@nd3 ~]# cat /tmp/block.tmp 

11:50:01        104.3

12:00:01        6.08

12:10:01        14.99

12:20:01        31.66

12:30:01        8.35

12:40:01        53.13

12:50:01        13.61

13:00:01        250.68

[root@nd3 ~]# sar -q|gawk '/^[^a-z]+$/{print $1,$4,$5,$6}'>/tmp/cpuload.tmp

[root@nd3 ~]# cat /tmp/cpuload.tmp 

11:50:01 0.00 0.03 0.05

12:00:01 0.00 0.00 0.00

12:10:01 0.00 0.00 0.00

12:20:01 0.00 0.00 0.00

12:30:01 0.00 0.00 0.00

12:40:01 0.00 0.00 0.00

12:50:01 0.00 0.00 0.00

13:00:01 0.00 0.01 0.00

13:10:01 0.00 0.00 0.00

[root@nd3 ~]# yum install gnuplot -y

第一种方法:

#gnuplot

gnuplot> set xdata time

gnuplot> set timefmt "%H:%M:%S"

gnuplot> set xlabel "Time"

gnuplot> set ylabel "Load Average"

gnuplot> plot "/tmp/cpuload.tmp" using 1:2 title "1min" with lines,"/tmp/cpuload.tmp" using 1:3 title "5mins" with lines,"/tmp/cpuload.tmp" using 1:4 title "15mins" with lines

第二种方法,把常用的命名保存到文件中执行;

[root@nameserver Desktop]# gnuplot -persist cpu.gnuplot 

[root@nameserver Desktop]# cat cpu.gnuplot 

set xdata time

set timefmt "%H:%M:%S"

set xlabel "Time"

set ylabel "Load Average"

plot "/tmp/cpuload.tmp" using 1:2 title "1min" with lines,"/tmp/cpuload.tmp" using 1:3 title "5mins" with lines,"/tmp/cpuload.tmp" using 1:4 title "15mins" with lines


2. 终极使用,搜集每天12:00到14点I/O情况,并生成对应的图片,放置到/var/www/html/stat/io.`date +%F`.png

# sar -b -s 12:00:00 -e 14:00:00 |gawk '/^[^a-z]+$/{print $1,$5,$6}' >/tmp/block.`date +%F` 

# cat /tmp/block.gnuplot 

set xdata time

set timefmt "%H:%M:%S"

set xlabel "Time"

set ylabel "I/O stat"

set term png size 1024,768

set output "/var/www/html/stat/io.`date +%F`.png"

plot "/tmp/block.`date +%F`" using 1:2 title "bread/s" with lines,"/tmp/block.`date +%F`" using 1:3 title "bwrite/s" with lines

# 把它用计划任务每天运行就好了

[root@nameserver Desktop]# crontab -l

10 14 * * * sar -b -s 12:00:00 -e 14:00:00 |gawk '/^[^a-z]+$/{print $1,$5,$6}'>/tmp/block && gnuplot /shell/block.gnuplot >/dev/null 2>&1

3. Sar 的用法

sar -b 1 磁盘I/O.每一秒刷新一次

# sar -q 1 负载

sar -P 1 -f /var/log/sa/sa22 查指定的CPU


转载于:https://my.oschina.net/eloops/blog/111087

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值