经常要查看一些日志的输出速度,用来判断是否有速度异常等

如果全部加上监控的话会很麻烦,而且可能看了一次就再也不看了,

是否有一个工具可以马上看到日志的输出速度呢?

 

我给大家写了一个

代码很简单,文件名log_speed.py

#!/usr/bin/env python
#coding:utf8

import sys
import time


count = 0
time_start = time.time()

while True:
    row = sys.stdin.readline()
    if not row:
        break
    count += 1

    deta_t = time.time()-time_start
    sys.stdout.write('\rtotal:%d,speed: %d/s'% (count,count/deta_t))
    sys.stdout.flush()

如何使用呢

准备工作

sudo chmod +x log_speed.py

sudo cp log_speed.py /usr/local/bin/log_speed

常见用法

统计nginx日志的速度

tail -f /var/log/nginx/access.log | log_speed

统计nginx日志含有爬虫的输出速度

tail -f /var/log/nginx/access.log |grep spider |log_speed

 

https://github.com/suxianbaozi/log_speed

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐