snmpdiskio for ubuntu 13.10 LTS

Step by Step:
1.

sudo apt-get install snmp snmpd snmp-mibs-downloader

 

2.Download snmpdiskio package from "http://forums.cacti.net/viewtopic.php?f=12&t=12742" and following README
3.Edit profiles for snmpd:

『/etc/snmp/snmpd.conf』
agentAddress  udp:127.0.0.1:161
view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1
view   systemonly  included   .1.3.6.1.2.1.2
extend .1.3.6.1.4.1.2021.54 hdNum /usr/local/bin/snmpdiskio hdNum
extend .1.3.6.1.4.1.2021.55 hdIndex /usr/local/bin/snmpdiskio hdIndex
extend .1.3.6.1.4.1.2021.56 hdDescr /usr/local/bin/snmpdiskio hdDescr
extend .1.3.6.1.4.1.2021.57 hdInBlocks /usr/local/bin/snmpdiskio hdInBlocks
extend .1.3.6.1.4.1.2021.58 hdOutBlocks /usr/local/bin/snmpdiskio hdOutBlocks
『/etc/snmp/snmp.conf』
mibs :
『/etc/default/snmpd』
export MIBS=/usr/share/snmp/mibs
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I interface,ifTable,ifXTable,cpu,cpu_linux,hw_mem,extend,versioninfo,snmp_mib,ip,at,system_mib -smux,mteTrigger,mteTriggerConf -p /var/run/snmpd.pid'

 

4.Download mibs and restart snmpd:

sudo download-mibs
sudo service snmpd restart

 

5.Testing snmpwalk:

snmpwalk -v 2c -c public localhost .1.3.6.1.4.1.2021.54
echo like these:
iso.3.6.1.4.1.2021.54.1.0 = INTEGER: 1
iso.3.6.1.4.1.2021.54.2.1.2.5.104.100.78.117.109 = STRING: "/usr/local/bin/snmpdiskio"
iso.3.6.1.4.1.2021.54.2.1.3.5.104.100.78.117.109 = STRING: "hdNum"
iso.3.6.1.4.1.2021.54.2.1.4.5.104.100.78.117.109 = ""
iso.3.6.1.4.1.2021.54.2.1.5.5.104.100.78.117.109 = INTEGER: 5
iso.3.6.1.4.1.2021.54.2.1.6.5.104.100.78.117.109 = INTEGER: 1
iso.3.6.1.4.1.2021.54.2.1.7.5.104.100.78.117.109 = INTEGER: 1
iso.3.6.1.4.1.2021.54.2.1.20.5.104.100.78.117.109 = INTEGER: 4
iso.3.6.1.4.1.2021.54.2.1.21.5.104.100.78.117.109 = INTEGER: 1
iso.3.6.1.4.1.2021.54.3.1.1.5.104.100.78.117.109 = STRING: "33"
iso.3.6.1.4.1.2021.54.3.1.2.5.104.100.78.117.109 = STRING: "33"
iso.3.6.1.4.1.2021.54.3.1.3.5.104.100.78.117.109 = INTEGER: 1
iso.3.6.1.4.1.2021.54.3.1.4.5.104.100.78.117.109 = INTEGER: 0
iso.3.6.1.4.1.2021.54.4.1.2.5.104.100.78.117.109.1 = STRING: "33"
snmpdiskio hdNum
echo like these:
33

 

So,you should modify your partition.xml like these:

<interface>
        <name>Get SNMP Partitions</name>
        <description>Queries a host for a list of monitorable partitions</description>
        <oid_index>.1.3.6.1.4.1.2021.55.4</oid_index>
        <oid_num_indexes>.1.3.6.1.4.1.2021.54.4</oid_num_indexes>
#       <index_order>hdDescr:hdName:hdIndex</index_order>
        <index_order>hdDescr:hdIndex</index_order>
        <index_order_type>numeric</index_order_type>
        <index_title_format>|chosen_order_field|</index_title_format>

        <fields>
                <hdIndex>
                        <name>Index</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.55.4</oid>
                </hdIndex>
                <hdDescr>
                        <name>Description</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>input</direction>
                        <oid>.1.3.6.1.4.1.2021.56.4</oid>
                </hdDescr>
                <hdInBlocks>
                        <name>Bytes Written</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.57.4.1.2.10.104.100.73.110.66.108.111.99.107.115</oid>
                </hdInBlocks>
                <hdOutBlocks>
                        <name>Bytes Read</name>
                        <method>walk</method>
                        <source>value</source>
                        <direction>output</direction>
                        <oid>.1.3.6.1.4.1.2021.58.4.1.2.11.104.100.79.117.116.66.108.111.99.107.115</oid>
                </hdOutBlocks>
        </fields>
</interface>

 

6.At last, putting snmpdiskio code:

#!/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>
# 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 <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

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: