python 实现提取log文件中的关键句子,并进行统计分析
作者:Allen_Zhong 时间:2022-04-19 06:24:09
利用python开发了一个提取sim.log 中的各个关键步骤中的时间并进行统计的程序:
#!/usr/bin/python2.6
import re,datetime
file_name='/home/alzhong/logs/qtat1/R2860.01.13/sim-applycommitrollback-bld1.log'
file=open(file_name,'r')
acnum=[];time_res=[];lnum=0
def trans_time(time):
t1=datetime.datetime.strptime(time,'%y/%m/%d %H:%M:%S')
return t1
for (num,line) in enumerate(file):
if(re.search(r'^(.*)BEGINNING SIM PROCEDURE(.*)$',line)):
m=re.search(r'^(.*)BEGINNING SIM PROCEDURE(.*)$',line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
elif(re.search(r'^(.*)CP_W(.*)$', line)):
m=re.search(r'^(.*)CP_W(.*)$', line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
elif(re.search(r"^(.*)VERIFY_S(.*)$", line)):
m=re.search(r"^(.*)VERIFY_S(.*)$", line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
elif(re.search(r"^(.*)--action commit(.*)$",line)):
m=re.search(r"^(.*)--action commit(.*)$",line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
elif(re.search(r"^(.*)COMPLETED SIM PROCEDURE(.*)$",line)):
m=re.search(r"^(.*)COMPLETED SIM PROCEDURE(.*)$",line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
elif(re.search(r"^(.*)RESUMING SIM PROCEDURE(.*)$",line)):
m=re.search(r"^(.*)RESUMING SIM PROCEDURE(.*)$",line)
print 'Step %d:'%(lnum), m.group(0);lnum+=1
acnum.append(trans_time(line[0:17]))
file.close()
if(re.search(r"^(.*)backout(.*)$",file_name)):
time_res.append((acnum[2]-acnum[0]).seconds/60)
time_res.append((acnum[4]-acnum[3]).seconds/60)
time_res.append((acnum[6]-acnum[5]).seconds/60)
time_res.append(((acnum[8]-acnum[7])+(acnum[10]-acnum[9])+(acnum[13]-acnum[11])).seconds/60)
print "\n3). sim --proc update --action apply to \"CP_WARNING\" %s mins" %(time_res[0])
print "4). sim --proc update --action resume to \"VERIFY_SOFTWARE\" %s mins"%(time_res[1])
print "5). sim --proc update --action resume to \"COMMIT\" %s mins"%(time_res[2])
print "8). Backout from RXX to RXX %s mins"%(time_res[3])
elif(re.search(r"^(.*)rollback(.*)$",file_name)):
time_res.append((acnum[2]-acnum[0]).seconds/60)
time_res.append((acnum[4]-acnum[3]).seconds/60)
time_res.append((acnum[6]-acnum[5]).seconds/60)
time_res.append((acnum[8]-acnum[7]).seconds/60)
time_res.append(((acnum[10]-acnum[9])+(acnum[12]-acnum[11])+(acnum[15]-acnum[13])).seconds/60)
print "\n3). sim --proc update --action apply to \"CP_WARNING\" %s mins" %(time_res[0])
print "4). sim --proc update --action resume to \"VERIFY_SOFTWARE\" %s mins"%(time_res[1])
print "5). sim --proc update --action resume to \"COMMIT\" %s mins"%(time_res[2])
print "6). sim --proc update --action commit to end of Patch %s mins"%(time_res[3])
print "8). Rollback from RXX to RXX %s mins" %(time_res[4])
if __name__ == '__main__':
pass
:q!
<lsslogin1-alzhong>/home/alzhong/tools: ls
simt
<lsslogin1-alzhong>/home/alzhong/tools: ./simt
Step 0: 14/06/16 12:31:32 BEGINNING SIM PROCEDURE 'update apply' type=hot ...
Step 1: 14/06/16 13:18:42 RESUMING SIM PROCEDURE 'update apply' type=hot ...
Step 2: 14/06/16 13:30:43 SIM0317 PAUSE_REQUEST: (PROCEDURE) [PAUSE(CP_WARNING): Use 'sim --proc update --action resume' to continue...] (update:1435)
Step 3: 14/06/16 13:43:40 RESUMING SIM PROCEDURE 'update apply' type=hot ...
Step 4: 14/06/16 13:47:49 SIM0343 PAUSE_REQUEST: (PROCEDURE) [PAUSE(VERIFY_SOFTWARE): Use 'sim --proc update --action resume' to continue...] (update:1634)
Step 5: 14/06/16 13:54:26 RESUMING SIM PROCEDURE 'update apply' type=hot ...
Step 6: 14/06/16 14:25:41 SIM0496 PAUSE_REQUEST: (COMMIT) [PAUSE(COMMIT): Use 'sim --proc update --action commit' to continue...] (update:2579)
Step 7: 14/06/16 14:41:51 RESUMING SIM PROCEDURE 'update commit' type=hot ...
Step 8: 14/06/16 15:18:34 COMPLETED SIM PROCEDURE 'update commit' type=hot
Step 9: 14/06/16 15:31:35 BEGINNING SIM PROCEDURE 'update rollback' type=hot level=9999 ...
Step 10: 14/06/16 15:47:34 SIM0091 PAUSE_REQUEST: (PROCEDURE) [PAUSE(CP_WARNING): Use 'sim --proc update --action resume' to continue...] (update_rlbk:421)
Step 11: 14/06/16 15:53:30 RESUMING SIM PROCEDURE 'update rollback' type=hot level=9999 ...
Step 12: 14/06/16 16:02:03 SIM0135 PAUSE_REQUEST: (PROCEDURE) [PAUSE(VERIFY_SOFTWARE): Use 'sim --proc update --action resume' to continue...] (update_rlbk:564)
Step 13: 14/06/16 16:04:22 RESUMING SIM PROCEDURE 'update rollback' type=hot level=9999 ...
Step 14: 14/06/16 16:09:42 RESUMING SIM PROCEDURE 'update rollback' type=hot level=9999 ...
Step 15: 14/06/16 16:26:56 COMPLETED SIM PROCEDURE 'update rollback' type=hot level=9999
3). sim --proc update --action apply to "CP_WARNING" 59 mins
4). sim --proc update --action resume to "VERIFY_SOFTWARE" 4 mins
5). sim --proc update --action resume to "COMMIT" 31 mins
6). sim --proc update --action commit to end of Patch 36 mins
8). Rollback from RXX to RXX 47 mins
来源:https://blog.csdn.net/zhongyu211/article/details/34423213
标签:python,log,关键句子
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于Python编写一个刷题练习系统
2022-10-01 13:28:34
![](https://img.aspxhome.com/file/2023/2/79442_0s.png)
各种Python库安装包下载地址与安装过程详细介绍(Windows版)
2021-01-27 14:00:05
![](https://img.aspxhome.com/file/2023/9/89089_0s.png)
linux 下python多线程递归复制文件夹及文件夹中的文件
2021-06-28 03:27:44
Go本地测试小技巧解耦任务拆解
2023-08-29 14:09:26
二级下拉菜单代码
2008-11-01 18:18:00
SQL触发器实例讲解
2012-04-13 11:52:48
Python中for循环可迭代对象迭代器及生成器源码学习
2023-10-11 07:00:30
三行代码使用Python将视频转Gif的方法示例
2021-02-28 13:53:39
![](https://img.aspxhome.com/file/2023/8/104988_0s.gif)
详细介绍Python的鸭子类型
2023-07-14 10:28:17
python ddt实现数据驱动
2021-11-11 02:37:08
MS Server和Oracle中对NULL处理的一些细节差异
2009-06-10 17:35:00
在IE中使用高级CSS3选择器
2010-01-22 15:20:00
使用python BeautifulSoup库抓取58手机维修信息
2022-08-10 01:55:20
flask循环导入的问题解决
2023-10-01 10:28:52
js与jquery获取父元素,删除子元素的两种不同方法
2023-10-07 04:08:00
Django如何使用redis作为缓存
2022-12-30 19:19:20
Python高级特性之闭包与装饰器实例详解
2021-09-19 03:17:25
![](https://img.aspxhome.com/file/2023/3/65473_0s.png)
Script 元素 type 属性的妙用
2011-03-07 16:13:00
python编程-将Python程序转化为可执行程序[整理]
2022-10-28 03:48:43
详解pycharm配置python解释器的问题
2022-10-14 13:22:08
![](https://img.aspxhome.com/file/2023/7/107997_0s.png)