GBase 8a
运维管理
文章

获取各管理节点任务并写表,供租户客户使用

发表于2024-12-02 10:40:0078次浏览0个评论

先申请对应表权限,create,insert,drop等

建表以及shell脚本,定时用crontab解决:

建表:
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'
);
shell脚本
#!/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

评论

登录后才可以发表评论