设为首页 收藏本站
查看: 823|回复: 0

[经验分享] Mysql监控

[复制链接]

尚未签到

发表于 2018-9-28 08:45:50 | 显示全部楼层 |阅读模式
#!/bin/bash  
#check mysql_status
  
MYSQL_USER='root'
  
MYSQL_HOST='127.0.0.1'
  
MYSQL_PORT='3306'
  
MYSQL_PWD='123'
  
MYSQL_CONN="/usr/local/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
  
if [ $# -ne "1" ];then
  
    echo "error error!"
  
fi
  
case $1 in
  
    Uptime)
  
        result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"`              #mysql启动时间累加,mysql工作时间
  
        echo $result
  
        ;;
  
    Com_update)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3`   #执行update 操作的次数
  
        echo $result
  
        ;;
  
    Slow_queries)
  
        result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"`                  #慢查询的次数
  
        echo $result
  
        ;;
  
    Com_select)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`  #执行select 操作的次数,一次查询只累加1
  
        echo $result
  
                ;;
  
    Com_rollback)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`  #事务回滚情况,对于回滚操作非常频繁的数据库,可能意味着应用编写存在问题
  
                echo $result
  
                ;;
  
    Questions)
  
        result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` #初始的查询操作的总数
  
                echo $result
  
                ;;
  
    Com_insert)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`  #执行insert 操作的次数,对于批量插入的insert 操作,只累加一次;
  
                echo $result
  
                ;;
  
    Com_delete)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` #执行delete 操作的次数
  
                echo $result
  
                ;;
  
    Com_commit)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`  #事务提交次数
  
                echo $result
  
                ;;
  
    Bytes_sent)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`  #请求流量带宽,发送
  
                echo $result
  
                ;;
  
    Bytes_received)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` #响应流量带宽,接收
  
                echo $result
  
                ;;
  
    Com_begin)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
  
                echo $result
  
                ;;
  
    Innodb_rows_read)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_read"|cut -d"|" -f3`    #Innodb中select 查询返回的行数
  
                echo $result
  
             ;;
  
    Innodb_rows_inserted)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_inserted"|cut -d"|" -f3` #执行Insert 操作插入的行数
  
                echo $result
  
        ;;
  
    Innodb_rows_updated)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_updated"|cut -d"|" -f3` #执行update 操作更新的行数
  
                echo $result
  
        ;;
  
    Innodb_rows_deleted)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_deleted"|cut -d"|" -f3` #执行update 操作更新的行数
  
                echo $result
  
        ;;
  
    Qcache_free_memory)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Qcache_free_memory"|cut -d"|" -f3`  #缓存中的空闲内存
  
                echo $result
  
                ;;
  
    Qcache_hits)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Qcache_hits"|cut -d"|" -f3`  #每次查询在缓存中命中时就增大
  
                echo $result
  
                ;;
  
    Qcache_inserts)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Qcache_inserts"|cut -d"|" -f3`  #每次插入一个查询时就增大。命中次数除以插入次数就是不中比率
  
                echo $result
  
                ;;
  
    Threads_connected)
  
        result=`${MYSQL_CONN} extended-status |grep -w "Threads_connected"|cut -d"|" -f3`  #当前连接数
  
                echo $result
  
                ;;
  
        *)
  
        echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin||Innodb_rows_read|Innodb_rows_inserted|Innodb_rows_updated|Innodb_rows_deleted|Qcache_free_memory|Qcache_hits|Qcache_inserts|Threads_connected)"
  
        ;;
  
esac



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-603053-1-1.html 上篇帖子: 安装MySQL Enterprise Monitor-DBA的天空 下篇帖子: MySQL 备份和还原
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表