首页 > 数据库 > MySQL > 正文

mysql数据收集shell脚本

2024-07-24 12:40:14
字体:
来源:转载
供稿:网友

#!/bin/sh
INTERVAL=5
PASSWORD='-ucncn -p123456'
PREFIX=$INTERVAL-sec-status
RUNFILE=/www/logs/mysql_bench
mysql -e 'SHOW GLOBAL VARIABLES' $PASSWORD >> mysql-variables
while test -e $RUNFILE; do
    file=$(date +%F_%I)
    sleep=$(date +%s.%N | awk "{print $INTERVAL - (/$1 % $INTERVAL)}")
    sleep $sleep
    ts="$(date + "TS %s.%N %F %T")"
    loadavg="$(uptime)"
    echo "$ts $loadavg" >> $PREFIX-${file}-status
    mysql -e 'SHOW GLOBAL STATUS' $PASSWORD >> $PREFIX-${file}-status &
    echo "$ts $loadavg" >> $PREFIX-${file}-innodbstatus
    echo -e 'SHOW ENGINE INNODB STATUS/G' $PASSWORD >> $PREFIX-${file}-innodbstatus  &
    echo "$ts $loadavg" >> $PREFIX-${file}-processlist
    mysql -e 'SHOW FULL PROCESSLIST/G' $PASSWORD >> $PREFIX-${file}-processlist & echo $ts
done
echo Exiting because $RUNFILE does not exist.

这个shell脚本很简单,但提供了一个有效的收集状态和性能数据的框架。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表