该脚本作用用于查询日志过去一分钟内的并发量,并发单位位1分钟,结果打印在标准输出中,可以配合一些软件实现日志的并发实时监控,比如zabbix。
在今天的桌面应用世界上有大量的奖励,以便能够开发应用程序,可以运行在多个环境。目前,有一种跨平台框架可供选择的Python开发桌面应用程序屈指可数。 wxPython的就是这样的一个跨平台的GUI工具包的Python编程语言。它允许Python程序员创建一个完整的,功能强大的图形用户界面的程序,简单,方便。 wxPython的代码风格,改变了多年来不少,并得到更多Python的。例子,你会发现这本书是对不断更新,反映在风格上的变化。 本书提供最新的书,快速创建健壮的,可靠,可重复使用的wxPython应用
1
#! /usr/local/bin/python3
import sys
import re
import datetime
import os
def generate_previous_minutes():
format='%d/%b/%Y:%H:%M'
return (datetime.datetime.today()-datetime.timedelta(minutes=1)).strftime(format)
def check_logs(log_path,examine_minutes):
regex_minutes=re.compile(examine_minutes)
minutes_count=0
step=10*1024*1024
with open(log_path,encoding='Latin-1') as file:
line=file.readline()
while line:
time_line=line.split(' ')[3][1:]
if time_line>=examine_minutes:
file.seek(file.tell()-step)
file.readline()
break
file.seek(file.tell()+step)
if file.tell()>=os.path.getsize(log_path):
file.seek(file.tell()-step)
file.readline()
break
file.readline()
line=file.readline().strip()
for line in file:
line=line.strip()
words=line.split(' ')
if(regex_minutes.search(words[3])):
minutes_count+=1
print(minutes_count)
def main(log_path):
previous_minutes=generate_previous_minutes()
print(previous_minutes)
check_logs(log_path,previous_minutes)
if __name__ == '__main__':
log_path=sys.argv[1]
main(log_path)
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号