diff --git a/linkis-dist/bin/install.sh b/linkis-dist/bin/install.sh
index d7e52128ba..d6e50221d5 100644
--- a/linkis-dist/bin/install.sh
+++ b/linkis-dist/bin/install.sh
@@ -127,6 +127,7 @@ RANDOM_LINKISCLI_TOKEN="LINKISCLI-`cat /proc/sys/kernel/random/uuid | awk -F- '{
if [ $DEBUG_MODE != "true" ];then
sed -i ${txt} "s#BML-AUTH#$RANDOM_BML_TOKEN#g" $LINKIS_HOME/conf/linkis-cli/linkis-cli.properties
sed -i ${txt} "s#BML-AUTH#$RANDOM_BML_TOKEN#g" $common_conf
+ sed -i ${txt} "s#BML-AUTH#$RANDOM_BML_TOKEN#g" $LINKIS_HOME/admin/configuration_helper.sh
sed -i ${txt} "s#LINKIS_CLI_TEST#$RANDOM_LINKIS_CLI_TEST_TOKEN#g" $common_conf
sed -i ${txt} "s#WS-AUTH#$RANDOM_WS_TOKEN#g" $common_conf
sed -i ${txt} "s#DSM-AUTH#$RANDOM_DSM_TOKEN#g" $common_conf
@@ -532,6 +533,7 @@ sed -i ${txt} "s#spring.eureka.instance.metadata-map.linkis.conf.version.*#spri
if [ "$RESULT_SET_ROOT_PATH" != "" ]
then
sed -i ${txt} "s#wds.linkis.resultSet.store.path.*#wds.linkis.resultSet.store.path=$RESULT_SET_ROOT_PATH#g" $entrance_conf
+ sed -i ${txt} "s#resultSetRootDir=.*#resultSetRootDir=$RESULT_SET_ROOT_PATH#g" $LINKIS_HOME/admin/linkis_task_res_log_clear.sh
fi
publicservice_conf=$LINKIS_HOME/conf/linkis-ps-publicservice.properties
diff --git a/linkis-dist/package/admin/clear_ec_record.sh b/linkis-dist/package/admin/clear_ec_record.sh
new file mode 100644
index 0000000000..5cd1525263
--- /dev/null
+++ b/linkis-dist/package/admin/clear_ec_record.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# description: clear linkis_ps_job_history_group_history 10 days ago record
+#
+if [ -f ${LINKIS_CONF_DIR}/db.sh ]
+then
+ export LINKIS_DB_CONFIG_PATH=${LINKIS_CONF_DIR}/db.sh
+else
+ if [ -f ${LINKIS_HOME}/conf/db.sh ]
+ then
+ export LINKIS_DB_CONFIG_PATH=${LINKIS_HOME}/conf/db.sh
+ else
+ echo "can not find db.sh"
+ exit
+ fi
+fi
+source ${LINKIS_DB_CONFIG_PATH}
+
+delete_day=`date -d "-10 days" "+%Y-%m-%d"`
+delte_time="$delete_day 00:00:00"
+echo "start to delete linkis_cg_ec_resource_info_record before $delte_time"
+parm="release_time <=\"$delte_time\" "
+
+count=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT count(1) FROM linkis_cg_ec_resource_info_record where $parm limit 1"`
+maxid=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT MAX(id) FROM linkis_cg_ec_resource_info_record where $parm limit 1"`
+echo "will delete count:$count"
+echo "maxid:$maxid"
+
+while [ $count -gt 1 ];do
+ mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "DELETE FROM linkis_cg_ec_resource_info_record where id <= $maxid limit 5000;"
+ count=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT count(1) FROM linkis_cg_ec_resource_info_record where $parm limit 1"`
+ echo "count change : $count"
+ sleep 1s
+done
+
+echo "clear_ec_record.sh over"
\ No newline at end of file
diff --git a/linkis-dist/package/admin/clear_history_task.sh b/linkis-dist/package/admin/clear_history_task.sh
new file mode 100644
index 0000000000..75c49cb715
--- /dev/null
+++ b/linkis-dist/package/admin/clear_history_task.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#
+# description: clear linkis_ps_job_history_group_history 3 month record
+#
+if [ -f ${LINKIS_CONF_DIR}/db.sh ]
+then
+ export LINKIS_DB_CONFIG_PATH=${LINKIS_CONF_DIR}/db.sh
+else
+ if [ -f ${LINKIS_HOME}/conf/db.sh ]
+ then
+ export LINKIS_DB_CONFIG_PATH=${LINKIS_HOME}/conf/db.sh
+ else
+ echo "can not find db.sh"
+ exit
+ fi
+fi
+source ${LINKIS_DB_CONFIG_PATH}
+
+delete_day=`date -d "-90 days" "+%Y-%m-%d"`
+delte_time="$delete_day 00:00:00"
+echo "start to delete linkis_ps_job_history_group_history before $delte_time"
+parm="created_time <=\"$delte_time\" "
+
+count=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT count(1) FROM linkis_ps_job_history_group_history where $parm limit 1 "`
+maxid=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT MAX(id) FROM linkis_ps_job_history_group_history where $parm limit 1 "`
+echo "will delete count:$count"
+echo "maxid:$maxid"
+
+while [ $count -gt 1 ];do
+ mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "DELETE FROM linkis_ps_job_history_group_history where id <= $maxid limit 5000;"
+ count=`mysql -h$MYSQL_HOST -P$MYSQL_PORT -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB -ss -e "SELECT count(1) FROM linkis_ps_job_history_group_history where $parm limit 1 "`
+ echo "count change : $count"
+ sleep 1s
+done
\ No newline at end of file
diff --git a/linkis-dist/package/admin/configuration_helper.sh b/linkis-dist/package/admin/configuration_helper.sh
new file mode 100644
index 0000000000..8c918dfe61
--- /dev/null
+++ b/linkis-dist/package/admin/configuration_helper.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+cd `dirname $0`
+cd ..
+INSTALL_HOME=`pwd`
+
+
+function print_usage(){
+ echo "Usage: configuration_helper.sh [add | get | delete] [engineType] [version] [creator] [configKey] [configValue option]"
+ echo "get eq: sh configuration_helper.sh get spark 2.4.3 test wds.linkis.rm.instance hadoop"
+ echo "delete eq: sh configuration_helper.sh delete spark 2.4.3 test wds.linkis.rm.instance hadoop"
+ echo "add eq: sh configuration_helper.sh add spark 2.4.3 test wds.linkis.rm.instance hadoop 6"
+ echo "add eq: sh configuration_helper.sh add spark 2.4.3 test wds.linkis.rm.instance hadoop 6 force"
+ echo "add tips: add with force will ignore check error"
+ echo "Most commands print help when invoked w/o parameters."
+}
+
+if [ $# -lt 6 ]; then
+ print_usage
+ exit 2
+fi
+
+# set LINKIS_HOME
+if [ "$LINKIS_HOME" = "" ]; then
+ export LINKIS_HOME=$INSTALL_HOME
+fi
+
+# set LINKIS_CONF_DIR
+if [ "$LINKIS_CONF_DIR" = "" ]; then
+ export LINKIS_CONF_DIR=$LINKIS_HOME/conf
+fi
+linkisMainConf=$LINKIS_CONF_DIR/linkis.properties
+gatewayUrl=$(grep wds.linkis.gateway.url $linkisMainConf | cut -d"=" -f2)
+echo "gatewayUrl: $gatewayUrl"
+engineType=$2
+version=$3
+creator=$4
+configKey=$5
+user=$6
+configValue=$7
+COMMAND=$1
+if [ "$8" = "force" ]; then
+ force=true
+fi
+
+get()
+{
+ requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue?creator=$creator&engineType=$engineType&version=$version&configKey=$configKey"
+ curl --location --request GET $requestUrl -H "Token-Code:BML-AUTH" -H "Token-User:$user"
+}
+
+delete()
+{
+ requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue"
+ requestBody="{\"engineType\":\"$engineType\",\"version\":\"$version\",\"creator\":\"$creator\",\"configKey\":\"$configKey\"}"
+ curl -i -X DELETE $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:BML-AUTH" -H "Token-User:$user" -d "$requestBody"
+}
+
+add()
+{
+ requestUrl="$gatewayUrl/api/rest_j/v1/configuration/keyvalue"
+ requestBody="{\"engineType\":\"$engineType\",\"version\":\"$version\",\"creator\":\"$creator\",\"configKey\":\"$configKey\",\"configValue\":\"$configValue\",\"force\":\"$force\",\"user\":\"$user\"}"
+ curl -i -X POST $requestUrl -H "Accept: application/json" -H "Content-Type: application/json" -H "Token-Code:BML-AUTH" -H "Token-User:hadoop" -d "$requestBody"
+}
+
+case $COMMAND in
+ add|get|delete)
+ $COMMAND
+ ;;
+ *)
+ print_usage
+ exit 2
+ ;;
+esac
diff --git a/linkis-dist/package/admin/linkis_task_res_log_clear.sh b/linkis-dist/package/admin/linkis_task_res_log_clear.sh
new file mode 100644
index 0000000000..4272633e23
--- /dev/null
+++ b/linkis-dist/package/admin/linkis_task_res_log_clear.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#!/bin/bash
+expiredDays=365
+resultSetRootDir=/tmp/linkis
+logRootDir=/tmp/linkis
+userResultSetDir=$(hdfs dfs -ls $resultSetRootDir | awk '{print $8}')
+realLogRootDir=$logRootDir/log
+echo userResultSetDirs: $userResultSetDir
+echo realLogRootDir: $realLogRootDir
+
+if [ -z $LINKIS_LOG_DIR ];then
+ expiredFileRecordDir=${LINKIS_HOME}/expiredFileRecord
+else
+ expiredFileRecordDir=$LINKIS_LOG_DIR/expiredFileRecord
+fi
+
+function createExpiredFileRecoredDir(){
+ if [ ! -d $expiredFileRecordDir ];then
+ mkdir -p $expiredFileRecordDir
+ fi
+}
+
+createExpiredFileRecoredDir
+expireDate=$(date -d -${expiredDays}day +%Y-%m-%d)
+expireResultSetFile=$expiredFileRecordDir/linkis_expire_resultset_dir_${expireDate}.txt
+expireLogFile=$expiredFileRecordDir/linkis_expire_log_dir_${expireDate}.txt
+
+hdfs dfs -ls $realLogRootDir | awk '$8 ~ /.*linkis\/log\/[0-9|\-|\_]*/ {cmd = "date -d -12month +%Y-%m-%d";cmd | getline oneMonthAgo;if($6 < oneMonthAgo) print $8}' >> $expireLogFile
+
+for i in $userResultSetDir
+do
+ hdfs dfs -ls $i/linkis | awk '$8 ~ /.*linkis\/[0-9\-]{10}/ {cmd = "date -d -12month +%Y-%m-%d";cmd | getline oneMonthAgo;if($6 < oneMonthAgo) print $8}' >> $expireResultSetFile
+done
+
+cat $expireLogFile | xargs -n 1000 hdfs dfs -rm -r -f
+
+cat $expireResultSetFile | xargs -n 1000 hdfs dfs -rm -r -f
+
+
diff --git a/linkis-dist/package/conf/linkis-et-monitor-file.properties b/linkis-dist/package/conf/linkis-et-monitor-file.properties
new file mode 100644
index 0000000000..22a45841d8
--- /dev/null
+++ b/linkis-dist/package/conf/linkis-et-monitor-file.properties
@@ -0,0 +1,143 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+jobhistory.errorcode.01002={"alert_title":"Linkis Service load is too high, please contact Linkis owner","alert_info":"Linkis Linkis Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01003={"alert_title":"Linkis Service load is too high, please contact Linkis owner","alert_info":"Linkis Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01101={"alert_title":"Linkis Service load is too high, please contact Linkis owner","alert_info":" Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01102={"alert_title":"Linkis ECM memory Service load is too high, please contact Linkis owner","alert_info":" Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01103={"alert_title":"Linkis ECM CPU Service load is too high, please contact Linkis owner","alert_info":" Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01104={"alert_title":"Linkis ECM instances Service load is too high, please contact Linkis owner","alert_info":" Service load is too high, please contact Linkis owner","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.errorcode.01105={"alert_title":"Linkis Memory Service load is too high, please contact Linkis owner","alert_info":"The machine has insufficient memory. Please contact the administrator to expand the memory.","alert_way":"1,2,3","alert_reciver":"hadoop","alert_level":"2","alert_obj":"linkis-alert-obj","can_recover":"0"}
+jobhistory.unfinished.time.exceed.sec.43200={"alert_title":"Linkis task execute timeout","alert_info":"Linkis task execute timeout 12h","alert_way":"1,2,3","alert_reciver":"","alert_level":"4","alert_obj":"Linkis","can_recover":"0"}
+
+ecm.resource.monitor.im.12003=\
+ {"alert_title":"Linkis Monitor Resource Alert",\
+ "alert_info":" $instance ECM Memory/cpu insufficient resource < 0.2 please contact Linkis owner: $name",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12004=\
+ {"alert_title":"Linkis Monitor Resource Alert",\
+ "alert_info":" $instance ECM Memory/cpu insufficient resource < 0.2 please contact Linkis owner: $name",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"2",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12005=\
+ {"alert_title":"Linkis entrance user running task monitor",\
+ "alert_info":"User $username runninng task at linkis ( $url ) > $runningtask ,please attention",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12006=\
+ {"alert_title":"Linkis entrance user queued task monitor",\
+ "alert_info":"User $username queued task at linkis ( $url ) > $queuedtask ,please attention",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12007=\
+ {"alert_title":"Linkis entrance user total task monitor",\
+ "alert_info":"User $username queued task at linkis ( $url ) > $tasktotal ,please attention",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12008=\
+ {"alert_title":"Linkis entrance all running task monitor",\
+ "alert_info":"linkis ( $url ) running task > $taskminor,please attention",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+ecm.resource.monitor.im.12009=\
+ {"alert_title":"Linkis entrance all running task monitor",\
+ "alert_info":"linkis ( $url ) all task > $taskmajor,please attention",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"2",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+
+
+
+user.mode.monitor.im.12011=\
+ {"alert_title":"User mode execution timeout alarm",\
+ "alert_info":"User mode execution timeout alarm Linkis url: $url engineType:$engineType Task ID: $jobId please attention $name",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"alexyang,hadoop",\
+ "alert_level":"2",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+user.mode.monitor.im.12012=\
+ {"alert_title":"User mode execution failure alarm",\
+ "alert_info":"User mode execution failure alarm Linkis url: $url Engine: $engineType TaskID: $jobId ER=rrorCode?$errorCode errorMsg: $errorMsg please attention $name",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"alexyang,hadoop",\
+ "alert_level":"2",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+
+user.mode.monitor.im.12017=\
+ {"alert_title":"@alert_title",\
+ "alert_info":"task execute failed, reason $msg",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"@alert_reciver",\
+ "alert_level":"@alert_level",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+user.mode.monitor.im.12018=\
+ {"alert_title":"@alert_title",\
+ "alert_info":"task execute time out $timeout",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"@alert_reciver",\
+ "alert_level":"@alert_level",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+
+thread.monitor.timeout.im.12014=\
+ {"alert_title":" Linkis Shell Timeout Alert ",\
+ "alert_info":"Monitor Shell execute time out $shellName",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"hadoop",\
+ "alert_level":"3",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+jobhistory.result.monitor.im.12015=\
+ {"alert_title":"Linkis \u4EFB\u52A1\u72B6\u6001\u901A\u77E5",\
+ "alert_info":"Task ID:$id final status: $status",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"",\
+ "alert_level":"4",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+jobhistory.result.monitor.im.12016=\
+ {"alert_title":"@alert_title",\
+ "alert_info":"[Alarm time]$date\n[Subsystem]$sysid\n[Alarm IP]$ip\n[Alarm object]$object\n[Alarm information]$detail",\
+ "alert_way":"1,2,3",\
+ "alert_reciver":"@alert_reciver",\
+ "alert_level":"@alert_level",\
+ "alert_obj":"linkis_alert",\
+ "can_recover":"0"}
+
+
diff --git a/linkis-dist/package/conf/linkis-et-monitor.properties b/linkis-dist/package/conf/linkis-et-monitor.properties
new file mode 100644
index 0000000000..6d802941ca
--- /dev/null
+++ b/linkis-dist/package/conf/linkis-et-monitor.properties
@@ -0,0 +1,84 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+wds.linkis.server.mybatis.typeAliasesPackage=org.apache.linkis.monitor.scan.app.instance.entity,org.apache.linkis.monitor.scan.app.jobhistory.entity,org.apache.linkis.bml.cleaner.dao
+wds.linkis.server.mybatis.BasePackage=org.apache.linkis.monitor.scan.app.instance.dao,org.apache.linkis.monitor.scan.app.jobhistory.dao,org.apache.linkis.bml.cleaner.dao
+
+
+# alert server url
+linkis.alert.url=http://127.0.0.1/
+
+# alert receiver
+linkis.alert.receiver.default=hadoop
+
+# monitor ecm resource
+linkis.monitor.ecm.resource.cron=0 0/10 * * * ?
+
+# Resource remaining ratio
+linkis.monitor.ecmResourceTask.major=0.005
+linkis.monitor.ecmResourceTask.minor=0.01
+
+# entrance task metrics cron
+linkis.monitor.entrance.task.cron=0 0/10 * * * ?
+
+# Timeout task cron
+linkis.monitor.jobHistory.timeout.cron=0 0/20 * * * ?
+
+# time out interval 24h
+linkis.monitor.scanner.timeout.interval.seconds=86400
+
+
+# Finished task cron
+linkis.monitor.jobHistory.finished.cron=0 0/20 * * * ?
+
+# linkis user mode cron
+linkis.monitor.user.mode.cron=0 0/20 * * * ?
+
+# user mode for engine
+linkis.monitor.user.enginelist=[{"engineType":"hive-2.3.3","code":"show tables","runType":"hql","executeUser":"hadoop"},\
+ {"engineType":"spark-2.4.3","code":"show tables","runType":"sql","executeUser":"hadoop"},\
+ {"engineType":"shell-1","code":"pwd","runType":"sh","executeUser":"hadoop"}]
+
+linkis.monitor.user.mode.timeOut=300
+
+
+# bml clear cron
+linkis.monitor.bml.clear.history.version.cron=0 0 12 * * ?
+# bml max version
+linkis.bml.cleaner.version.max.num=50
+# keep verssion
+linkis.bml.cleaner.version.keep.num=20
+# clear max interval
+linkis.bml.cleaner.previous.interval.days=30
+# once scan limit
+linkis.bml.cleaner.once.limit.num=100
+
+# clear db ec record cron
+linkis.monitor.clear.ecRecord.cron=0 10 12 * * ?
+
+# clear task log cron
+linkis.monitor.clear.taskLog.cron=0 10 12 * * ?
+
+# clear db task history cron
+linkis.monitor.clear.history.task.cron=0 0 13 * * ?
+
+# poll size
+linkis.monitor.scheduled.pool.cores.num=20
+
+# shell time out conf minute
+linkis.monitor.shell.time.out.minute=60
+
+##Spring
+spring.server.port=9119
diff --git a/linkis-dist/package/sbin/ext/linkis-et-monitor b/linkis-dist/package/sbin/ext/linkis-et-monitor
new file mode 100644
index 0000000000..e0c78c487d
--- /dev/null
+++ b/linkis-dist/package/sbin/ext/linkis-et-monitor
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# description: monitor start cmd
+#
+
+
+source $LINKIS_CONF_DIR/linkis-env.sh
+export SERVER_SUFFIX="linkis-extensions/linkis-et-monitor"
+
+export SERVER_CLASS=org.apache.linkis.monitor.LinksMonitorApplication
+
+if test -z "$MONITOR_HEAP_SIZE"
+ then
+ if test -z "$SERVER_HEAP_SIZE"
+ then
+ export SERVER_HEAP_SIZE="512M"
+ fi
+else
+ export SERVER_HEAP_SIZE=$MONITOR_HEAP_SIZE
+fi
+
+#export DEBUG_PORT=
+
+export COMMON_START_BIN=$LINKIS_HOME/sbin/ext/linkis-common-start
+if [[ ! -f "${COMMON_START_BIN}" ]]; then
+ echo "The $COMMON_START_BIN does not exist!"
+ exit 1
+else
+ sh $COMMON_START_BIN
+fi
\ No newline at end of file
diff --git a/linkis-dist/src/main/assembly/distribution.xml b/linkis-dist/src/main/assembly/distribution.xml
index 57fd07d4d6..a506c99b18 100644
--- a/linkis-dist/src/main/assembly/distribution.xml
+++ b/linkis-dist/src/main/assembly/distribution.xml
@@ -261,6 +261,21 @@
+
+
+
+
+
+ ../linkis-extensions/linkis-et-monitor/target/out/lib
+
+
+ linkis-package/lib/linkis-extensions/linkis-et-monitor
+
+
+ **/*
+
+
+
diff --git a/linkis-extensions/linkis-et-monitor/pom.xml b/linkis-extensions/linkis-et-monitor/pom.xml
new file mode 100644
index 0000000000..0e5f44c076
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/pom.xml
@@ -0,0 +1,112 @@
+
+
+
+ 4.0.0
+
+ org.apache.linkis
+ linkis
+ ${revision}
+ ../../pom.xml
+
+
+ linkis-et-monitor
+
+
+
+ org.apache.linkis
+ linkis-httpclient
+ ${project.version}
+
+
+ org.apache.linkis
+ linkis-mybatis
+ ${project.version}
+
+
+
+ org.apache.linkis
+ linkis-storage
+ ${project.version}
+ provided
+
+
+ org.apache.linkis
+ linkis-rpc
+ ${project.version}
+ provided
+
+
+
+ org.apache.linkis
+ linkis-gateway-httpclient-support
+ ${project.version}
+
+
+
+ org.apache.linkis
+ linkis-common
+ ${project.version}
+
+
+
+ org.springframework
+ spring-test
+ test
+
+
+
+ junit
+ junit
+ test
+
+
+ org.apache.linkis
+ linkis-computation-client
+ ${project.version}
+
+
+
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ false
+
+ false
+ out
+ false
+ false
+
+ src/main/assembly/distribution.xml
+
+
+
+
+ make-assembly
+
+ single
+
+ package
+
+
+
+
+
+
+
diff --git a/linkis-extensions/linkis-et-monitor/src/main/assembly/distribution.xml b/linkis-extensions/linkis-et-monitor/src/main/assembly/distribution.xml
new file mode 100644
index 0000000000..e606ed79f2
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/assembly/distribution.xml
@@ -0,0 +1,296 @@
+
+
+
+
+ linkis-et-monitor
+
+ dir
+
+ false
+ linkis-et-monitor
+
+
+
+
+
+ lib
+ true
+ true
+ false
+ false
+ true
+
+
+ antlr:antlr:jar
+ aopalliance:aopalliance:jar
+ asm:asm:jar
+ cglib:cglib:jar
+ com.amazonaws:aws-java-sdk-autoscaling:jar
+ com.amazonaws:aws-java-sdk-core:jar
+ com.amazonaws:aws-java-sdk-ec2:jar
+ com.amazonaws:aws-java-sdk-route53:jar
+ com.amazonaws:aws-java-sdk-sts:jar
+ com.amazonaws:jmespath-java:jar
+ com.fasterxml.jackson.core:jackson-annotations:jar
+ com.fasterxml.jackson.core:jackson-core:jar
+ com.fasterxml.jackson.core:jackson-databind:jar
+ com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar
+ com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar
+ com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar
+ com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar
+ com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar
+ com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar
+ com.fasterxml.jackson.module:jackson-module-parameter-names:jar
+ com.fasterxml.jackson.module:jackson-module-paranamer:jar
+ com.fasterxml.jackson.module:jackson-module-scala_2.11:jar
+ com.github.andrewoma.dexx:dexx-collections:jar
+ com.github.vlsi.compactmap:compactmap:jar
+ com.google.code.findbugs:annotations:jar
+ com.google.code.findbugs:jsr305:jar
+ com.google.code.gson:gson:jar
+ com.google.guava:guava:jar
+ com.google.inject:guice:jar
+ com.google.protobuf:protobuf-java:jar
+ com.netflix.archaius:archaius-core:jar
+ com.netflix.eureka:eureka-client:jar
+ com.netflix.eureka:eureka-core:jar
+ com.netflix.hystrix:hystrix-core:jar
+ com.netflix.netflix-commons:netflix-commons-util:jar
+ com.netflix.netflix-commons:netflix-eventbus:jar
+ com.netflix.netflix-commons:netflix-infix:jar
+ com.netflix.netflix-commons:netflix-statistics:jar
+ com.netflix.ribbon:ribbon:jar
+ com.netflix.ribbon:ribbon-core:jar
+ com.netflix.ribbon:ribbon-eureka:jar
+ com.netflix.ribbon:ribbon-httpclient:jar
+ com.netflix.ribbon:ribbon-loadbalancer:jar
+ com.netflix.ribbon:ribbon-transport:jar
+ com.netflix.servo:servo-core:jar
+ com.ning:async-http-client:jar
+ com.sun.jersey.contribs:jersey-apache-client4:jar
+ com.sun.jersey:jersey-client:jar
+ com.sun.jersey:jersey-core:jar
+ com.sun.jersey:jersey-json:jar
+ com.sun.jersey:jersey-server:jar
+ com.sun.jersey:jersey-servlet:jar
+ com.sun.xml.bind:jaxb-impl:jar
+ com.thoughtworks.paranamer:paranamer:jar
+ com.thoughtworks.xstream:xstream:jar
+ org.apache.linkis:linkis-common:jar
+ org.apache.linkis:linkis-module:jar
+ commons-beanutils:commons-beanutils:jar
+ commons-beanutils:commons-beanutils-core:jar
+ commons-cli:commons-cli:jar
+ commons-codec:commons-codec:jar
+ commons-collections:commons-collections:jar
+ commons-configuration:commons-configuration:jar
+ commons-daemon:commons-daemon:jar
+ commons-dbcp:commons-dbcp:jar
+ commons-digester:commons-digester:jar
+ commons-httpclient:commons-httpclient:jar
+ commons-io:commons-io:jar
+ commons-jxpath:commons-jxpath:jar
+ commons-lang:commons-lang:jar
+ commons-logging:commons-logging:jar
+ commons-net:commons-net:jar
+ commons-pool:commons-pool:jar
+ io.micrometer:micrometer-core:jar
+ io.netty:netty:jar
+ io.netty:netty-all:jar
+ io.netty:netty-buffer:jar
+ io.netty:netty-codec:jar
+ io.netty:netty-codec-http:jar
+ io.netty:netty-common:jar
+ io.netty:netty-handler:jar
+ io.netty:netty-transport:jar
+ io.netty:netty-transport-native-epoll:jar
+ io.reactivex:rxjava:jar
+ io.reactivex:rxnetty:jar
+ io.reactivex:rxnetty-contexts:jar
+ io.reactivex:rxnetty-servo:jar
+ javax.activation:activation:jar
+ javax.annotation:javax.annotation-api:jar
+ javax.inject:javax.inject:jar
+ javax.servlet:javax.servlet-api:jar
+ javax.servlet.jsp:jsp-api:jar
+ javax.validation:validation-api:jar
+ javax.websocket:javax.websocket-api:jar
+ javax.ws.rs:javax.ws.rs-api:jar
+ javax.xml.bind:jaxb-api:jar
+ javax.xml.stream:stax-api:jar
+ joda-time:joda-time:jar
+ log4j:log4j:jar
+ mysql:mysql-connector-java:jar
+ net.databinder.dispatch:dispatch-core_2.11:jar
+ net.databinder.dispatch:dispatch-json4s-jackson_2.11:jar
+ org.antlr:antlr-runtime:jar
+ org.antlr:stringtemplate:jar
+ org.apache.commons:commons-compress:jar
+ org.apache.commons:commons-math:jar
+ org.apache.commons:commons-math3:jar
+ org.apache.curator:curator-client:jar
+ org.apache.curator:curator-framework:jar
+ org.apache.curator:curator-recipes:jar
+ org.apache.directory.api:api-asn1-api:jar
+ org.apache.directory.api:api-util:jar
+ org.apache.directory.server:apacheds-i18n:jar
+ org.apache.directory.server:apacheds-kerberos-codec:jar
+ org.apache.hadoop:hadoop-annotations:jar
+ org.apache.hadoop:hadoop-auth:jar
+ org.apache.hadoop:hadoop-common:jar
+ org.apache.hadoop:hadoop-hdfs:jar
+ org.apache.htrace:htrace-core:jar
+ org.apache.httpcomponents:httpclient:jar
+ org.apache.httpcomponents:httpcore:jar
+ org.apache.logging.log4j:log4j-api:jar
+ org.apache.logging.log4j:log4j-core:jar
+ org.apache.logging.log4j:log4j-jul:jar
+ org.apache.logging.log4j:log4j-slf4j-impl:jar
+ org.apache.zookeeper:zookeeper:jar
+ org.aspectj:aspectjweaver:jar
+ org.bouncycastle:bcpkix-jdk15on:jar
+ org.bouncycastle:bcprov-jdk15on:jar
+ org.codehaus.jackson:jackson-jaxrs:jar
+ org.codehaus.jackson:jackson-xc:jar
+ org.codehaus.jettison:jettison:jar
+ org.codehaus.woodstox:stax2-api:jar
+ org.codehaus.woodstox:woodstox-core-asl:jar
+ org.eclipse.jetty:jetty-annotations:jar
+ org.eclipse.jetty:jetty-client:jar
+ org.eclipse.jetty:jetty-continuation:jar
+ org.eclipse.jetty:jetty-http:jar
+ org.eclipse.jetty:jetty-io:jar
+ org.eclipse.jetty:jetty-jndi:jar
+ org.eclipse.jetty:jetty-plus:jar
+ org.eclipse.jetty:jetty-security:jar
+ org.eclipse.jetty:jetty-server:jar
+ org.eclipse.jetty:jetty-servlet:jar
+ org.eclipse.jetty:jetty-servlets:jar
+ org.eclipse.jetty:jetty-util:jar
+ org.eclipse.jetty:jetty-webapp:jar
+ org.eclipse.jetty:jetty-xml:jar
+ org.eclipse.jetty.websocket:javax-websocket-client-impl:jar
+ org.eclipse.jetty.websocket:javax-websocket-server-impl:jar
+ org.eclipse.jetty.websocket:websocket-api:jar
+ org.eclipse.jetty.websocket:websocket-client:jar
+ org.eclipse.jetty.websocket:websocket-common:jar
+ org.eclipse.jetty.websocket:websocket-server:jar
+ org.eclipse.jetty.websocket:websocket-servlet:jar
+ org.fusesource.leveldbjni:leveldbjni-all:jar
+ org.glassfish.hk2:class-model:jar
+ org.glassfish.hk2:config-types:jar
+ org.glassfish.hk2.external:aopalliance-repackaged:jar
+ org.glassfish.hk2.external:asm-all-repackaged:jar
+ org.glassfish.hk2.external:bean-validator:jar
+ org.glassfish.hk2.external:javax.inject:jar
+ org.glassfish.hk2:hk2:jar
+ org.glassfish.hk2:hk2-api:jar
+ org.glassfish.hk2:hk2-config:jar
+ org.glassfish.hk2:hk2-core:jar
+ org.glassfish.hk2:hk2-locator:jar
+ org.glassfish.hk2:hk2-runlevel:jar
+ org.glassfish.hk2:hk2-utils:jar
+ org.glassfish.hk2:osgi-resource-locator:jar
+ org.glassfish.hk2:spring-bridge:jar
+ org.glassfish.jersey.bundles:jaxrs-ri:jar
+ org.glassfish.jersey.bundles.repackaged:jersey-guava:jar
+ org.glassfish.jersey.containers:jersey-container-servlet:jar
+ org.glassfish.jersey.containers:jersey-container-servlet-core:jar
+ org.glassfish.jersey.core:jersey-client:jar
+ org.glassfish.jersey.core:jersey-common:jar
+ org.glassfish.jersey.core:jersey-server:jar
+ org.glassfish.jersey.ext:jersey-entity-filtering:jar
+ org.glassfish.jersey.ext:jersey-spring3:jar
+ org.glassfish.jersey.media:jersey-media-jaxb:jar
+ org.glassfish.jersey.media:jersey-media-json-jackson:jar
+ org.glassfish.jersey.media:jersey-media-multipart:jar
+ org.hdrhistogram:HdrHistogram:jar
+ org.javassist:javassist:jar
+ org.json4s:json4s-ast_2.11:jar
+ org.json4s:json4s-core_2.11:jar
+ org.json4s:json4s-jackson_2.11:jar
+ org.jsoup:jsoup:jar
+ org.jvnet.mimepull:mimepull:jar
+ org.jvnet:tiger-types:jar
+ org.latencyutils:LatencyUtils:jar
+ org.mortbay.jasper:apache-el:jar
+ org.mortbay.jetty:jetty:jar
+ org.mortbay.jetty:jetty-util:jar
+ org.ow2.asm:asm-analysis:jar
+ org.ow2.asm:asm-commons:jar
+ org.ow2.asm:asm-tree:jar
+ org.reflections:reflections:jar
+ org.scala-lang.modules:scala-parser-combinators_2.11:jar
+ org.scala-lang.modules:scala-xml_2.11:jar
+ org.scala-lang:scala-compiler:jar
+ org.scala-lang:scala-library:jar
+ org.scala-lang:scala-reflect:jar
+ org.scala-lang:scalap:jar
+ org.slf4j:jul-to-slf4j:jar
+ org.slf4j:slf4j-api:jar
+ org.springframework.boot:spring-boot:jar
+ org.springframework.boot:spring-boot-actuator:jar
+ org.springframework.boot:spring-boot-actuator-autoconfigure:jar
+ org.springframework.boot:spring-boot-autoconfigure:jar
+ org.springframework.boot:spring-boot-starter:jar
+ org.springframework.boot:spring-boot-starter-actuator:jar
+ org.springframework.boot:spring-boot-starter-aop:jar
+ org.springframework.boot:spring-boot-starter-jetty:jar
+ org.springframework.boot:spring-boot-starter-json:jar
+ org.springframework.boot:spring-boot-starter-log4j2:jar
+ org.springframework.boot:spring-boot-starter-web:jar
+ org.springframework.cloud:spring-cloud-commons:jar
+ org.springframework.cloud:spring-cloud-config-client:jar
+ org.springframework.cloud:spring-cloud-context:jar
+ org.springframework.cloud:spring-cloud-netflix-archaius:jar
+ org.springframework.cloud:spring-cloud-netflix-core:jar
+ org.springframework.cloud:spring-cloud-netflix-eureka-client:jar
+ org.springframework.cloud:spring-cloud-netflix-ribbon:jar
+ org.springframework.cloud:spring-cloud-starter:jar
+ org.springframework.cloud:spring-cloud-starter-config:jar
+ org.springframework.cloud:spring-cloud-starter-eureka:jar
+ org.springframework.cloud:spring-cloud-starter-netflix-archaius:jar
+ org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar
+ org.springframework.cloud:spring-cloud-starter-netflix-ribbon:jar
+ org.springframework.security:spring-security-crypto:jar
+ org.springframework.security:spring-security-rsa:jar
+ org.springframework:spring-aop:jar
+ org.springframework:spring-beans:jar
+ org.springframework:spring-context:jar
+ org.springframework:spring-core:jar
+ org.springframework:spring-expression:jar
+ org.springframework:spring-jcl:jar
+ org.springframework:spring-web:jar
+ org.springframework:spring-webmvc:jar
+ org.tukaani:xz:jar
+ org.yaml:snakeyaml:jar
+ software.amazon.ion:ion-java:jar
+ xerces:xercesImpl:jar
+ xmlenc:xmlenc:jar
+ xmlpull:xmlpull:jar
+ xpp3:xpp3_min:jar
+
+
+
+
+
+
+
+
+
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/LinksMonitorApplication.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/LinksMonitorApplication.java
new file mode 100644
index 0000000000..8f503dcf65
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/LinksMonitorApplication.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor;
+
+import org.apache.linkis.LinkisBaseServerApp;
+
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+@EnableScheduling
+@SpringBootApplication
+public class LinksMonitorApplication {
+
+ public static void main(String[] args) throws ReflectiveOperationException {
+ LinkisBaseServerApp.main(args);
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/dao/VersionDao.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/dao/VersionDao.java
new file mode 100644
index 0000000000..b4492c95ac
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/dao/VersionDao.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.dao;
+
+import org.apache.linkis.monitor.bml.cleaner.entity.CleanedResourceVersion;
+import org.apache.linkis.monitor.bml.cleaner.entity.ResourceVersion;
+import org.apache.linkis.monitor.bml.cleaner.vo.CleanResourceVo;
+
+import org.apache.ibatis.annotations.*;
+
+import java.util.Date;
+import java.util.List;
+
+public interface VersionDao {
+
+ @Select(
+ "select resource_id, count(resource_id) as version_count, max(version) as max_version from "
+ + "linkis_ps_bml_resources_version lpbrv where start_time < #{startTime} GROUP BY resource_id HAVING count(resource_id) > #{maxVersionNum} limit #{limitNum}")
+ List getAllNeedCleanResource(
+ @Param("maxVersionNum") Integer maxVersionNum,
+ @Param("startTime") Date startTime,
+ @Param("limitNum") int num);
+
+ @Select(
+ "select * from linkis_ps_bml_resources_version where resource_id = #{resourceId} and version < #{minKeepVersion} and version <> 'v000001'")
+ List getCleanVersionsByResourceId(
+ @Param("resourceId") String resourceId, @Param("minKeepVersion") String minKeepVersion);
+
+ @Insert({
+ "insert into linkis_ps_bml_cleaned_resources_version(`resource_id`,`file_md5`,`version`,`size`,`start_byte`, `end_byte`,`resource`,`description`,"
+ + "`start_time`,`end_time`,`client_ip`,`updator`,`enable_flag`,`old_resource`) values(#{resourceId},#{fileMd5},#{version},#{size},#{startByte},#{endByte}"
+ + ",#{resource},#{description},#{startTime},#{endTime},#{clientIp},#{updator},#{enableFlag},#{oldResource})"
+ })
+ @Options(useGeneratedKeys = true, keyProperty = "id")
+ void insertCleanResourceVersion(CleanedResourceVersion cleanedResourceVersion);
+
+ @Delete("delete from linkis_ps_bml_resources_version where id=#{id}")
+ void deleteResourceVersionById(@Param("id") long id);
+
+ @Select(
+ "select version from linkis_ps_bml_resources_version where resource_id =#{resourceId} and version <= #{maxVersion} order by version desc limit #{keepNum},1")
+ String getMinKeepVersion(
+ @Param("resourceId") String resourceId,
+ @Param("maxVersion") String maxVersion,
+ @Param("keepNum") int keepNum);
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/CleanedResourceVersion.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/CleanedResourceVersion.java
new file mode 100644
index 0000000000..5a0bfcc487
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/CleanedResourceVersion.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.entity;
+
+import java.util.Date;
+
+public class CleanedResourceVersion {
+
+ private long id;
+
+ private String resourceId;
+
+ private String fileMd5;
+
+ private String version;
+
+ private long size;
+
+ private String resource;
+
+ private String oldResource;
+
+ private String description;
+
+ private String clientIp;
+
+ private boolean enableFlag;
+
+ private String user;
+
+ private String system;
+
+ private Date startTime;
+
+ private Date endTime;
+
+ private long startByte;
+
+ private long endByte;
+
+ private String updator;
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getSystem() {
+ return system;
+ }
+
+ public void setSystem(String system) {
+ this.system = system;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getResource() {
+ return resource;
+ }
+
+ public void setResource(String resource) {
+ this.resource = resource;
+ }
+
+ public String getOldResource() {
+ return oldResource;
+ }
+
+ public void setOldResource(String oldResource) {
+ this.oldResource = oldResource;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getFileMd5() {
+ return fileMd5;
+ }
+
+ public void setFileMd5(String fileMd5) {
+ this.fileMd5 = fileMd5;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public void setSize(long size) {
+ this.size = size;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getClientIp() {
+ return clientIp;
+ }
+
+ public void setClientIp(String clientIp) {
+ this.clientIp = clientIp;
+ }
+
+ public boolean isEnableFlag() {
+ return enableFlag;
+ }
+
+ public void setEnableFlag(boolean enableFlag) {
+ this.enableFlag = enableFlag;
+ }
+
+ public long getStartByte() {
+ return startByte;
+ }
+
+ public void setStartByte(long startByte) {
+ this.startByte = startByte;
+ }
+
+ public long getEndByte() {
+ return endByte;
+ }
+
+ public void setEndByte(long endByte) {
+ this.endByte = endByte;
+ }
+
+ public Date getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Date startTime) {
+ this.startTime = startTime;
+ }
+
+ public Date getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Date endTime) {
+ this.endTime = endTime;
+ }
+
+ public String getUpdator() {
+ return updator;
+ }
+
+ public void setUpdator(String updator) {
+ this.updator = updator;
+ }
+
+ public static CleanedResourceVersion copyFromResourceVersion(ResourceVersion resourceVersion) {
+ CleanedResourceVersion cleanedResourceVersion = new CleanedResourceVersion();
+ cleanedResourceVersion.setResourceId(resourceVersion.getResourceId());
+ cleanedResourceVersion.setOldResource(resourceVersion.getResource());
+ cleanedResourceVersion.setFileMd5(resourceVersion.getFileMd5());
+ cleanedResourceVersion.setClientIp(resourceVersion.getClientIp());
+ cleanedResourceVersion.setSize(resourceVersion.getSize());
+ cleanedResourceVersion.setEnableFlag(resourceVersion.getEnableFlag());
+ cleanedResourceVersion.setVersion(resourceVersion.getVersion());
+ cleanedResourceVersion.setStartByte(resourceVersion.getStartByte());
+ cleanedResourceVersion.setEndByte(resourceVersion.getEndByte());
+ cleanedResourceVersion.setStartTime(resourceVersion.getStartTime());
+ cleanedResourceVersion.setEndTime(resourceVersion.getEndTime());
+ return cleanedResourceVersion;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/ResourceVersion.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/ResourceVersion.java
new file mode 100644
index 0000000000..5d297cf180
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/entity/ResourceVersion.java
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.entity;
+
+import java.util.Date;
+
+public class ResourceVersion {
+
+ private long id;
+
+ private String resourceId;
+
+ private String fileMd5;
+
+ private String version;
+
+ private long size;
+
+ private String resource;
+
+ private String description;
+
+ private String clientIp;
+
+ private boolean enableFlag;
+
+ private String user;
+
+ private String system;
+
+ private Date startTime;
+
+ private Date endTime;
+
+ private long startByte;
+
+ private long endByte;
+
+ private String updator;
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getSystem() {
+ return system;
+ }
+
+ public void setSystem(String system) {
+ this.system = system;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getResource() {
+ return resource;
+ }
+
+ public void setResource(String resource) {
+ this.resource = resource;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getFileMd5() {
+ return fileMd5;
+ }
+
+ public void setFileMd5(String fileMd5) {
+ this.fileMd5 = fileMd5;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public void setSize(long size) {
+ this.size = size;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getClientIp() {
+ return clientIp;
+ }
+
+ public void setClientIp(String clientIp) {
+ this.clientIp = clientIp;
+ }
+
+ public boolean getEnableFlag() {
+ return enableFlag;
+ }
+
+ public void setEnableFlag(boolean enableFlag) {
+ this.enableFlag = enableFlag;
+ }
+
+ public long getStartByte() {
+ return startByte;
+ }
+
+ public void setStartByte(long startByte) {
+ this.startByte = startByte;
+ }
+
+ public long getEndByte() {
+ return endByte;
+ }
+
+ public void setEndByte(long endByte) {
+ this.endByte = endByte;
+ }
+
+ public Date getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Date startTime) {
+ this.startTime = startTime;
+ }
+
+ public Date getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Date endTime) {
+ this.endTime = endTime;
+ }
+
+ public String getUpdator() {
+ return updator;
+ }
+
+ public void setUpdator(String updator) {
+ this.updator = updator;
+ }
+
+ public static ResourceVersion createNewResourceVersion(
+ String resourceId,
+ String resourcePath,
+ String fileMd5,
+ String clientIp,
+ long size,
+ String version,
+ long startByte) {
+ ResourceVersion resourceVersion = new ResourceVersion();
+ resourceVersion.setResourceId(resourceId);
+ resourceVersion.setResource(resourcePath);
+ resourceVersion.setFileMd5(fileMd5);
+ resourceVersion.setClientIp(clientIp);
+ resourceVersion.setSize(size);
+ resourceVersion.setEnableFlag(true);
+ resourceVersion.setVersion(version);
+ resourceVersion.setStartByte(startByte);
+ resourceVersion.setEndByte(startByte + size - 1);
+ resourceVersion.setStartTime(new Date(System.currentTimeMillis()));
+ resourceVersion.setEndTime(new Date(System.currentTimeMillis()));
+ return resourceVersion;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/CleanerService.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/CleanerService.java
new file mode 100644
index 0000000000..0dfa15f396
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/CleanerService.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.service;
+
+public interface CleanerService {
+
+ public void run();
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/VersionService.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/VersionService.java
new file mode 100644
index 0000000000..cc1a45c9e6
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/VersionService.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.service;
+
+import org.apache.linkis.common.io.FsPath;
+import org.apache.linkis.monitor.bml.cleaner.entity.CleanedResourceVersion;
+import org.apache.linkis.storage.fs.FileSystem;
+
+import java.io.IOException;
+
+public interface VersionService {
+
+ void doMove(
+ FileSystem fs,
+ FsPath srcPath,
+ FsPath destPath,
+ CleanedResourceVersion insertVersion,
+ long delVersionId)
+ throws IOException;
+
+ void moveOnDb(CleanedResourceVersion insertVersion, long delVersionId);
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/CleanerServiceImpl.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/CleanerServiceImpl.java
new file mode 100644
index 0000000000..ec2ed2d758
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/CleanerServiceImpl.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.service.impl;
+
+import org.apache.linkis.common.io.FsPath;
+import org.apache.linkis.monitor.bml.cleaner.dao.VersionDao;
+import org.apache.linkis.monitor.bml.cleaner.entity.CleanedResourceVersion;
+import org.apache.linkis.monitor.bml.cleaner.entity.ResourceVersion;
+import org.apache.linkis.monitor.bml.cleaner.service.CleanerService;
+import org.apache.linkis.monitor.bml.cleaner.service.VersionService;
+import org.apache.linkis.monitor.bml.cleaner.vo.CleanResourceVo;
+import org.apache.linkis.monitor.constants.Constants;
+import org.apache.linkis.storage.FSFactory;
+import org.apache.linkis.storage.fs.FileSystem;
+import org.apache.linkis.storage.utils.StorageConfiguration;
+import org.apache.linkis.storage.utils.StorageUtils;
+
+import org.apache.commons.io.IOUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class CleanerServiceImpl implements CleanerService {
+
+ private final Logger logger = LoggerFactory.getLogger("CleanerServiceImpl");
+
+ private final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
+
+ public static final String VERSION_FORMAT = "%06d";
+ public static final String VERSION_PREFIX = "v";
+ public static final String TRASH_DIR = "/trash";
+
+ private FileSystem fs = null;
+
+ @Autowired private VersionDao versionDao;
+
+ public void setVersionDao(VersionDao versionDao) {
+ this.versionDao = versionDao;
+ }
+
+ private Set cleanedResourceIds = new HashSet();
+
+ Date previous;
+
+ @Autowired VersionService versionService;
+
+ public void clean() {
+ previous =
+ new Date(
+ System.currentTimeMillis()
+ - (Long) Constants.BML_PREVIOUS_INTERVAL_TIME_DAYS().getValue() * 86400 * 1000);
+
+ if ((Integer) Constants.BML_VERSION_MAX_NUM().getValue()
+ - (Integer) Constants.BML_VERSION_KEEP_NUM().getValue()
+ <= 1) {
+ logger.error("conf error need to keep version num > 1");
+ return;
+ }
+ List needCleanResources = getCleanResources();
+ while (needCleanResources != null && needCleanResources.size() > 0) {
+ logger.info("need cleaned resource count:{}", needCleanResources.size());
+ fs =
+ (FileSystem)
+ FSFactory.getFs(StorageUtils.HDFS, StorageConfiguration.HDFS_ROOT_USER.getValue());
+ for (CleanResourceVo resourceVo : needCleanResources) {
+ String minVersion =
+ versionDao.getMinKeepVersion(
+ resourceVo.getResourceId(),
+ resourceVo.getMaxVersion(),
+ (Integer) Constants.BML_VERSION_KEEP_NUM().getValue() - 1);
+ List cleanVersionList =
+ versionDao.getCleanVersionsByResourceId(resourceVo.getResourceId(), minVersion);
+ // move on hdfs
+ for (ResourceVersion version : cleanVersionList) {
+ FsPath srcPath = new FsPath(version.getResource());
+ // fs放到外层
+ try {
+ fs.init(null);
+ if (!fs.exists(srcPath)) {
+ logger.error("try to move but bml source file:{} not exists!", version.getResource());
+ CleanedResourceVersion cleanedResourceVersion =
+ CleanedResourceVersion.copyFromResourceVersion(version);
+ cleanedResourceVersion.setResource("");
+ versionService.moveOnDb(cleanedResourceVersion, version.getId());
+ continue;
+ }
+ String destPrefix =
+ version.getResource().substring(0, version.getResource().indexOf("/bml/") + 4);
+ String destPath =
+ destPrefix
+ + TRASH_DIR
+ + File.separator
+ + sdf.format(new Date())
+ + File.separator
+ + version.getResourceId()
+ + "_"
+ + version.getVersion();
+ FsPath dest = new FsPath(destPath);
+ if (!fs.exists(dest.getParent())) {
+ fs.mkdirs(dest.getParent());
+ }
+ logger.info("begin to mv bml resource:{} to dest:{}", version.getResource(), destPath);
+ CleanedResourceVersion cleanedResourceVersion =
+ CleanedResourceVersion.copyFromResourceVersion(version);
+ cleanedResourceVersion.setResource(destPath);
+ versionService.doMove(fs, srcPath, dest, cleanedResourceVersion, version.getId());
+ } catch (Exception e) {
+ logger.error("failed to mv bml resource:{}", e.getMessage(), e);
+ }
+ }
+
+ cleanedResourceIds.add(resourceVo.getResourceId());
+ }
+ needCleanResources = getCleanResources();
+ }
+ }
+
+ public void run() {
+ logger.info("start to clean.");
+ clean();
+ logger.info("start to shutdown.");
+ shutdown();
+ }
+
+ void shutdown() {
+ IOUtils.closeQuietly(fs);
+ }
+
+ List getCleanResources() {
+ List cleanResourceVoList =
+ versionDao.getAllNeedCleanResource(
+ (Integer) Constants.BML_VERSION_MAX_NUM().getValue(),
+ previous,
+ (Integer) Constants.BML_CLEAN_ONCE_RESOURCE_LIMIT_NUM().getValue());
+
+ return cleanResourceVoList.stream()
+ .filter(cleanResourceVo -> !cleanedResourceIds.contains(cleanResourceVo.getResourceId()))
+ .collect(Collectors.toList());
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/VersionServiceImpl.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/VersionServiceImpl.java
new file mode 100644
index 0000000000..be9e5b70ea
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/service/impl/VersionServiceImpl.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.service.impl;
+
+import org.apache.linkis.common.io.FsPath;
+import org.apache.linkis.monitor.bml.cleaner.dao.VersionDao;
+import org.apache.linkis.monitor.bml.cleaner.entity.CleanedResourceVersion;
+import org.apache.linkis.monitor.bml.cleaner.service.VersionService;
+import org.apache.linkis.storage.fs.FileSystem;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+
+@Service
+public class VersionServiceImpl implements VersionService {
+
+ @Autowired VersionDao versionDao;
+
+ public void setVersionDao(VersionDao versionDao) {
+ this.versionDao = versionDao;
+ }
+
+ @Transactional(rollbackFor = Throwable.class)
+ public void doMove(
+ FileSystem fs,
+ FsPath srcPath,
+ FsPath destPath,
+ CleanedResourceVersion insertVersion,
+ long delVersionId)
+ throws IOException {
+ versionDao.insertCleanResourceVersion(insertVersion);
+ versionDao.deleteResourceVersionById(delVersionId);
+ fs.renameTo(srcPath, destPath);
+ }
+
+ @Transactional
+ public void moveOnDb(CleanedResourceVersion insertVersion, long delVersionId) {
+ versionDao.insertCleanResourceVersion(insertVersion);
+ versionDao.deleteResourceVersionById(delVersionId);
+ }
+
+ public String test() {
+ return "this a test string";
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/vo/CleanResourceVo.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/vo/CleanResourceVo.java
new file mode 100644
index 0000000000..4ef205effd
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/bml/cleaner/vo/CleanResourceVo.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.bml.cleaner.vo;
+
+public class CleanResourceVo {
+ private String resourceId;
+ private int versionCount;
+ private String maxVersion;
+
+ public String getResourceId() {
+ return resourceId;
+ }
+
+ public void setResourceId(String resourceId) {
+ this.resourceId = resourceId;
+ }
+
+ public int getVersionCount() {
+ return versionCount;
+ }
+
+ public void setVersionCount(int versionCount) {
+ this.versionCount = versionCount;
+ }
+
+ public String getMaxVersion() {
+ return maxVersion;
+ }
+
+ public void setMaxVersion(String maxVersion) {
+ this.maxVersion = maxVersion;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ListenerConfig.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ListenerConfig.java
new file mode 100644
index 0000000000..eb5c11af87
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ListenerConfig.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.config;
+
+import org.apache.linkis.monitor.until.HttpsUntils;
+import org.apache.linkis.monitor.until.ThreadUtils;
+import org.apache.linkis.monitor.utils.log.LogUtils;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.EventListener;
+
+import java.io.IOException;
+
+import org.slf4j.Logger;
+
+@Configuration
+public class ListenerConfig {
+
+ private static final Logger logger = LogUtils.stdOutLogger();
+
+ @EventListener
+ private void shutdownEntrance(ContextClosedEvent event) {
+ try {
+ ThreadUtils.executors.shutdown();
+ HttpsUntils.client.close();
+ } catch (IOException e) {
+ logger.error("ListenerConfig error msg {}", e.getMessage());
+ }
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/MonitorConfig.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/MonitorConfig.java
new file mode 100644
index 0000000000..5b4c2e269a
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/MonitorConfig.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.config;
+
+import org.apache.linkis.common.conf.CommonVars;
+import org.apache.linkis.common.conf.Configuration;
+
+public class MonitorConfig {
+
+ public static final String shellPath = Configuration.getLinkisHome() + "/admin/";
+
+ public static final CommonVars USER_MODE_TIMEOUT =
+ CommonVars.apply("linkis.monitor.user.timeOut", 300);
+ public static final CommonVars USER_MODE_ENGINE =
+ CommonVars.apply("linkis.monitor.user.enginelist", "[]");
+
+ public static final CommonVars ECM_TASK_MAJOR =
+ CommonVars.apply("linkis.monitor.ecmResourceTask.major", 0.03);
+ public static final CommonVars ECM_TASK_MINOR =
+ CommonVars.apply("linkis.monitor.ecmResourceTask.minor", 0.1);
+ public static final CommonVars ECM_TASK_IMURL =
+ CommonVars.apply("linkis.monitor.metrics.imsUrl");
+ public static final CommonVars ECM_TASK_USER_AUTHKEY =
+ CommonVars.apply("linkis.monitor.metrics.userAuthKey");
+
+ public static final CommonVars JOB_HISTORY_TIME_EXCEED =
+ CommonVars.apply("linkis.monitor.jobhistory.id.timeExceed", 0L);
+
+ public static final CommonVars ENTRANCE_TASK_USERTOTAL =
+ CommonVars.apply("linkis.monitor.entranceTask.userTotalTask", 1000);
+ public static final CommonVars ENTRANCE_TASK_TOTAL_MAJOR =
+ CommonVars.apply("linkis.monitor.entranceTask.linkisTotalTaskMajor", 50000);
+ public static final CommonVars ENTRANCE_TASK_TOTAL_MINOR =
+ CommonVars.apply("linkis.monitor.entranceTask.linkisTotalTaskMinor", 10000);
+ public static final CommonVars ENTRANCE_TASK_USERLIST =
+ CommonVars.apply("linkis.monitor.entranceTask.userlist", "[]");
+
+ public static final CommonVars SCHEDULED_CONFIG_NUM =
+ CommonVars.apply("linkis.monitor.scheduled.pool.cores.num", 10);
+
+ public static final CommonVars SHELL_TIMEOUT =
+ CommonVars.apply("linkis.monitor.shell.time.out.minute", 30);
+
+ public static final CommonVars USER_MODE_INTERFACE_TIMEOUT =
+ CommonVars.apply("linkis.monitor.user.mode.time.out", 30 * 1000);
+
+ public static final CommonVars SOLUTION_URL =
+ CommonVars.apply(
+ "linkis.monitor.jobhistory.solution.url",
+ "https://linkis.apache.org/docs/latest/tuning-and-troubleshooting/error-guide/error-code");
+
+ public static final CommonVars TASK_RUNTIME_TIMEOUT_DESC =
+ CommonVars.apply(
+ "linkis.monitor.jobhistory.task.timeout.desc",
+ "[Linkis任务信息]您好,您在Linkis/DSS提交的任务(任务ID:{0}),已经运行超过{1}h,"
+ + "请关注是否任务正常,如果不正常您可以到Linkis/DSS管理台进行任务的kill,集群信息为BDAP({2})。详细解决方案见Q47:{3} ");
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ScheduledConfig.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ScheduledConfig.java
new file mode 100644
index 0000000000..e954122671
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/config/ScheduledConfig.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+@Configuration
+public class ScheduledConfig implements SchedulingConfigurer {
+ @Bean
+ public Executor taskExecutor() {
+ return Executors.newScheduledThreadPool(MonitorConfig.SCHEDULED_CONFIG_NUM.getValue());
+ }
+
+ @Override
+ public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
+ scheduledTaskRegistrar.setScheduler(taskExecutor());
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EngineEntity.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EngineEntity.java
new file mode 100644
index 0000000000..760c06ba1b
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EngineEntity.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.entity;
+
+import java.io.Serializable;
+
+public class EngineEntity implements Serializable {
+
+ private String engineType;
+
+ private String code;
+
+ private String runType;
+
+ public String getEngineType() {
+ return engineType;
+ }
+
+ public void setEngineType(String engineType) {
+ this.engineType = engineType;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ public String getRunType() {
+ return runType;
+ }
+
+ public void setRunType(String runType) {
+ this.runType = runType;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EntranceEntity.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EntranceEntity.java
new file mode 100644
index 0000000000..241439b499
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/EntranceEntity.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.entity;
+
+import java.io.Serializable;
+
+public class EntranceEntity implements Serializable {
+
+ private Integer runningtasks;
+
+ private Integer queuedtasks;
+
+ private String alteruser;
+
+ private String username;
+
+ public Integer getQueuedtasks() {
+ return queuedtasks;
+ }
+
+ public void setQueuedtasks(Integer queuedtasks) {
+ this.queuedtasks = queuedtasks;
+ }
+
+ public String getAlteruser() {
+ return alteruser;
+ }
+
+ public void setAlteruser(String alteruser) {
+ this.alteruser = alteruser;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public Integer getRunningtasks() {
+ return runningtasks;
+ }
+
+ public void setRunningtasks(Integer runningtasks) {
+ this.runningtasks = runningtasks;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/IndexEntity.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/IndexEntity.java
new file mode 100644
index 0000000000..2905f8aced
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/entity/IndexEntity.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.entity;
+
+import org.apache.linkis.monitor.constants.Constants;
+
+public class IndexEntity {
+
+ private final String subsystemId = Constants.ALERT_SUB_SYSTEM_ID();
+ private String interfaceName;
+ private String attrGroup;
+ private String attrName;
+ private String hostIp;
+ private String metricValue;
+
+ public String getSubsystemId() {
+ return subsystemId;
+ }
+
+ public String getInterfaceName() {
+ return interfaceName;
+ }
+
+ public void setInterfaceName(String interfaceName) {
+ this.interfaceName = interfaceName;
+ }
+
+ public String getAttrGroup() {
+ return attrGroup;
+ }
+
+ public void setAttrGroup(String attrGroup) {
+ this.attrGroup = attrGroup;
+ }
+
+ public String getAttrName() {
+ return attrName;
+ }
+
+ public void setAttrName(String attrName) {
+ this.attrName = attrName;
+ }
+
+ public String getHostIp() {
+ return hostIp;
+ }
+
+ public void setHostIp(String hostIp) {
+ this.hostIp = hostIp;
+ }
+
+ public String getMetricValue() {
+ return metricValue;
+ }
+
+ public void setMetricValue(String metricValue) {
+ this.metricValue = metricValue;
+ }
+
+ public IndexEntity() {}
+
+ public IndexEntity(
+ String interfaceName, String attrGroup, String attrName, String hostIp, String metricValue) {
+ this.interfaceName = interfaceName;
+ this.attrGroup = attrGroup;
+ this.attrName = attrName;
+ this.hostIp = hostIp;
+ this.metricValue = metricValue;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InsLabelRelationDao.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InsLabelRelationDao.java
new file mode 100644
index 0000000000..d805c1a99b
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InsLabelRelationDao.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.dao;
+
+import org.apache.linkis.monitor.instance.entity.InsPersistenceLabel;
+
+import java.util.List;
+
+public interface InsLabelRelationDao {
+
+ /**
+ * Search labels
+ *
+ * @param instance instance value (http:port)
+ * @return
+ */
+ List searchLabelsByInstance(String instance);
+
+ void dropRelationsByInstance(String instance);
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceInfoDao.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceInfoDao.java
new file mode 100644
index 0000000000..973801a37a
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceInfoDao.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.dao;
+
+import org.apache.linkis.common.ServiceInstance;
+import org.apache.linkis.monitor.instance.entity.InstanceInfo;
+
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+public interface InstanceInfoDao {
+
+ void removeInstance(ServiceInstance instance);
+
+ List getInstanceInfoByApplicationNameAndHostnameFuzzy(
+ @Param("hostname") String hostname, @Param("applicationName") String applicationName);
+
+ List getInstanceInfoByApplicationNameAndInstanceName(
+ @Param("instanceName") String instanceName, @Param("applicationName") String applicationName);
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceLabelDao.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceLabelDao.java
new file mode 100644
index 0000000000..361bebf8ba
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/dao/InstanceLabelDao.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.dao;
+
+import org.apache.linkis.monitor.instance.entity.InsPersistenceLabel;
+
+import java.util.List;
+
+public interface InstanceLabelDao {
+ /**
+ * Remove label
+ *
+ * @param label label entity
+ */
+ void remove(InsPersistenceLabel label);
+
+ /**
+ * Remove key -> value map from label id
+ *
+ * @param labelId
+ */
+ void doRemoveKeyValues(Integer labelId);
+
+ void doRemoveKeyValuesBatch(List labelIds);
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabel.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabel.java
new file mode 100644
index 0000000000..0959c27988
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabel.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.entity;
+
+import java.util.Date;
+
+public class InsPersistenceLabel {
+ private Integer id;
+ private int labelValueSize = -1;
+ private String stringValue;
+ private Boolean modifiable = false;
+
+ private String labelKey;
+
+ private String feature;
+
+ private Date updateTime;
+ private Date createTime;
+
+ public Boolean getModifiable() {
+ return modifiable;
+ }
+
+ public void setModifiable(Boolean modifiable) {
+ this.modifiable = modifiable;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public int getLabelValueSize() {
+ return labelValueSize;
+ }
+
+ public void setLabelValueSize(int labelValueSize) {
+ this.labelValueSize = labelValueSize;
+ }
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ public void setStringValue(String stringValue) {
+ this.stringValue = stringValue;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public String getLabelKey() {
+ return labelKey;
+ }
+
+ public void setLabelKey(String labelKey) {
+ this.labelKey = labelKey;
+ }
+
+ public String getFeature() {
+ return feature;
+ }
+
+ public void setFeature(String feature) {
+ this.feature = feature;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabelValue.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabelValue.java
new file mode 100644
index 0000000000..029f552608
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InsPersistenceLabelValue.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.entity;
+
+public class InsPersistenceLabelValue {
+
+ private Integer labelId;
+
+ private String valueKey;
+
+ private String valueContent;
+
+ public InsPersistenceLabelValue() {}
+
+ public InsPersistenceLabelValue(Integer labelId, String key, String content) {
+ this.labelId = labelId;
+ this.valueKey = key;
+ this.valueContent = content;
+ }
+
+ public String getValueKey() {
+ return valueKey;
+ }
+
+ public void setValueKey(String valueKey) {
+ this.valueKey = valueKey;
+ }
+
+ public String getValueContent() {
+ return valueContent;
+ }
+
+ public void setValueContent(String valueContent) {
+ this.valueContent = valueContent;
+ }
+
+ public Integer getLabelId() {
+ return labelId;
+ }
+
+ public void setLabelId(Integer labelId) {
+ this.labelId = labelId;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InstanceInfo.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InstanceInfo.java
new file mode 100644
index 0000000000..5360ffd323
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/instance/entity/InstanceInfo.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.instance.entity;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+public class InstanceInfo {
+ /** Automatic increment */
+ private Integer id;
+
+ private String applicationName;
+
+ private String instance;
+
+ private Date updateTime;
+
+ private Date createTime;
+ /** Labels related */
+ private List labels = new ArrayList<>();
+
+ public InstanceInfo() {}
+
+ public InstanceInfo(String applicationName, String instance) {
+ this.applicationName = applicationName;
+ this.instance = instance;
+ }
+
+ public List getLabels() {
+ return labels;
+ }
+
+ public void setLabels(List labels) {
+ this.labels = labels;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getApplicationName() {
+ return applicationName;
+ }
+
+ public void setApplicationName(String applicationName) {
+ this.applicationName = applicationName;
+ }
+
+ public String getInstance() {
+ return instance;
+ }
+
+ public void setInstance(String instance) {
+ this.instance = instance;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/QueryUtils.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/QueryUtils.java
new file mode 100644
index 0000000000..aa73471c49
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/QueryUtils.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.jobhistory;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class QueryUtils {
+
+ private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+
+ public static String dateToString(Date date) {
+ return dateFormat.format(date);
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/dao/JobHistoryMapper.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/dao/JobHistoryMapper.java
new file mode 100644
index 0000000000..ebd213cfb3
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/dao/JobHistoryMapper.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.jobhistory.dao;
+
+import org.apache.linkis.monitor.jobhistory.entity.JobHistory;
+
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Date;
+import java.util.List;
+
+public interface JobHistoryMapper {
+
+ List selectJobHistory(JobHistory jobReq);
+
+ List search(
+ @Param("id") Long id,
+ @Param("umUser") String username,
+ @Param("status") List status,
+ @Param("startDate") Date startDate,
+ @Param("endDate") Date endDate,
+ @Param("engineType") String engineType);
+
+ void updateIncompleteJobStatusGivenIDList(
+ @Param("idList") List idList, @Param("targetStatus") String targetStatus);
+
+ void updateJobStatusForInstanceGivenStatusList(
+ @Param("instanceName") String instanceName,
+ @Param("statusList") List statusList,
+ @Param("targetStatus") String targetStatus,
+ @Param("startDate") Date startDate);
+
+ List searchByCache(
+ @Param("id") Long id,
+ @Param("umUser") String username,
+ @Param("status") List status,
+ @Param("startDate") Date startDate,
+ @Param("endDate") Date endDate,
+ @Param("engineType") String engineType);
+
+ List searchByCacheAndUpdateTime(
+ @Param("id") Long id,
+ @Param("umUser") String username,
+ @Param("status") List status,
+ @Param("startDate") Date startDate,
+ @Param("endDate") Date endDate,
+ @Param("engineType") String engineType);
+
+ Long selectIdByHalfDay(@Param("id") long beginId);
+
+ Long selectMaxId();
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/entity/JobHistory.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/entity/JobHistory.java
new file mode 100644
index 0000000000..e2499d328d
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/entity/JobHistory.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.jobhistory.entity;
+
+import org.apache.linkis.monitor.jobhistory.QueryUtils;
+
+import java.util.Date;
+
+public class JobHistory {
+
+ private Long id;
+
+ private String jobReqId;
+
+ private String submitUser;
+
+ private String executeUser;
+
+ private String source;
+
+ private String labels;
+
+ private String params;
+
+ private String progress;
+
+ private String status;
+
+ private String logPath;
+
+ private Integer errorCode;
+
+ private String errorDesc;
+
+ private Date createdTime;
+
+ private Date updatedTime;
+
+ private String updateTimeMills;
+
+ private String instances;
+
+ private String metrics;
+
+ private String engineType;
+
+ private String executionCode;
+
+ private String observeInfo;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getJobReqId() {
+ return jobReqId;
+ }
+
+ public void setJobReqId(String jobReqId) {
+ this.jobReqId = jobReqId;
+ }
+
+ public String getSubmitUser() {
+ return submitUser;
+ }
+
+ public void setSubmitUser(String submitUser) {
+ this.submitUser = submitUser;
+ }
+
+ public String getExecuteUser() {
+ return executeUser;
+ }
+
+ public void setExecuteUser(String executeUser) {
+ this.executeUser = executeUser;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getLabels() {
+ return labels;
+ }
+
+ public void setLabels(String labels) {
+ this.labels = labels;
+ }
+
+ public String getParams() {
+ return params;
+ }
+
+ public void setParams(String params) {
+ this.params = params;
+ }
+
+ public String getProgress() {
+ return progress;
+ }
+
+ public void setProgress(String progress) {
+ this.progress = progress;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String getLogPath() {
+ return logPath;
+ }
+
+ public void setLogPath(String logPath) {
+ this.logPath = logPath;
+ }
+
+ public Integer getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(Integer errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorDesc() {
+ return errorDesc;
+ }
+
+ public void setErrorDesc(String errorDesc) {
+ this.errorDesc = errorDesc;
+ }
+
+ public Date getCreatedTime() {
+ return createdTime;
+ }
+
+ public void setCreatedTime(Date createdTime) {
+ this.createdTime = createdTime;
+ }
+
+ public Date getUpdatedTime() {
+ return updatedTime;
+ }
+
+ public void setUpdatedTime(Date updatedTime) {
+ this.updatedTime = updatedTime;
+ }
+
+ public String getInstances() {
+ return instances;
+ }
+
+ public void setInstances(String instances) {
+ this.instances = instances;
+ }
+
+ public String getMetrics() {
+ return metrics;
+ }
+
+ public void setMetrics(String metrics) {
+ this.metrics = metrics;
+ }
+
+ public String getEngineType() {
+ return engineType;
+ }
+
+ public void setEngineType(String engineType) {
+ this.engineType = engineType;
+ }
+
+ public String getExecutionCode() {
+ return executionCode;
+ }
+
+ public void setExecutionCode(String executionCode) {
+ this.executionCode = executionCode;
+ }
+
+ public String getUpdateTimeMills() {
+ return QueryUtils.dateToString(getUpdatedTime());
+ }
+
+ public String getObserveInfo() {
+ return observeInfo;
+ }
+
+ public void setObserveInfo(String observeInfo) {
+ this.observeInfo = observeInfo;
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/AnomalyScannerException.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/AnomalyScannerException.java
new file mode 100644
index 0000000000..b2c83be013
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/AnomalyScannerException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.jobhistory.exception;
+
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.common.exception.ExceptionLevel;
+
+public class AnomalyScannerException extends ErrorException {
+ public AnomalyScannerException(int errCode, String desc) {
+ super(errCode, desc);
+ }
+
+ public AnomalyScannerException(
+ int errCode, String desc, String ip, int port, String serviceKind) {
+ super(errCode, desc, ip, port, serviceKind);
+ }
+
+ @Override
+ public ExceptionLevel getLevel() {
+ return super.getLevel();
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/DirtyDataCleanException.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/DirtyDataCleanException.java
new file mode 100644
index 0000000000..b1c5e64743
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/jobhistory/exception/DirtyDataCleanException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.jobhistory.exception;
+
+import org.apache.linkis.common.exception.ErrorException;
+import org.apache.linkis.common.exception.ExceptionLevel;
+
+public class DirtyDataCleanException extends ErrorException {
+ public DirtyDataCleanException(int errCode, String desc) {
+ super(errCode, desc);
+ }
+
+ public DirtyDataCleanException(
+ int errCode, String desc, String ip, int port, String serviceKind) {
+ super(errCode, desc, ip, port, serviceKind);
+ }
+
+ @Override
+ public ExceptionLevel getLevel() {
+ return super.getLevel();
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/BmlClear.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/BmlClear.java
new file mode 100644
index 0000000000..cb7d37197f
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/BmlClear.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.monitor.bml.cleaner.service.CleanerService;
+import org.apache.linkis.monitor.utils.log.LogUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import org.slf4j.Logger;
+
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class BmlClear {
+
+ private static final Logger logger = LogUtils.stdOutLogger();
+
+ @Autowired private CleanerService cleanerServices;
+
+ @Scheduled(cron = "${linkis.monitor.bml.clear.history.version.cron}")
+ public void jobHistoryScanTask() {
+ logger.info("start to clear bml history version");
+ cleanerServices.run();
+ logger.info("end to clear bml history version");
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EcRecordClear.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EcRecordClear.java
new file mode 100644
index 0000000000..ddb3d3e8c8
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EcRecordClear.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.monitor.config.MonitorConfig;
+import org.apache.linkis.monitor.until.ThreadUtils;
+import org.apache.linkis.monitor.utils.log.LogUtils;
+
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+
+/** * Task: clean up linkis_cg_ec_resource_info_record data */
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class EcRecordClear {
+
+ private static final Logger logger = LogUtils.stdOutLogger();
+
+ @Scheduled(cron = "${linkis.monitor.clear.ecRecord.cron}")
+ public void ecRecordClear() {
+ logger.info("Start to clear_ec_record shell");
+ List cmdlist = new ArrayList<>();
+ cmdlist.add("sh");
+ cmdlist.add(MonitorConfig.shellPath + "clear_ec_record.sh");
+ logger.info("clear_ec_record shell command {}", cmdlist);
+ String exec = ThreadUtils.run(cmdlist, "clear_ec_record.sh");
+ logger.info("shell log {}", exec);
+ logger.info("End to clear_ec_record shell ");
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EntranceTaskMonitor.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EntranceTaskMonitor.java
new file mode 100644
index 0000000000..a6e7879f07
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/EntranceTaskMonitor.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.common.ServiceInstance;
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.governance.common.conf.GovernanceCommonConf;
+import org.apache.linkis.monitor.config.MonitorConfig;
+import org.apache.linkis.monitor.constants.Constants;
+import org.apache.linkis.monitor.entity.IndexEntity;
+import org.apache.linkis.monitor.until.HttpsUntils;
+import org.apache.linkis.monitor.utils.alert.AlertDesc;
+import org.apache.linkis.monitor.utils.alert.ims.MonitorAlertUtils;
+import org.apache.linkis.monitor.utils.alert.ims.PooledImsAlertUtils;
+import org.apache.linkis.rpc.Sender;
+import org.apache.linkis.server.BDPJettyServerHelper;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.*;
+
+import com.google.gson.internal.LinkedTreeMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * * Entrance monitors the number of tasks for specified users and systems. If the configured
+ * threshold is exceeded, an alarm will be triggered.
+ */
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class EntranceTaskMonitor {
+
+ private static final Logger logger = LoggerFactory.getLogger(EntranceTaskMonitor.class);
+
+ private static final String ENTRANCE_RUNNING_TASK = "entrance_running_task";
+ private static final String ENTRANCE_QUEUED_TASK = "entrance_queued_task";
+
+ @Scheduled(cron = "${linkis.monitor.entrance.task.cron}")
+ public void entranceTask() throws IOException {
+ List> userlist = new ArrayList<>();
+ String value = MonitorConfig.ENTRANCE_TASK_USERLIST.getValue();
+ if (StringUtils.isNotBlank(value)) {
+ userlist = BDPJettyServerHelper.gson().fromJson(value, ArrayList.class);
+ }
+
+ userlist.forEach(
+ entranceEntity -> {
+ Map data = new HashMap<>();
+ try {
+ data =
+ MapUtils.getMap(
+ HttpsUntils.getEntranceTask(null, entranceEntity.get("username"), null),
+ "data");
+ logger.info("TaskMonitor userlist response {}:", data);
+ } catch (IOException e) {
+ logger.warn("failed to get EntranceTask data");
+ }
+
+ int runningNumber =
+ null != entranceEntity.get("runningtasks")
+ ? Integer.parseInt(entranceEntity.get("runningtasks"))
+ : 0;
+ int queuedNumber =
+ null != entranceEntity.get("queuedtasks")
+ ? Integer.parseInt(entranceEntity.get("queuedtasks"))
+ : 0;
+
+ BigDecimal runningtotal = new BigDecimal((int) data.get("runningNumber"));
+ BigDecimal queuedtotal = new BigDecimal((int) data.get("queuedNumber"));
+ BigDecimal total = runningtotal.add(queuedtotal);
+ HashMap parms = new HashMap<>();
+ parms.put("$username", entranceEntity.get("username"));
+ parms.put("$alteruser", entranceEntity.get("alteruser"));
+ parms.put("$url", Configuration.GATEWAY_URL().getValue());
+ // 获取标准阈值
+ if (runningtotal.intValue() > runningNumber) {
+ // 触发告警 用户运行任务满
+ parms.put("$runningtask", String.valueOf(runningNumber));
+ Map ecmResourceAlerts =
+ MonitorAlertUtils.getAlerts(Constants.ALERT_RESOURCE_MONITOR(), parms);
+ PooledImsAlertUtils.addAlert(ecmResourceAlerts.get("12005"));
+ }
+ if (queuedtotal.intValue() > queuedNumber) {
+ // 触发告警 用户排队任务满
+ parms.put("$queuedtask", String.valueOf(queuedNumber));
+ Map ecmResourceAlerts =
+ MonitorAlertUtils.getAlerts(Constants.ALERT_RESOURCE_MONITOR(), parms);
+ PooledImsAlertUtils.addAlert(ecmResourceAlerts.get("12006"));
+ }
+ int usertotalTask = MonitorConfig.ENTRANCE_TASK_USERTOTAL.getValue();
+ if (total.intValue() > usertotalTask) {
+ parms.put("$tasktotal", String.valueOf(usertotalTask));
+ Map ecmResourceAlerts =
+ MonitorAlertUtils.getAlerts(Constants.ALERT_RESOURCE_MONITOR(), parms);
+ PooledImsAlertUtils.addAlert(ecmResourceAlerts.get("12007"));
+ }
+ });
+ Map likisData = null;
+ try {
+ likisData = MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", null), "data");
+ logger.info("TaskMonitor hadoop response {}:", likisData);
+ } catch (IOException e) {
+ logger.warn("failed to get EntranceTask data");
+ }
+ // 系统监控
+ BigDecimal runningNumber = new BigDecimal((int) likisData.get("runningNumber"));
+ BigDecimal queuedNumber = new BigDecimal((int) likisData.get("queuedNumber"));
+ BigDecimal total = runningNumber.add(queuedNumber);
+
+ HashMap parms = new HashMap<>();
+ parms.put("$url", Configuration.GATEWAY_URL().getValue());
+ int linkisTotalMajor = MonitorConfig.ENTRANCE_TASK_TOTAL_MAJOR.getValue();
+ int linkisTotalMinor = MonitorConfig.ENTRANCE_TASK_TOTAL_MINOR.getValue();
+ if (total.intValue() >= linkisTotalMajor) {
+ // 触发告警Major
+ parms.put("$taskmajor", String.valueOf(linkisTotalMajor));
+ logger.info("TaskMonitor parms {}:", parms);
+ Map ecmResourceAlerts =
+ MonitorAlertUtils.getAlerts(Constants.ALERT_RESOURCE_MONITOR(), parms);
+ PooledImsAlertUtils.addAlert(ecmResourceAlerts.get("12009"));
+
+ } else if (total.intValue() >= linkisTotalMinor) {
+ parms.put("$taskminor", String.valueOf(linkisTotalMinor));
+ logger.info("TaskMonitor parms {}:", parms);
+ Map ecmResourceAlerts =
+ MonitorAlertUtils.getAlerts(Constants.ALERT_RESOURCE_MONITOR(), parms);
+ PooledImsAlertUtils.addAlert(ecmResourceAlerts.get("12008"));
+ }
+ resourceSendToIms();
+ }
+
+ public static void resourceSendToIms() {
+ ServiceInstance[] instances =
+ Sender.getInstances(GovernanceCommonConf.ENTRANCE_SERVICE_NAME().getValue());
+ if (null != instances) {
+ for (ServiceInstance instance : instances) {
+ String serviceInstance = instance.getInstance();
+ try {
+ Map instanceData =
+ MapUtils.getMap(HttpsUntils.getEntranceTask(null, "hadoop", serviceInstance), "data");
+ int runningNumber = 0;
+ int queuedNumber = 0;
+ if (instanceData.containsKey("runningNumber")) {
+ runningNumber = (int) instanceData.get("runningNumber");
+ }
+ if (instanceData.containsKey("queuedNumber")) {
+ queuedNumber = (int) instanceData.get("queuedNumber");
+ }
+ logger.info("ResourceMonitor send index ");
+ List list = new ArrayList<>();
+ list.add(
+ new IndexEntity(
+ serviceInstance,
+ "entrance",
+ ENTRANCE_RUNNING_TASK,
+ HttpsUntils.localHost,
+ String.valueOf(runningNumber)));
+ list.add(
+ new IndexEntity(
+ serviceInstance,
+ "entrance",
+ ENTRANCE_QUEUED_TASK,
+ HttpsUntils.localHost,
+ String.valueOf(queuedNumber)));
+ HttpsUntils.sendIndex(list);
+ } catch (IOException e) {
+ logger.warn("failed to send EcmResource index :" + e);
+ }
+ }
+ }
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryClear.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryClear.java
new file mode 100644
index 0000000000..346ca9cb06
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryClear.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.monitor.config.MonitorConfig;
+import org.apache.linkis.monitor.until.ThreadUtils;
+import org.apache.linkis.monitor.utils.log.LogUtils;
+
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+
+/** * Task: clean up linkis_ps_job_history_group_history data */
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class JobHistoryClear {
+
+ private static final Logger logger = LogUtils.stdOutLogger();
+
+ @Scheduled(cron = "${linkis.monitor.clear.history.task.cron}")
+ public void historyTaskClear() {
+ logger.info("Start to clear_history_task shell");
+ List cmdlist = new ArrayList<>();
+ cmdlist.add("sh");
+ cmdlist.add(MonitorConfig.shellPath + "clear_history_task.sh");
+ logger.info("clear_history_task shell command {}", cmdlist);
+ String exec = ThreadUtils.run(cmdlist, "clear_history_task.sh");
+ logger.info("shell log {}", exec);
+ logger.info("End to clear_history_task shell ");
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryMonitor.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryMonitor.java
new file mode 100644
index 0000000000..c4bd65a90b
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/JobHistoryMonitor.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.monitor.config.MonitorConfig;
+import org.apache.linkis.monitor.constants.Constants;
+import org.apache.linkis.monitor.core.pac.DataFetcher;
+import org.apache.linkis.monitor.core.scanner.AnomalyScanner;
+import org.apache.linkis.monitor.core.scanner.DefaultScanner;
+import org.apache.linkis.monitor.factory.MapperFactory;
+import org.apache.linkis.monitor.jobhistory.JobHistoryDataFetcher;
+import org.apache.linkis.monitor.jobhistory.errorcode.JobHistoryErrCodeRule;
+import org.apache.linkis.monitor.jobhistory.errorcode.JobHistoryErrorCodeAlertSender;
+import org.apache.linkis.monitor.jobhistory.jobtime.JobTimeExceedAlertSender;
+import org.apache.linkis.monitor.jobhistory.jobtime.JobTimeExceedRule;
+import org.apache.linkis.monitor.jobhistory.labels.JobHistoryLabelsAlertSender;
+import org.apache.linkis.monitor.jobhistory.labels.JobHistoryLabelsRule;
+import org.apache.linkis.monitor.jobhistory.runtime.CommonJobRunTimeRule;
+import org.apache.linkis.monitor.jobhistory.runtime.CommonRunTimeAlertSender;
+import org.apache.linkis.monitor.jobhistory.runtime.JobHistoryRunTimeAlertSender;
+import org.apache.linkis.monitor.jobhistory.runtime.JobHistoryRunTimeRule;
+import org.apache.linkis.monitor.until.CacheUtils;
+import org.apache.linkis.monitor.utils.alert.AlertDesc;
+import org.apache.linkis.monitor.utils.alert.ims.ImsAlertDesc;
+import org.apache.linkis.monitor.utils.alert.ims.MonitorAlertUtils;
+import org.apache.linkis.monitor.utils.alert.ims.UserLabelAlertUtils;
+import org.apache.linkis.monitor.utils.log.LogUtils;
+
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.*;
+
+import org.slf4j.Logger;
+
+/**
+ * * jobHistory monitor 1.errorCode: Monitor the error code 2.userLabel: tenant label
+ * monitoring,scan the execution data within the first 20 minutes, and judge the labels field of the
+ * data
+ *
+ *
3.jobResultRunTime: Scan the execution data within the first 20 minutes, and judge the
+ * completed tasks. If the parm field in the jobhistory contains (task.notification.conditions) and
+ * the result of executing the task is (Succeed, Failed, Canceled, Timeout, ALL) any one of them, an
+ * alarm is triggered and the result of the job is that it has ended. All three are indispensable
+ *
+ *
4.jobResultRunTimeForDSS: Scan the execution data within the first 20 minutes, scan the tasks
+ * that have been marked for notification, if the task has ended, a notification will be initiated
+ *
+ *
5.jobHistoryUnfinishedScan: monitor the status of the execution task, scan the data outside 12
+ * hours and within 24 hours
+ */
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class JobHistoryMonitor {
+
+ private static final Logger logger = LogUtils.stdOutLogger();
+ private static final long backtrackNum = 1000000L;
+
+ @Scheduled(cron = "${linkis.monitor.jobHistory.finished.cron}")
+ public void jobHistoryFinishedScan() {
+ long intervalMs = 20 * 60 * 1000;
+ long maxIntervalMs = Constants.ERRORCODE_MAX_INTERVALS_SECONDS() * 1000;
+ long endTime = System.currentTimeMillis();
+ long startTime = endTime - intervalMs;
+ long realIntervals = Math.min(endTime - startTime, maxIntervalMs);
+ AnomalyScanner scanner = new DefaultScanner();
+ boolean shouldStart = false;
+ long id;
+ if (null == CacheUtils.cacheBuilder.getIfPresent("jobHistoryId")) {
+ long maxId = MapperFactory.getJobHistoryMapper().selectMaxId();
+ long beginId = 0L;
+ if (maxId > backtrackNum) {
+ beginId = maxId - backtrackNum;
+ }
+ id = MapperFactory.getJobHistoryMapper().selectIdByHalfDay(beginId);
+ CacheUtils.cacheBuilder.put("jobHistoryId", id);
+ } else {
+ id = CacheUtils.cacheBuilder.getIfPresent("jobHistoryId");
+ }
+ List fetchers = generateFetchersfortime(startTime, endTime, id, "updated_time");
+ if (fetchers.isEmpty()) {
+ logger.warn("generated 0 dataFetchers, plz check input");
+ return;
+ }
+ // errorCode
+ try {
+ Map errorCodeAlerts =
+ MonitorAlertUtils.getAlerts(Constants.SCAN_PREFIX_ERRORCODE(), null);
+
+ if (errorCodeAlerts == null || errorCodeAlerts.size() == 0) {
+ logger.info("[INFO] Loaded 0 errorcode alert from alert-rule properties file.");
+ } else {
+ logger.info(
+ "[INFO] Loaded {} errorcode alert from alert-rules properties file.",
+ errorCodeAlerts.size());
+ shouldStart = true;
+ addIntervalToImsAlerts(errorCodeAlerts, realIntervals);
+ JobHistoryErrCodeRule jobHistoryErrCodeRule =
+ new JobHistoryErrCodeRule(
+ errorCodeAlerts.keySet(), new JobHistoryErrorCodeAlertSender(errorCodeAlerts));
+ scanner.addScanRule(jobHistoryErrCodeRule);
+ }
+ } catch (Exception e) {
+ logger.warn("Jobhistory Monitor ErrorCode Faily: " + e.getMessage());
+ }
+ // userLabel
+ try {
+ Map userLabelAlerts =
+ UserLabelAlertUtils.getAlerts(Constants.USER_LABEL_MONITOR(), "");
+ if (userLabelAlerts == null || userLabelAlerts.size() == 0) {
+ logger.info("[INFO] Loaded 0 alerts userLabel alert-rule from alert properties file.");
+ } else {
+ logger.info(
+ "[INFO] Loaded {} alerts userLabel alert-rules from alert properties file.",
+ userLabelAlerts.size());
+ shouldStart = true;
+ JobHistoryLabelsRule jobHistoryLabelsRule =
+ new JobHistoryLabelsRule(new JobHistoryLabelsAlertSender());
+ scanner.addScanRule(jobHistoryLabelsRule);
+ }
+ } catch (Exception e) {
+ logger.warn("Jobhistory Monitor UserLabel Faily: " + e.getMessage());
+ }
+ // jobResultRunTime
+ try {
+ Map jobResultAlerts =
+ MonitorAlertUtils.getAlerts((Constants.SCAN_PREFIX_ERRORCODE()), null);
+ if (jobResultAlerts == null || jobResultAlerts.size() == 0) {
+ logger.info("[INFO] Loaded 0 jobResult alert from alert-rule properties file.");
+ } else {
+ logger.info(
+ "[INFO] Loaded {} alerts jobResult alert-rules from alert properties file.",
+ jobResultAlerts.size());
+ shouldStart = true;
+ JobHistoryRunTimeRule jobHistoryRunTimeRule =
+ new JobHistoryRunTimeRule(new JobHistoryRunTimeAlertSender());
+ scanner.addScanRule(jobHistoryRunTimeRule);
+ }
+ } catch (Exception e) {
+ logger.warn("Jobhistory Monitor JobResultRunTime Faily: " + e.getMessage());
+ }
+ // jobResultRunTimeForDSS
+ try {
+ Map dssJobResultAlerts =
+ MonitorAlertUtils.getAlerts((Constants.SCAN_PREFIX_ERRORCODE()), null);
+ if (dssJobResultAlerts == null || dssJobResultAlerts.size() == 0) {
+ logger.info("[INFO] Loaded 0 jobResult alert from alert-rule properties file.");
+ } else {
+ logger.info(
+ "[INFO] Loaded {} alerts jobResult alert-rules from alert properties file.",
+ dssJobResultAlerts.size());
+ shouldStart = true;
+
+ CommonJobRunTimeRule commonJobRunTimeRule =
+ new CommonJobRunTimeRule(new CommonRunTimeAlertSender());
+ scanner.addScanRule(commonJobRunTimeRule);
+ }
+ } catch (Exception e) {
+ logger.warn("Jobhistory JobResultRunTimeForDSS ErrorCode Faily: " + e.getMessage());
+ }
+ run(scanner, fetchers, shouldStart);
+ }
+
+ @Scheduled(cron = "${linkis.monitor.jobHistory.timeout.cron}")
+ public void jobHistoryUnfinishedScan() {
+ long id =
+ Optional.ofNullable(CacheUtils.cacheBuilder.getIfPresent("jobhistoryScan"))
+ .orElse(MonitorConfig.JOB_HISTORY_TIME_EXCEED.getValue());
+ long intervalMs = Constants.TIMEOUT_INTERVALS_SECONDS() * 1000;
+ long maxIntervalMs = Constants.ERRORCODE_MAX_INTERVALS_SECONDS() * 1000;
+ long endTime = System.currentTimeMillis();
+ long startTime = endTime - intervalMs;
+ long realIntervals = Math.min(endTime - startTime, maxIntervalMs);
+ AnomalyScanner scanner = new DefaultScanner();
+ boolean shouldStart = false;
+ List fetchers =
+ generateFetchers(startTime, endTime, maxIntervalMs, id, "created_time");
+ if (fetchers.isEmpty()) {
+ logger.warn("generated 0 dataFetchers, plz check input");
+ return;
+ }
+ Map jobTimeAlerts =
+ MonitorAlertUtils.getAlerts((Constants.SCAN_PREFIX_UNFINISHED_JOBTIME_EXCEED_SEC()), null);
+ if (jobTimeAlerts == null || jobTimeAlerts.size() == 0) {
+ logger.info("[INFO] Loaded 0 alerts jobtime alert-rule from alert properties file.");
+ } else {
+ logger.info(
+ "[INFO] Loaded {} alerts jobtime alert-rules from alert properties file.",
+ jobTimeAlerts.size());
+ shouldStart = true;
+ addIntervalToImsAlerts(jobTimeAlerts, realIntervals);
+ JobTimeExceedRule jobTimeExceedRule =
+ new JobTimeExceedRule(
+ jobTimeAlerts.keySet(), new JobTimeExceedAlertSender(jobTimeAlerts));
+ scanner.addScanRule(jobTimeExceedRule);
+ }
+ run(scanner, fetchers, shouldStart);
+ }
+
+ public static void run(AnomalyScanner scanner, List fetchers, Boolean shouldStart) {
+ if (shouldStart) {
+ scanner.addDataFetchers(fetchers);
+ scanner.run();
+ }
+ }
+
+ private static List generateFetchers(
+ long startTime, long endTime, long maxIntervalMs, long id, String timeType) {
+ List ret = new ArrayList<>();
+ long pe = endTime;
+ long ps;
+ while (pe > startTime) {
+ ps = Math.max(pe - maxIntervalMs, startTime);
+ String[] fetcherArgs =
+ new String[] {String.valueOf(ps), String.valueOf(pe), String.valueOf(id), timeType};
+ ret.add(new JobHistoryDataFetcher(fetcherArgs, MapperFactory.getJobHistoryMapper()));
+ logger.info(
+ "Generated dataFetcher for startTime: " + new Date(ps) + ". EndTime: " + new Date(pe));
+ pe = pe - maxIntervalMs;
+ }
+ return ret;
+ }
+
+ private static List generateFetchersfortime(
+ long startTime, long endTime, long id, String timeType) {
+ List fetchers = new ArrayList<>();
+ String[] fetcherArgs =
+ new String[] {
+ String.valueOf(startTime), String.valueOf(endTime), String.valueOf(id), timeType
+ };
+ fetchers.add(new JobHistoryDataFetcher(fetcherArgs, MapperFactory.getJobHistoryMapper()));
+ logger.info(
+ "Generated dataFetcher for startTime: "
+ + new Date(startTime)
+ + ". EndTime: "
+ + new Date(endTime));
+ return fetchers;
+ }
+
+ private static void addIntervalToImsAlerts(Map alerts, long realIntervals) {
+ for (AlertDesc alert : alerts.values()) {
+ if (!(alert instanceof ImsAlertDesc)) {
+ logger.info("[warn] ignore wrong alert" + alert);
+ } else {
+ ((ImsAlertDesc) alert).hitIntervalMs_$eq(realIntervals);
+ }
+ }
+ }
+}
diff --git a/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/ResourceMonitor.java b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/ResourceMonitor.java
new file mode 100644
index 0000000000..ac3046501c
--- /dev/null
+++ b/linkis-extensions/linkis-et-monitor/src/main/java/org/apache/linkis/monitor/scheduled/ResourceMonitor.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.monitor.scheduled;
+
+import org.apache.linkis.common.utils.ByteTimeUtils;
+import org.apache.linkis.monitor.config.MonitorConfig;
+import org.apache.linkis.monitor.constants.Constants;
+import org.apache.linkis.monitor.entity.IndexEntity;
+import org.apache.linkis.monitor.until.HttpsUntils;
+import org.apache.linkis.monitor.utils.alert.AlertDesc;
+import org.apache.linkis.monitor.utils.alert.ims.MonitorAlertUtils;
+import org.apache.linkis.monitor.utils.alert.ims.PooledImsAlertUtils;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** * Monitor the usage of ECM resources for monitoring and metrics reporting */
+@Component
+@PropertySource(value = "classpath:linkis-et-monitor.properties", encoding = "UTF-8")
+public class ResourceMonitor {
+
+ private static final Logger logger = LoggerFactory.getLogger(ResourceMonitor.class);
+
+ @Scheduled(cron = "${linkis.monitor.ecm.resource.cron}")
+ public void ecmResourceTask() {
+ Map resultmap = null;
+ AtomicReference tenant = new AtomicReference<>("租户标签:公共资源");
+ AtomicReference totalMemory = new AtomicReference<>(0.0);
+ AtomicReference totalInstance = new AtomicReference<>(0.0);
+ AtomicReference totalCores = new AtomicReference<>(0.0);
+ try {
+ resultmap = HttpsUntils.sendHttp(null, null);
+ logger.info("ResourceMonitor response {}:", resultmap);
+ } catch (IOException e) {
+ logger.warn("failed to get EcmResource data");
+ }
+ // got interface data
+ Map>> data = MapUtils.getMap(resultmap, "data");
+ List