从时间戳csv绘制每分钟请求数

时间:2015-06-24 18:30:23

标签: gnuplot

我有一个带有unix-timestamps的.csv文件,每个时间戳都描述了服务器上的一个请求。

现在,我想在图表中绘制每分钟/小时的请求数量图表。 像负载图一样。

如何使用gnuplot完成?

1 个答案:

答案 0 :(得分:0)

是的,gnuplot可以绘制这样的图表。在您的情况下,我建议使用boxes绘图样式,与histogram样式相比,使用传统的数字轴。

要计算每分钟或每小时的请求数,您必须正确地合并时间值。为此,请使用gnuplot提供的tm_*函数来切断秒或分钟,并将数据正确分组到完整的分钟或整个小时(另请参阅Gnuplot y-axis value from x(dates))。

要分到几分钟,请使用

bin_minutes(t) = t - tm_sec(t)

这只是从原始时间戳中减去秒数。这会将所有值映射为从0到59到同一分钟的秒数。要使框在0到59秒之间正确居中​​,请添加30秒。

bin_minutes(t) = t - tm_sec(t) + 30

要分到几个小时,请使用

bin_hours(t) = t - tm_min(t)*60 + 30*60 - tm_sec(t)

此外,你必须知道,那个gnuplot 4.6。使用1. Jan 2000作为所有时间函数的参考,gnuplot 5.0使用1. Jan 1970,就像正常的Unix时间戳一样。因此,根据您的gnuplot版本,您必须从Unix时间戳中减去一个偏移量,以获得正确的值(另请参阅我对Can I plot times when they're given as UNIX timestamps with added milliseconds?的回答中的讨论。)

将所有内容放在一起应该提供一个工作脚本(由于您没有发布任何数据,因此无法对其进行测试):

set yrange [0:*]
set xdata time
offset = (GPVAL_VERSION < 5.0 ? 946684800 : 0)
bin_minutes(t) = t - tm_sec(t) + 30
bin_hours(t) = t - tm_min(t)*60 + 30*60 - tm_sec(t)

plot 'file.dat' using (bin_minutes($1-offset)):(1) smooth frequency title 'requests per minute',\
     '' using (bin_hours($1-offset)):(1) smooth frequency title 'requests per hour'
相关问题