dm_analysis
# -*- coding: utf-8-*- #
import sys
import os
import io
import json
reload(sys)
sys.setdefaultencoding('utf-8') def unicode_convert(input):
if isinstance(input, dict):
return {unicode_convert(key): unicode_convert(value) for key, value in input.iteritems()}
elif isinstance(input, list):
return [unicode_convert(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input filter=["Dm.log.wf"] #设置过滤后的文件类型 当然可以设置多个类型 def all_path(dirname): result = []#所有的文件 for maindir, subdir, file_name_list in os.walk(dirname): # print("1:",maindir) #当前主目录
# print("2:",subdir) #当前主目录下的所有目录
# print("3:",file_name_list) #当前主目录下的所有文件 for filename in file_name_list:
apath = os.path.join(maindir, filename)#合并成一个完整路径
ext = os.path.splitext(apath)[0] # 获取文件后缀 [0]获取的是除了文件名以外的内容
ext = ext.split('/')
ext = ext[5] if ext in filter:
result.append(apath) return result if __name__ == "__main__":
print sys.getdefaultencoding()
result = all_path("/home/work/yangq/dm_analysis")
for file_log in result:
print "*****************************************"
print file_log
f = open(file_log, "r")
f_new = open("/home/work/yangq/dm_analysis/result", "a+")
f_new_error = open("/home/work/yangq/dm_analysis/error", "a+")
haproxy_list = f.readlines()
dm_statistics="dm_statistics"
f_new.write(file_log + "\n")
f_new.write("###################################################################" + "\n")
f_new_error.write(file_log + "\n")
f_new_error.write("###################################################################" + "\n")
for line in haproxy_list:
if dm_statistics in line:
#print sys._getframe().f_lineno
#print line
strlist = line.split('dm_statistics: ')
sss = strlist[1]
#test2 = unicode_convert(json.loads(sss))
try:
test2 = json.loads(sss.decode('utf-8'))
except UnicodeDecodeError as w:
f_new_error.write(line)
f_new_error.write("有特殊自符" + "\n")
continue
except ValueError:
f_new_error.write(line)
f_new_error.write("ValueError" + "\n")
continue f_new.write("query:" + str(test2['req']['query']) + " ")
if 'recommend_word' in test2['latency']:
f_new.write("recommend_word:" + str(test2['latency']['recommend_word']) + " ")
if 'um' in test2['latency']:
f_new.write("um:" + str(test2['latency']['um']) + " ")
if 'se' in test2['latency']:
f_new.write("se:" + str(test2['latency']['se']) + " ")
if 'ia' in test2['latency']:
f_new.write("ia:" + str(test2['latency']['ia']) + " ")
if 'ir' in test2['latency']:
f_new.write("ir:" + str(test2['latency']['ir']) + " ")
if 'dm' in test2['latency']:
f_new.write("dm:" + str(test2['latency']['dm']) + " ")
if 'chat' in test2['latency']:
f_new.write("chat:" + str(test2['latency']['chat']) + " ")
if 'ACTION_CALCULATE.calc' in test2['detail_latency']:
f_new.write("ACTION_CALCULATE.calc: " + str(test2['detail_latency']['nli']['ACTION_CALCULATE.calc']) + "\n")
f_new.write("\n")
#try:
# f_new.write("query:" + str(test2['req']['query']) + " " + \
# "recommend_word:" + str(test2['latency']['recommend_word']) + \
# " " "um:" + str(test2['latency']['um']) + " " + \
# "se:" + str(test2['latency']['se']) + " " + \
# "ia:" + str(test2['latency']['ia']) + " " + \
# "ir:" + str(test2['latency']['ir']) + " " + \
# "dm:" + str(test2['latency']['dm']) + " " + \
# "chat:" + str(test2['latency']['chat']) + " " + \
# "ACTION_CALCULATE.calc: " + str(test2['detail_latency']['nli']['ACTION_CALCULATE.calc']) + "\n")
#except KeyError as e:
# f_new_error.write(line)
# f_new_error.write("losing key:" + str(e) + "\n")
# continue
f.close()
f_new.close()
f_new_error.close()
pass
dm_analysis的更多相关文章
随机推荐
- elasticsearch 的内存JVM和GC相关问题
JVM对ElasticSearch集群的稳定性有很大的影响. Java是一个垃圾收集语言,意思是这个程序不会手动管理分配和释放内存.程序员只需要编写代码,jvm管理根据需要管理分配内存的处理,然后在不 ...
- 【4】数独(Sudoku Killer)(深度优先遍历)
问题描述:给你多个数独题目,让你输出答案 思路:递归确定每一个‘?’的位置的值,直到所有‘?’都被确定.先将原字符数组转换为整型数组,‘?’由数字0代替,然后每一次层递归找到第一个0的位置,如果找到了 ...
- Windows 7 改造
1.界面改造 1.1 软件 Wallpaper Engine 收费(18¥) 动态桌面,通过steam安装,使用steam中的创意工坊下载内容 最好使用集成显卡运行,单显卡方案容易桌面异常刷新 Clo ...
- 类 __getitem__ __getattr__ __call__
__getitem__ 实例虽然能作用于for循环,看起来和list有点像,但是,把它当成list来使用还是不行,要表现得像list那样按照下标取出元素,需要实现__getitem__()方法 __g ...
- socket网络编程-----I/O复用之poll函数
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/soc ...
- C++编程题#1:含k个3的数
描述 输入二个正整数m 和 k,其中1 < m < 100000,1 < k <5 ,判断m 能否被19整除,且恰好含有k个3,如果满足条件,则输出YES,否则,输出NO. 例 ...
- who are we?
human been like animals,we work for our master. when we dreaming,we drive the machine run.
- Go Lang
IDE: https://www.jetbrains.com/products.html?fromMenu#type=ide Study: http://www.runoob.com/go/go-en ...
- Python学习第六课
Python学习第六课 课前回顾 列表 创建 通过 [] :写在[]里,元素之间用逗号隔开 对应操作: 查 增 append insert 改(重新赋值) 删除(remove del pop(删除后会 ...
- Spring框架:@ResponseBody 中文乱码----------我的主题站内单点登录
问题背景 本文并不是介绍@ResponseBody注解,也不是中文乱码问题的大汇总笔记,这些网上都有很多内容了.这边仅对几年前,一个卡壳了挺久时间的问题的解决过程做一个记录,以警惕自己,达到自醒得目的 ...