使用 shell 基于日志计算每秒查询值的简单方法
我们能够跟踪我们托管的服务器上的流量:
...
+1287737841.266952 ...
+1287737841.267117 ...
+1287737841.267136 ...
+1287737841.278288 ...
+1287737841.278310 ...
+1287737841.278321 ...
+1287737841.278331 ...
+1287737841.278341 ...
...
如您所见,它们包括时间戳,精确到微秒! 我只是希望能够计算浮动 QPS(每秒查询数),也许是每分钟,甚至每小时。有什么办法用shell来做吗?
We're able to tail the traffic on a server that we host :
...
+1287737841.266952 ...
+1287737841.267117 ...
+1287737841.267136 ...
+1287737841.278288 ...
+1287737841.278310 ...
+1287737841.278321 ...
+1287737841.278331 ...
+1287737841.278341 ...
...
As you can see they include timestamps, down to the micro-second!
I just want to be able to compute a floating QPS (Queries Per Second), and maybe per minute, and per hour from this. Any way of doing it with the shell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
中,这将为您提供每秒的查询数:
假设您有可用的 bash 并且您的日志位于文件Traffic.log 科尔姆 1 1 |科尔姆 11 | uniq -c
这将为您提供每分钟的查询数:
for i in
cat Traffic.log |科尔姆 1 1 | colrm 11
;执行 echo $(($i/60));完成 | uniq -c这将为您提供每小时的查询数量:
for i in
cat Traffic.log |科尔姆 1 1 | colrm 11
;执行 echo $(($i/3600));完成 | uniq -c我确信一定有一种 CPU 密集程度较低的方法来做到这一点,但这是我首先想到的。
让我知道它是否有效。
Assuming you have bash available and that your log is on the file traffic.log, this would give you the number of queries per second:
cat traffic.log | colrm 1 1 | colrm 11 | uniq -c
This would give you the number of queries per minute:
for i in
cat traffic.log | colrm 1 1 | colrm 11
; do echo $(($i/60)); done | uniq -cAnd this would give you the number of queries per hour:
for i in
cat traffic.log | colrm 1 1 | colrm 11
; do echo $(($i/3600)); done | uniq -cI'm sure there must be a less CPU intensive way of doing it but this is the first thing that came to my mind.
Let me know if it worked.