我正在尝试绘制 REST 命令需要多少毫秒的图表。该命令每分钟发出多次。这是我编写的插件:
#!/bin/bash
#
# Collect stats for the timing of recommendations.
#
logs="/var/www/custhome/logs/play.log"
# CONFIG
if [ "$#" -eq "1" ] && [ "$1" = "config" ]; then
echo "graph_title Post Recommendation Times"
echo "graph_category apache"
echo "graph_info Data is pooled from all sites."
echo "graph_vlabel ms"
echo "graph_period ms"
echo "graph_data_size huge"
echo "precs.label PostRecommending"
echo "precs.type GAUGE"
echo "precs.min 0"
echo "precs.draw AREA"
exit
fi
# DATA
precs=(`grep :Post.Recommending /var/www/custhome/logs/play.log | awk '{print $7}'`)
for i in "${precs[@]}"
do
[ $i -eq 0 ] && continue
echo "precs.value $i"
done
日志文件中的典型行如下:
4:59:17,422 DEBUG ~ colorado:45870:Post Recommending took 1925 millis
15:02:22,588 DEBUG ~ michigan:417550:Post Recommending took 1306 millis
15:02:23,753 DEBUG ~ michigan:417550:Post Recommending took 276 millis
15:02:23,754 DEBUG ~ michigan:417550:Post Recommending took 277 millis
15:05:21,047 DEBUG ~ chicago:1105784:Post Recommending took 2484 millis
15:07:02,275 DEBUG ~ colorado:66199:Post Recommending took 3303 millis
问题是,图表每次刷新时都显示相同的数据 - 1.53k 毫秒。这个数字似乎是一个平均值。我想要看到的是显示所有值的图表,并且它需要随着新数据的输入而随时间变化。
在 munin 中有没有更好的方法可以做到这一点?或者我应该先对数据进行一些预处理?或者使用完全不同的工具来查看我需要的结果?我习惯使用 munin 来绘制每秒 REST 调用总数之类的图表。但我很难理解如何表示这些数据。
答案1
我最终通过计算每次读取的平均值来做到这一点:
for i in "${recs[@]}"
do
((total+=$i))
done
echo "recs.value $((total/${#recs[@]}))"