GBase 8a
运维管理
文章
查询各管理节点任务并写表
发表于2025-01-03 13:26:0455次浏览5个评论
建表:
create table session_status_info(
vc varchar(64) comment 'vc名字',
start_time datetime comment '下发时间',
collection_time timestamp comment '采集时间',
manage_coorip varchar(64) comment '运行节点ip',
session_id BIGINT(4) comment '会话id',
username varchar(128) comment '执行用户',
client_ip varchar(64) comment '客户端ip',
keep_duration int(7) comment '运行时间',
command varchar(16) comment '状态',
info longtext comment 'sql'
);脚本:
#!/bin/bash
#######################################
# version:20241024 #
# arrange:crontab 定时任务部署 #
# function:获取管理节点任务并写入到表中 #
#######################################
source /home/gbase/.bashrc
workdir=$(cd `dirname $0`;pwd)
cd $workdir
#固定参数
pss=`echo "WGlhbiMyOTQ2I3NhCg=="|base64 -d`
tmp=$workdir/sel_coor_processlist.tmp
localhost_ip=`/usr/sbin/ifconfig bond1 |grep netmask |awk '{print $2}'`
insert_table='vc00001.gclusterdb.session_status_info'
#采集参数
coor_list=`gcadmin |grep oordinator | grep OPEN |awk '{print $4}'`
for coor_ip in ${coor_list}; do
gccli -ugbase_wh -p${pss} -h${coor_ip} -e"select CONCAT(ID,':!:',USER,':!:',HOST,':!:',COMMAND,':!:',VC,':!:',START_TIME,':!:',info,':!:',time,':!:') from vc00001.information_schema.processlist where COMMAND!='Sleep' and user not in ('gbase_wh','gbase','root','system','event_scheduler');" |grep -iv "CONCAT(ID," > ${tmp}
sed -i "s/\\\n//g" ${tmp}
sed -i "s/\\\t//g" ${tmp}
sed -i "s/\\\r//g" ${tmp}
while IFS= read -r data_sql
do
ID=`echo ${data_sql} |awk -F':!:' '{print $1}'`
USER=`echo ${data_sql} |awk -F':!:' '{print $2}'`
HOST=`echo ${data_sql} |awk -F':!:' '{print $3}' | awk -F':' '{print $1}'`
COMMAND=`echo ${data_sql} |awk -F':!:' '{print $4}'`
VC=`echo ${data_sql} |awk -F':!:' '{print $5}'`
START_TIME=`echo ${data_sql} |awk -F':!:' '{print $6}'`
INFO=`echo ${data_sql} |awk -F':!:' '{print $7}' |sed "s/'//g"`
keep_duration=`echo ${data_sql} |awk -F':!:' '{print $8}'`
gccli -ugbase_wh -p${pss} -h${localhost_ip} -vvv -e"insert into ${insert_table}(vc,start_time,manage_coorip,session_id,username,client_ip,keep_duration,command,info) values('${VC}','${START_TIME}','${coor_ip}','${ID}','${USER}','${HOST}','${keep_duration}','${COMMAND}','${INFO}');"
done < "${tmp}"
done在crontab中按需添加定时任务即可。
热门帖子
- 12025-12-01浏览数:182759
- 22023-05-09浏览数:25051
- 42023-09-25浏览数:18521
- 52020-05-11浏览数:17526