# -*- 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的更多相关文章

随机推荐

  1. Swing学习1——总体概述

    以下来自于JDK1.6 一.Swing学习我划分为两个方面: 一方面Swing的界面设计部分,包括相关组件类的继承关系,组件的功能用途,布局管理: 1.首先继承关系上自上而下为 java.lang.O ...

  2. mac安装破解的Navicat

    原文:https://www.jianshu.com/p/f42785e55b6b 原始文档没操作成功,折腾了一下午,后来在如下地址看的简洁版的,突然发现一句重要的话,豁然开朗. 原文链接:https ...

  3. readfile() file_get_content f

    php.ini:memory_limit memory_limit是设置内存限制的,如果使用readfile()读取文件就会和这个有关, 调用readfile()函数将打开这个文件,并且将文件内容输出 ...

  4. Galera Cluster——一种新型的高一致性MySQL集群架构

    原文链接:https://www.sohu.com/a/147032902_505779,最近被分配定位mysql的问题,学习下. 1. 何谓Galera Cluster 何谓Galera Clust ...

  5. DNS学习笔记

    一.域名的层级结构 主机名.次级域名.顶级域名.根域名 # 即 host.sld.tld.root 比如,域名math.stackexchange.com显示为math.stackexchange.c ...

  6. SQL 姓名,联系方式-脱敏

    SELECT ORDER_PROJECT.project_type AS attribute, ORDER_PROJECT.order_num, ,), "*") AS pv, C ...

  7. python基础---面向对象的概念

    1.面向对象 什么是面向过程?? 将一个复杂单位问题一步步小化,最终只需要完成一个人小的功能就可以了 比如:将大象放进冰箱要几步? 一共三步:打开冰箱,把大象塞进入,关门就可以了 优点:复杂度降低了, ...

  8. 阿里云上rabbitmq安装

    环境:CentOS Linux release 7.4.1708 (Core)   rabbitmq-server-3.7.13-1.el7.noarch.rpm  阿里云服务器 1.安装elang ...

  9. mac安装brew简单方法

    安装方法:命令行输入 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/ma ...

  10. Python学习之路基础篇--03Python基础+万恶的运算符

    1 格式化输出% 用%s(用来表示str数据类型) 和 %d (用来表示int数据类型),如果要用%号的话,就要使用两个%%,这样即可输出. 2 初识编码 电脑的传输数据,储存都是用的 0101010 ...