Chinaunix首页 | 论坛 | 博客
  • 博客访问: 638397
  • 博文数量: 110
  • 博客积分: 3808
  • 博客等级: 中校
  • 技术积分: 1930
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 14:32
个人简介

声的伟大!

文章分类

全部博文(110)

文章存档

2014年(1)

2013年(2)

2012年(12)

2011年(81)

2010年(14)

分类: LINUX

2011-11-24 15:31:48

此文主要讲述了cacti利用snmpdiskio 监控服务器磁盘 IO的方法,cacti的安装这里不再累述


环境
cacti-0.8.7g
snmpdiskio-0.9.6

安装步骤
监控机上操作:
1.将下载的snmpdiskio-0.9.4.tar.gz上传到cacit服务器上,解压缩,将partition.xml拷

贝resource/snmp_queries下.
# tar xvf snmpdiskio-0.9.4.tar.gz
# cd snmpdiskio-0.9.4
# cp partition.xml ../cacti/resource/snmp_queries/

2.在cacti服务器的web界面下导入cacti_graph_template_disk_io_bytessec.xml模板
如图所示:


被监控机上操作:
1.将下载的snmpdiskio-0.9.4.tar.gz上传到被监控机上,解压缩,将目录下可执行文件

snmpdisk拷贝/usr/local/bin/下
# tar xvf snmpdiskio-0.9.4.tar.gz
# cd snmpdiskio-0.9.4
# cp snmpdiskio /usr/local/bin/

注:如果监控机也需要检测磁盘IO的话,做同样处理

2.由于9.4太老不支持2.6内核,需要修改,出自

中dverlaeckt 的“code”
# vim /usr/local/bin/snmpdiskio

#!/bin/bash
# $Id: snmpdiskio,v 1.5 2008/01/31 21:19:50 dverlaeckt Exp $
# snmpdiskio v0.9.6 (c) 2008 Dieter Verlaeckt
# snmpdiskio v0.9.5 (c) 2007 Pablo Destefanis
# snmpdiskio v0.9.4 (c) 2006 Mikael Fridh

# Fields in /proc/partitions (kernel 2.4)
# major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running

use aveq

# Fields in /proc/diskstats (kernel 2.6) for disks (i.e. hda)
# major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use

aveq

# Fields in /proc/diskstats (kernel 2.6) for partitions (i.e. hda1)
# major minor name rio rsect wio wsect

# InBlocks = sectors written to disk
# OutBlocks = sectors read from disk

# Set default procfile for kernel 2.4
PROCFILE="/proc/partitions"
MODE="linux24"

# Probably kernel 2.6:
if [ -f /proc/diskstats ]; then
    PROCFILE=/proc/diskstats
    MODE="linux26"
fi


function hdNum()
{
        awk ' BEGIN { num=0 } $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { num++ } END {

print num } ' $PROCFILE
}

function hdIndex()
{
        awk ' BEGIN { num=0 } $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { num++; print

num } ' $PROCFILE
}

function hdDescr()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { printf "%s\n", $3 }'

$PROCFILE
        else
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ { printf "%s\n", $4 }'

$PROCFILE
        fi
}

function hdInBlocks()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 7 { printf

"%.0f\n", $7 * 512 }
                      $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 14 { printf

"%.0f\n", $10 * 512 } ' $PROCFILE
        else
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 15 { printf

"%.0f\n", $11 * 512 } ' $PROCFILE
        fi
}

function hdOutBlocks()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 7 { printf

"%.0f\n", $5 * 512 }
                      $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 14 { printf

"%.0f\n", $6 * 512 } ' $PROCFILE
        else
                awk ' $1 ~ /[0-9]+/ && $2 ~ /[0-9]+/ && NF == 15 { printf

"%.0f\n", $7 * 512 } ' $PROCFILE
        fi
}

function usage()
{
        cat <<-EOUSAGE
Usage: $0
EOUSAGE
}

if [ 1 -ne $# ]; then
        usage
        exit 1
fi

case $1 in
        hdNum|hdIndex|hdDescr|hdInBlocks|hdOutBlocks)
                $1
        ;;
        'hdNum')
                hdNum
        ;;
        'hdIndex')
                hdIndex
        ;;
        'hdDescr')
                hdDescr
        ;;
        'hdInBlocks')
                hdInBlocks
        ;;
        'hdOutBlocks')
                hdOutBlocks
        ;;
        *)
                usage
                exit 1
        ;;
esac

exit 0


3.修改snmpd.conf配置文件,添加以下内容
exec .1.3.6.1.4.1.2021.54 hdNum /usr/local/bin/snmpdiskio hdNum
exec .1.3.6.1.4.1.2021.55 hdIndex /usr/local/bin/snmpdiskio hdIndex
exec .1.3.6.1.4.1.2021.56 hdDescr /usr/local/bin/snmpdiskio hdDescr
exec .1.3.6.1.4.1.2021.57 hdInBlocks /usr/local/bin/snmpdiskio hdInBlocks
exec .1.3.6.1.4.1.2021.58 hdOutBlocks /usr/local/bin/snmpdiskio hdOutBlocks

4.重启snmp服务
# service snmpd restart

5.测试,正常会出现如下内容
# snmpwalk -v 2c -c public 192.168.88.128 .1.3.6.1.4.1.2021.58
UCD-SNMP-MIB::ucdavis.58.1.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.58.2.1 = STRING: "hdOutBlocks"
UCD-SNMP-MIB::ucdavis.58.3.1 = STRING: "/usr/local/bin/snmpdiskio hdOutBlocks"
UCD-SNMP-MIB::ucdavis.58.100.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.58.101.1 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.2 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.3 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.4 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.5 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.6 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.7 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.8 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.9 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.10 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.11 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.12 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.13 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.14 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.15 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.16 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.17 = STRING: "1666025984"
UCD-SNMP-MIB::ucdavis.58.101.18 = STRING: "1154048"
UCD-SNMP-MIB::ucdavis.58.101.19 = STRING: "1278602240"
UCD-SNMP-MIB::ucdavis.58.101.20 = STRING: "386118144"
UCD-SNMP-MIB::ucdavis.58.101.21 = STRING: "1277166592"
UCD-SNMP-MIB::ucdavis.58.101.22 = STRING: "1270784"
UCD-SNMP-MIB::ucdavis.58.101.23 = STRING: "73728"
UCD-SNMP-MIB::ucdavis.58.101.24 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.101.25 = STRING: "0"
UCD-SNMP-MIB::ucdavis.58.102.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.58.103.1 = ""

现在,添加设备
Devices-->Add,在Associated Data Queries选择SNMP - Disk Statistics ,如图


接下来*Create Graphs for this Host,如图


获得图像如下


阅读(3879) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~