python 分析系统日志
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 分析系统日志相关的知识,希望对你有一定的参考价值。
cat message.txt
[19-Mar-2015 16:47:50] WARNING: [pool www] child 10687, script '//index.php' (request: "GET /index.php") executing too slow (18.437847 sec), logging
[19-Mar-2015 16:47:50] WARNING: [pool www] child 10265, script '//index.php' (request: "GET /index.php") executing too slow (17.261909 sec), logging
[19-Mar-2015 16:47:50] WARNING: [pool www] child 9579, script '//index.php' (request: "GET /index.php") executing too slow (15.524025 sec), logging
[19-Mar-2015 16:47:55] WARNING: [pool www] child 10449, script '//index.php' (request: "GET /index.php") executing too slow (16.406524 sec), logging
[19-Mar-2015 16:47:55] WARNING: [pool www] child 9033, script '//index.php' (request: "GET /index.php") executing too slow (70.163890 sec), logging
[19-Mar-2015 16:59:35] WARNING: [pool www] child 10946, script '//index.php' (request: "GET /index.php") executing too slow (90.114181 sec), logging
[19-Mar-2015 16:59:50] WARNING: [pool www] child 10725, script '//index.php' (request: "GET /index.php") executing too slow (60.266744 sec), logging
[19-Mar-2015 16:59:55] WARNING: [pool www] child 9920, script '//index.php' (request: "GET /index.php") executing too slow (18.143190 sec), logging
求python做计划任务每次读取几行,每次读取时已读的旧数据不再读入都读新的 ,过滤出 executing too slow (19.163890 sec) 当数值达大于60 就打印 如php_slow:70
这样就可以了。然后wc统计行数。
如果你一定要用python做。就使用文件对象中的seek方法,移到上次处理的位置。追问
首先感谢您,我是想用python处理 然后sender到zabbix,python每次读都是新内容这样减少误报警!
以上是关于python 分析系统日志的主要内容,如果未能解决你的问题,请参考以下文章