标签:
统计下面字段中event.tags的值(红色内容)
{ "url": "http:\/\/icache.sinaimg.cn\/006gPXD2gw1exo8u4i7mkj30f00qotgg.lar", "size": "10.79", "id": "295785", "action": "PUSH", "toidc": "bj", "type": "ACCESS", "level": "INFO", "fromidc": "GZ", "service": "replicate", "event.tags": [ "A" ], "@timestamp": "2015-11-04T00:18:52,544+0800" }
简单脚本:
#!/usr/bin/env python import commands path = str(raw_input(‘Log Path: ‘)) f1 = open(path, ‘r‘) f2 = open(‘tag.txt‘,‘rw+‘) for line in f1.readlines(): l = eval(line) try: tag = str(l[‘event.tags‘]).split(‘\‘‘)[1]+‘\n‘ f2.writelines(tag) except: pass print commands.getoutput(‘cat tag.txt | sort | uniq -c‘) f1.close() f2.close()
返回结果:
[root@10.13.113.109 test]# python event.py path:test-normalize-1103.log 386432 A 32202 B 32204 D1 3 D2
Rsyslog mmnormalize event.tags字段统计
标签:
原文地址:http://my.oschina.net/moonly/blog/525699