Merge remote-tracking branch 'origin/master'

This commit is contained in:
2024-08-15 17:39:40 +08:00
3 changed files with 45 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
import logging
from goojia_utils import ElasticSearchClient, dingutils
log = logging.getLogger(__name__)
es206_client = ElasticSearchClient(host='192.168.0.206')
from datetime import datetime, timedelta
# 获取当前时间
now = datetime.now()
# 计算当前时间以前2分钟的时间
two_minutes_ago = now - timedelta(minutes=2)
# 将时间转换为时间戳(以毫秒为单位)
# 注意:timestamp() 方法返回的是秒,所以我们需要乘以1000来得到毫秒
timestamp_milliseconds = int(two_minutes_ago.timestamp() * 1000)
count = 0
for doc in es206_client.scan_by_sql("select code from fangjia_log where code >= 500 and creationDate > " + str(timestamp_milliseconds)):
count += 1
if count > 2:
print('【OPEN日志监控】最近两分钟超过两条错误,请检查日志!')
dingutils.send_text('【OPEN日志监控】最近两分钟超过两条错误,请检查OPEN日志!', 'ab4231000995a8c90d8d1e91dfd6930c3896dd1c3bbf1f0af19e19004cf6c98c')
break
+19
View File
@@ -0,0 +1,19 @@
from datetime import timedelta
from airflow.operators.bash import BashOperator
import pendulum
from airflow import DAG
with DAG(
dag_id="fangjia_log_dag",
# 每2分钟监控
schedule_interval=timedelta(minutes=2),
start_date=pendulum.datetime(2024, 8, 14, tz="Asia/Shanghai"),
catchup=True,
description="OPEN日志监控"
) as dag:
t1 = BashOperator(
task_id='fangjia_log',
bash_command='python /opt/airflow/dags/repo/dags/business/business/fangjia_log.py',
)
t1
+2 -2
View File
@@ -18,8 +18,8 @@ log.info(f"系统当前时间 : {now}")
def proc():
# 区域维度,统计2个月内样本数据量
es206_client = ElasticSearchClient(host='192.168.0.206')
sql = 'select city,region,p_date,cat,root from seawater where cat = \'sell\' and p_date >=' + str(
last_day) + ' and p_date<' + str(now_day)
sql = 'select city,region,p_date,cat,root from seawater where cat = \'sell\' and p_date >=' + str(last_day) + ' and p_date<' + str(now_day)
log.info(f"城市区域维度 sql : {sql}")
df = es206_client.scan_by_sql_to_data_frame(sql)