Authored by wuxiao

write_performance()

... ... @@ -54,6 +54,8 @@ php = "/Data/local/php/bin/php"
--日志文件
--log_file = nil
log_file = '/Data/code/yoho-phplog/access.log'
--性能调试文件根目录
performance_dir = '/tmp/performance'
--[[
通道配置
... ...
... ... @@ -70,10 +70,14 @@ while True:
db = 'performance'
measurement = Config.performance_channel+time.strftime('_%Y%m%d')
pre = data['data']['creator'] if 'creator' in data['data'].keys() else ''
write_performance(body,pre)
'''
json_body = dict(data['data'],**data['tags'])
if 'context' in json_body.keys():
json_body['context'] = json.loads(json_body['context'])
mongodb_insert(db,measurement,json_body)
'''
else:
'''
... ...
... ... @@ -22,11 +22,23 @@ lua = LuaRuntime(unpack_returned_tuples=True)
lua.execute(open(__DIR__+'/Config.lua').read(-1))
Config = lua.globals()
#写日志
def write_log(msg):
fp = open(Config.log_file,'a')
fp.write(msg)
fp.close()
#写性能调试日志
def write_performance(msg, pre = None):
if not os.path.isdir(Config.performance_dir):
os.makedirs(Config.performance_dir,0777)
file = time.strftime('%Y%m%d',time.localtime(time.time()))
if pre:
file = pre+'_'+file
fp = open(Config.performance_dir+'/'+file,'a')
fp.write(msg)
fp.close()
#连接rabbitmq
def rabbitmq_connect():
credentials = pika.PlainCredentials(Config.rabbitmq_user, Config.rabbitmq_pass)
... ... @@ -48,7 +60,7 @@ def mongodb_connect():
return _mongodb
#influxdb选择库,写入
def influxdb_insert(db,json_body):
def influxdb_insert(db, json_body):
try:
influxdb.switch_database(db)
influxdb.write_points(json_body)
... ... @@ -58,7 +70,7 @@ def influxdb_insert(db,json_body):
influxdb.write_points(json_body)
#mongodb选择库和集合,写入
def mongodb_insert(db,measurement,json_body):
def mongodb_insert(db, measurement, json_body):
try:
mongodb[db][measurement].insert_one(json_body)
except Exception as err:
... ...