您好,欢迎访问一九零五行业门户网

Ganglia监控MySQL

1、下载mysql监控脚本: gmetric-mysql.sh 免费下载地址在 http://linux.linuxidc.com/ 用户名与密码都是www.linuxidc.com 具体下
1、下载mysql监控脚本: gmetric-mysql.sh
免费下载地址在
用户名与密码都是
具体下载目录在 /2014年资料/4月/25日/ganglia监控mysql
下载方法见
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: 
# 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 3.1.x下扩展python模块(翻译自官方wiki)
使用ganglia监控hadoop集群
在vmware workstation的ubuntu下安装和配置hadoop与ganglia
ganglia安装部署之一建立grid
ganglia 极其简单安装教程yum版
ganglia快速开始向导(翻译自官方wiki)
centos集群上安装ganglia-3.6.0监控hadoop-2.2.0和hbase-0.96.0
本文永久更新链接地址:

其它类似信息

推荐信息