1. 程式人生 > 其它 >日誌監控告警-HQL-python指令碼

日誌監控告警-HQL-python指令碼

#!/usr/bin/env python3
from HiveTask import HiveTask
import os
import sys
sys.path.append(os.getenv('HIVE_TASK'))

ht = HiveTask()

data_day_str = sys.argv[1]
# data_day_str = '2021-11-15'
print('============================================')
print('data_day_str:', data_day_str)
print('============================================')

sql="""
use app;
set hive.input.format = org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
set hive.hadoop.supports.splittable.combineinputformat = true;
set mapreduce.input.fileinputformat.split.maxsize = 256000000;
set mapreduce.input.fileinputformat.split.minsize.per.node=256000000;
set mapreduce.input.fileinputformat.split.minsize.per.rack=256000000;
set hive.exec.parallel = true;
set hive.exec.parallel.thread.number = 8;
set hive.auto.convert.join = true;
set hive.mapjoin.smalltable.filesize=200000000;
set hive.auto.convert.join.noconditionaltask.size=100000000;

insert into app.app_cco_log_montior_hive_tmp_i_s_d partition ( dt= '0-""" + data_day_str + """' )
SELECT
app.appid as app_id,
log.h_app_name AS app_name,
app.department AS department,
concat_ws(',',collect_set(b.usererp)) as owner_erp,
'APP' as log_type,
COUNT(log.h_app_name) AS log_num
FROM
app.security_log_to_hive_tmp log
LEFT JOIN fdm.fdm_db_ocean_appasset_chain app
ON
log.h_app_name = app.appname
AND app.dp = 'ACTIVE'
AND app.updatedat >= sysdate( - 2)
LEFT JOIN fdm.fdm_db_ocean_appmemberrel_chain b
ON
app.id = b.appassetid
AND b.dp = 'ACTIVE'
AND b.userrole = 1
AND b.updatedat >= sysdate( - 2)

WHERE log.dt='0-""" + data_day_str + """'
and
app.appid is not null
GROUP BY
log.h_app_name,
app.department,
log.dt,
app.appid
"""
ht.exec_sql(schema_name = 'app', table_name = 'app_cco_log_montior_hive_tmp_i_s_d', sql = sql, merge_flag = True, merge_part_dir =['dt=0-'+ data_day_str], merge_type='mr')