yanfei 发表于 2017-4-20 07:43:51

cacti利用snmpdiskio 监控服务器磁盘IO监控

平台
CentOS5.4
cacti-0.8.7e(cacti-0.8.7g已经测试安装正常)
snmpdiskio-0.9.6
安装
安装cacti平台就不提了,网上多得是,今天主要是如何添加disk io监控的模板.
1.       将下载的snmpdiskio-0.9.4.tar.gz上传到cacit服务器上,解压缩,将partition.xml拷贝resource/snmp_queries下.
tar zxvf snmpdiskio-0.9.4.tar.gz
cp snmpdiskio-0.9.4 /usr/local/apache2/htdocs/cacti/resource/snmp_queries/
2.       在cacti服务器的web界面下导入cacti_data_query_snmp_disk_statistics.xml和cacti_graph_template_disk_io_bytessec.xml
     

3.       将下载的snmpdiskio-0.9.4.tar.gz上传到被监控机上,解压缩,将目录下可执行文件snmpdisk拷贝/usr/local/bin/下.
tar zxvf snmpdiskio-0.9.4.tar.gz
install -m 0755 -o root -g root -p -v snmpdiskio /usr/local/bin/,
由于9.4太老不支持2.6内核,需要修改,出自http://forums.cacti.net/viewtopic.php?p=124793#124793 中dverlaeckt 的“code”
Vim snmpdiskio
#!/bin/bash
# $Id: snmpdiskio,v 1.5 2008/01/31 21:19:50 dverlaeckt Exp $
# snmpdiskio v0.9.6 (c) 2008 Dieter Verlaeckt <dieter.verlaeckt@gmail.com>
# snmpdiskio v0.9.5 (c) 2007 Pablo Destefanis <pdestefanis@gmail.com>
# snmpdiskio v0.9.4 (c) 2006 Mikael Fridh <mikael@meanstreak.se>
 
# 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 ~ /+/ && $2 ~ /+/ { num++ } END { print num } ' $PROCFILE
}
 
function hdIndex()
{
        awk ' BEGIN { num=0 } $1 ~ /+/ && $2 ~ /+/ { num++; print num } ' $PROCFILE
}
 
function hdDescr()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /+/ && $2 ~ /+/ { printf "%s/n", $3 }' $PROCFILE
        else
                awk ' $1 ~ /+/ && $2 ~ /+/ { printf "%s/n", $4 }' $PROCFILE
        fi
}
 
function hdInBlocks()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /+/ && $2 ~ /+/ && NF == 7 { printf "%.0f/n", $7 * 512 }
                      $1 ~ /+/ && $2 ~ /+/ && NF == 14 { printf "%.0f/n", $10 * 512 } ' $PROCFILE
        else
                awk ' $1 ~ /+/ && $2 ~ /+/ && NF == 15 { printf "%.0f/n", $11 * 512 } ' $PROCFILE
        fi
}
 
function hdOutBlocks()
{
        if [ "$MODE" = "linux26" ]; then
                awk ' $1 ~ /+/ && $2 ~ /+/ && NF == 7 { printf "%.0f/n", $5 * 512 }
                      $1 ~ /+/ && $2 ~ /+/ && NF == 14 { printf "%.0f/n", $6 * 512 } ' $PROCFILE
        else
                awk ' $1 ~ /+/ && $2 ~ /+/ && NF == 15 { printf "%.0f/n", $7 * 512 } ' $PROCFILE
        fi
}
 
function usage()
{
        cat <<-EOUSAGE
Usage: $0 <hdNum|hdIndex|hdDescr|hdInBlocks|hdOutBlocks>
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
 
4.       修改被监控机的snmpd.conf,在文件的结尾添加如下:
exec .1.3.6.1.4.1.2021.54 hdNum /bin/sh /usr/local/bin/snmpdiskio hdNum
exec .1.3.6.1.4.1.2021.55 hdIndex /bin/sh /usr/local/bin/snmpdiskio hdIndex
exec .1.3.6.1.4.1.2021.56 hdDescr /bin/sh /usr/local/bin/snmpdiskio hdDescr
exec .1.3.6.1.4.1.2021.57 hdInBlocks /bin/sh /usr/local/bin/snmpdiskio hdInBlocks
exec .1.3.6.1.4.1.2021.58 hdOutBlocks /bin/sh /usr/local/bin/snmpdiskio hdOutBlocks
这里增加了/bin/sh,我在网上搜索了许多,都没有加上这个,我测试就是不成功.
Service snmpd restart
测试
snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.58
# snmpwalk -v 2c -c public localhost  .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: "/bin/sh /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: "390659584"
UCD-SNMP-MIB::ucdavis.58.101.18 = STRING: "823808"
UCD-SNMP-MIB::ucdavis.58.101.19 = STRING: "386556928"
UCD-SNMP-MIB::ucdavis.58.101.20 = STRING: "827904"
UCD-SNMP-MIB::ucdavis.58.101.21 = STRING: "5120"
UCD-SNMP-MIB::ucdavis.58.101.22 = STRING: "2224640"
UCD-SNMP-MIB::ucdavis.58.101.23 = STRING: "0"
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 = ""
出现如下数据,表示正常.
 
 
5.在cacti的devicesà Associated Data Queries添加SNMP - Disk Statistics
 

Create Graphs for this Host选择


你会发现要选择的硬盘太多,你可以用iostat命令,照这里添加
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.11    0.28    1.61    0.55    0.00   96.45
 
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               2.70        23.93        38.02     763647    1213086
sda1              0.00         0.05         0.00       1609         14
sda2              2.69        23.68        38.01     755634    1212824
sda3              0.00         0.05         0.00       1617          0
sda4              0.00         0.00         0.00         10          0
sda5              0.01         0.14         0.01       4345        248
我使用虚拟机测试的
 
 
排错
如果出现
snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.58
UCD-SNMP-MIB::ucdavis.58 = No Such Object available on this agent at this OID
你先执行snmpwalk -v 2c -c public localhost,看看是否正常,如不正常,说明snmpd.conf其他配置有问题,如正常,说明刚才添加exec有问题,请检查.
 
Snmp.conf提前设置
 
     40 #       sec.name  source          community
     41 com2sec notConfigUser  default       mynetsnmp
 
     61 #       group          context sec.model sec.level prefix read   write  notif
     62 access  notConfigGroup ""      any       noauth    exact  all    none none
 
     77 ##     group.name sec.model  sec.name
     78 group MyRWGroup  v1        local
     79 group MyRWGroup  v2c        local
     80 group MyRWGroup  usm        local
 
     86 ##           incl/excl subtree                          mask
     87 view all    included  .1                               80
 
 
 
  参考: http://upfelix.blogbus.com/logs/7

zhy1022wo 发表于 2018-10-17 15:01:40

谢谢分享!
页: [1]
查看完整版本: cacti利用snmpdiskio 监控服务器磁盘IO监控