Ganglia监控MySQL
1、下载mysql监控脚本: [root@node1 app]# wget http://www.javabloger.com/att/gmetric-mysql.sh
2、修改脚本中的msyql用户名和密码
3、该脚本54和58号行机器不同需要进行修改(未查明原因),可以在$[ ]和$(())间替换。 我的修改成DELTA_VALUE=$[ NEW_VALUE-PREVIOUS_VALUE ]、DELTA_TIMESTAMP=$[ NEW_TIMESTAMP-PREVIOUS_TIMESTAMP ]就好了。去掉了[]中的$
4、在crond执行该脚本
5、重启gmetad
附gmetric-mysql.sh
[root@node1 192.168.228.156]# cat /etc/ganglia/gmetric-mysql.sh
#! /bin/bash
#
# Get statistics from MySQL and feed them into Ganglia for monitoring.
#
# To use, simply adjust the path to gmetric and mysql credentials as appropriate.
#
# Author: David Winterbottom (david.winterbottom@gmail.com)
# Site: http://codeinthehole.com # Config
declare -r GMETRIC=/usr/bin/gmetric
declare -r NEW_DATA_FILE=/tmp/mysql-stats.new
declare -r OLD_DATA_FILE=/tmp/mysql-stats.old
declare -r MYSQL_USER="root"
declare -r MYSQL_PASSWORD="123456" # Sanity checks
if test -z "$GMETRIC" ; then
printf "The command $GMETRIC is not available";
exit 192
fi # Function for submiting metrics
function record_value
{
if [ $# -lt 1 ]; then
printf "You must specify a look-up value\n"
exit 192
fi
LOOKUP_VAR=$1
GANGLIA_NAME=${2-unspecified}
GANGLIA_TYPE=${3-float}
GANGLIA_UNITS=${4-units}
GANGLIA_VALUE=`grep "$LOOKUP_VAR[^_]" "$NEW_DATA_FILE" | awk '{print $2}'`
printf " * $GANGLIA_NAME: $GANGLIA_VALUE\n"
$GMETRIC --type "$GANGLIA_TYPE" --name "$GANGLIA_NAME" --value $GANGLIA_VALUE --unit "$GANGLIA_UNITS"
} # Function for submitting delta metrics
function record_value_rate
{
if [ $# -lt 1 ]; then
printf "You must specify a look-up value\n"
exit 192
fi
MYSQL_VAR=$1
GANGLIA_NAME=${2-unspecified}
GANGLIA_TYPE=${3-float}
GANGLIA_UNITS=${4-"per second"} # Get values from old and new files
PREVIOUS_VALUE=`grep "$MYSQL_VAR[^_]" "$OLD_DATA_FILE" | awk '{print $2}'`
NEW_VALUE=`grep "$MYSQL_VAR[^_]" "$NEW_DATA_FILE" | awk '{print $2}'`
# DELTA_VALUE=$[ $NEW_VALUE-$PREVIOUS_VALUE ]
DELTA_VALUE=$[ NEW_VALUE-PREVIOUS_VALUE ]
# DELTA_TIMESTAMP=$[ NEW_TIMESTAMP-PREVIOUS_TIMESTAMP ]
PREVIOUS_TIMESTAMP=`date -r "$OLD_DATA_FILE" +%s`
NEW_TIMESTAMP=`date -r "$NEW_DATA_FILE" +%s`
# DELTA_TIMESTAMP=$[ $NEW_TIMESTAMP-$PREVIOUS_TIMESTAMP ]
DELTA_TIMESTAMP=$[ NEW_TIMESTAMP-PREVIOUS_TIMESTAMP ]
if [ $DELTA_VALUE -lt 0 ] || [ $DELTA_TIMESTAMP -lt 0 ]; then
# Something strange here - MYSQL may just have started. Ignore for now
printf "Weird data value - skipping\n"
else
# Need to pipe to bc to perform floating point operations
DELTA_RATE=`echo "scale=4; $DELTA_VALUE/$DELTA_TIMESTAMP" | bc -l`
printf " * $GANGLIA_NAME -- Previous value: $PREVIOUS_VALUE, new value: $NEW_VALUE, delta: $DELTA_VALUE, previous timestamp: $PREVIOUS_TIMESTAMP, new timestamp: $NEW_TIMESTAMP, delta: $DELTA_TIMESTAMP, $DELTA_RATE per second\n"
$GMETRIC --type "$GANGLIA_TYPE" --name "$GANGLIA_NAME" --value $DELTA_VALUE --unit "$GANGLIA_UNITS"
fi
} # Read MySQL statistics into a temporary file
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --execute "SHOW GLOBAL STATUS" > "$NEW_DATA_FILE" # Submit metrics
record_value_rate "Connections" "MYSQL_CONNECTIONS" "float" "Connections/sec"
record_value_rate "Com_update" "MYSQL_UPDATE_QUERIES" "float" "Queries/sec"
record_value_rate "Com_select" "MYSQL_SELECT_QUERIES" "float" "Queries/sec"
record_value_rate "Com_insert" "MYSQL_INSERT_QUERIES" "float" "Queries/sec"
record_value_rate "Com_delete" "MYSQL_DELETE_QUERIES" "float" "Queries/sec"
record_value_rate "Created_tmp_tables" "MYSQL_CREATED_TMP_TABLES" "float" "Tables created/sec"
record_value_rate "Slow_queries" "MYSQL_SLOW_QUERIES" "float" "Queries/sec"
record_value_rate "Qcache_hits" "MYSQL_QUERY_CACHE_HITS" "float" "Hits/sec"
record_value "Qcache_queries_in_cache" "MYSQL_QUERIES_IN_CACHE" "float" "Queries"
record_value_rate "Questions" "MYSQL_QUESTIONS" "float" "Questions/sec"
record_value_rate "Threads_connected" "MYSQL_THREADS_CONNECTED" "float" "Threads connected/sec"
record_value "Threads_running" "MYSQL_THREADS_RUNNING" "float" "Threads running" # Copy data
cp "$NEW_DATA_FILE" "$OLD_DATA_FILE"
6、监控效果:
Ganglia监控MySQL的更多相关文章
- ganglia监控自己定义metric实践
Ganglia监控系统是UC Berkeley开源的一个项目,设计初衷就是要做好分布式集群的监控.监控层面包含资源层面和业务层面,资源层面包含cpu.memory.disk.IO.网络负载等,至于业务 ...
- 使用ganglia监控hadoop及hbase集群
一.Ganglia简介 Ganglia 是 UC Berkeley 发起的一个开源监视项目,设计用于测量数以千计的节点.每台计算机都运行一个收集和发送度量数据(如处理器速度.内存使用量等)的名为 gm ...
- 分布式监控系统Zabbix-3.0.3-完整安装记录(7)-使用percona监控MySQL
前面已经介绍了分布式监控系统Zabbix-3.0.3-完整安装记录(2)-添加mysql监控,但是没有提供可以直接使用的Key,太过简陋,监控效果不佳.要想更加仔细的监控Mysql,业内同学们都会选择 ...
- Zabbix监控mysql performance
介绍 zabbix监控mysql性能,使用zabbix自带的mysql监控模板,可以监控以下内容OPS(增删改查).mysql慢查询数量.mysql请求\响应流量带宽 配置 新建mysql监控用户 G ...
- 监控mysql各种选项
安装mysql之后,需要对mysql服务进行监控. nagios开源自带的check_mysql 对 mysql 的slave 机监控倒是不错.但是对数据库主机监控就略显不足了. 使用一个监控 ...
- zabbix通过第三方插件percona监控mysql数据库
zabbix通过第三方插件percona监控mysql数据库 ...
- zabbix利用自带的模板监控mysql数据库
zabbix利用自带的模板监控mysql数据库 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 有些东西你不会的时候觉得它特别难,但是当你去做的时候就发现如此的简单~zabbix功能 ...
- 详解 Spotlight on MySQL监控MySQL服务器
前一章详解了Spotlight on Unix 监控Linux服务器 ,今天再来看看Spotlight on MySQL怎么监控MySQL服务器. 注:http://www.cnblogs.com/J ...
- cacti监控mysql
cacti监控mysql 2013-09-25 16:21:43 分类: LINUX 原文地址:cacti监控mysql 作者:baochenggood cacti监控mysql 1 下载cacti监 ...
随机推荐
- wordpress 天气插件开发
<?php /* * author by:wordpress教程网(http://www.wpnoob.cn) * url: * */ class weatherWidget extends W ...
- Centos 6.5系统下搭建Git服务器--失败历程
参考博客 http://www.51hei.com/bbs/dpj-28077-1.html http://www.linuxidc.com/Linux/2014-06/103885p2.htm ht ...
- Demo3使用bootstrap
利用Ajax实现信息获取,使用bootstrap来美化页面,果然很强大. 将bootstrap的API添加到引用.如图程序源码结构: 页面源码: <!DOCTYPE html PUBLIC &q ...
- mongodb的连接和开启安全验证
首先是启动mongodb a.打开cmd,cd进入mongodb的安装目录下的bin目录下面,执行 mongod --dbpath D:\MongoDBdata(数据存放的目录) 或者将mongodb ...
- intellij idea exclude from compile后怎么加回来
File->Settings-> Build,Execution,Deployment->Compiler-> Execludes
- 用 CSS 做轮播图
对于用 css 实现一个轮播图的缘由,是那时候刚开始接触前端,完全还不懂 js.但是有一个项目(就是一个用来应付面试的作品)需要做一个轮播的效果,当时第一反应就是用 css3 自定义动画 -webki ...
- PostgreSQL auto_explain
The auto_explain module provides a means for logging execution plans of slow statements automaticall ...
- Lintcode: Segment Tree Modify
For a Maximum Segment Tree, which each node has an extra value max to store the maximum value in thi ...
- [原创]java WEB学习笔记82:Hibernate学习之路---映射 一对多关联关系,配置,CRUD方法测试及注意点
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- 也不知怎么了LVS.SH找不到,网上搜了一篇环境搭配CENTOS下面的高可用 参考
系统环境: ************************************************************ 两台服务器都装了 CentOS-5.2-x86_64 系统 Vir ...