...
|
...
|
@@ -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:
|
...
|
...
|
|