python 日志分析 -redis
#!/bin/python#encoding:utf8import time,re,osfile = open('/data/apps/logs/p4-controller/controller.log.%s' % (time.strftime("%Y-%m-%d", time.localtime())))def Analysis(): sum = 0 times.
#!/bin/python
#encoding:utf8
import time,re,os
file = open('/data/apps/logs/p4-controller/controller.log.%s' % (time.strftime("%Y-%m-%d", time.localtime())))
def Analysis():
sum = 0
times = 0
while True:
where = file.tell()
line = file.readline()
if not line:
time.sleep(1)
file.seek(where)
else:
matchObj1 = re.search( r"消费", line, re.M|re.I)
matchObj2 = re.search( r"成功", line, re.M|re.I)
if matchObj1 and matchObj2:
Data1 = line.split()[5]
if Data1 in "--------":
continue
else:
Data2 = float(Data1)
sum += Data2
times +=1
os.system("redis-cli -h 192.168.52.61 -p 6379 -a admin1234 hmset 192.168.182.11 total %s count %s" % (sum,times))
print "%s \n %s %f 到现在,成功交易总额: %f,成功笔数%s" % (line,Data1,Data2,sum,times)
Analysis()
shell
#!/bin/bash
filter=`date "+%Y-%m-%d %H:"`
number=`date +%H |awk '{print int($0)}'`
totals=$(cat /data/apps/logs/p4-controller/controller.log.`date +%Y-%m-%d` | grep 消费 | grep "成功" | grep "$filter" | awk '{sum+=$6} END {printf "%02d\n", sum}')
sums=$(cat /data/apps/logs/p4-controller/controller.log.`date +%Y-%m-%d` | grep 消费 | grep "成功" | grep -c "$filter")
total_key=${number}_total
count_key=${number}_count
redis-cli -h 192.168.52.61 -p 6379 -a xxxxx hmset h192.168.18.11 $total_key $totals $count_key $sums
#echo $number
#echo $totals
#echo $sums
更多推荐
所有评论(0)