zoukankan      html  css  js  c++  java
  • zabbix应用之Low-level discovery监控磁盘IO

    参考文章:

    http://qicheng0211.blog.51cto.com/3958621/1599776/

    zabbix自带的"Template OS Linux"模板支持监控已经挂载的磁盘空间利用率,是利用LLD(Low-level discovery )实现的,却没有对磁盘IO监控。

    思 路:首先创建Discovery rules,在agent端配置对应的UserParameter,调用shell脚本,动态查找出已经挂载的磁盘分区;然后创建Item prototypes,使用vfs.dev.read[device,<type>,<mode>]和 vfs.dev.write[device,<type>,<mode>]来监控磁盘分区的IO,包括磁盘读写速率、每秒读写扇 区数、每秒写操作数;然后创Graph prototypes,生成磁盘IO图表。(zabbix服务器端通过与zabbix agent通信来获取客户端服务器的数据;agent分为两个版本,其中一个是主动一个是被动,在配置主机我们可以看到一个agent,另一个是 agent(active)。前者为被动检测,后者为主动检 测;关建点来了vfs.dev.read[device,<type>,<mode>]就是监控项keys)

    zabbix agent类型所有key:http://ju.outofmemory.cn/entry/76305

    首先做io动态监控的zabbix_agent端执行该脚本:

    #!/bin/sh
    #
    # Filename:    autoMonitorDiskIO.sh
    # Date:        2017-02-15
    # Description: 部署zabbix low-level discovery 监控磁盘IO
    # Notes: 在被监控客户端运行此脚本,前提条件已经安装好zabbix agent
    #
     
    ROOT_UID=0
    if [ "$UID" -ne "$ROOT_UID" ];then
        echo "Error: Please run this script as root user."
        exit 1
    fi
     
    # 自行修改为你的zabbix agent配置文件路径
    AGENT_CONF="/etc/zabbix/zabbix_agentd.conf"
     
    mkdir -p /etc/zabbix/monitor_scripts
    # 创建 low-level discovery mounted disk 脚本
    cat > /etc/zabbix/monitor_scripts/mount_disk_discovery.sh << 'EOF'
    #!/bin/bash
    #Function: low-level discovery mounted disk
    #Script_name: mount_disk_discovery.sh 
    
    mount_disk_discovery()
    {
        local regexp="(btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|ntfs|fat32|zfs)"
        local tmpfile="/tmp/mounts.tmp"
        :> "$tmpfile"
        egrep "$regexp" /proc/mounts > "$tmpfile"
        local num=$(cat "$tmpfile" | wc -l)
        printf '{
    '
        printf '	"data":[ '
        while read line;do
            DEV_NAME=$(echo $line | awk '{print $1}')
            FS_NAME=$(echo $line | awk '{print $2}')
            SEC_SIZE=$(sudo /sbin/blockdev --getss $DEV_NAME 2>/dev/null)
            printf '
    		{'
            printf ""{#DEV_NAME}":"${DEV_NAME}","
            printf ""{#FS_NAME}":"${FS_NAME}","
            printf ""{#SEC_SIZE}":"${SEC_SIZE}"}"
            ((num--))
            [ "$num" == 0 ] && break
            printf ","
        done < "$tmpfile"
        printf '
    	]
    '
        printf '}
    '
    }
    
    case "$1" in
        mount_disk_discovery)
            "$1"
            ;;
        *)
            echo "Bad Parameter."
            echo "Usage: $0 mount_disk_discovery"
            exit 1
            ;;
    esac
    EOF
    touch /tmp/mounts.tmp
    chown zabbix:zabbix /tmp/mounts.tmp
    chown -R zabbix:zabbix /etc/zabbix/monitor_scripts
    chmod 755 /etc/zabbix/monitor_scripts/mount_disk_discovery.sh
     
    # 判断配置文件是否存在
    [ -f "${AGENT_CONF}" ] || { echo "ERROR: File ${AGENT_CONF} does not exist.";exit 1;}
     
    include=`grep '^Include' ${AGENT_CONF} | cut -d'=' -f2`
    # 在配置文件中添加自定义参数
    if [ -d "$include" ];then
        cat > $include/disk_lld.conf << 'EOF'
    UserParameter=mount_disk_discovery,/bin/bash /etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discovery
    EOF
    else
        grep -q '^UserParameter=mount_disk_discovery' ${AGENT_CONF} || cat >> ${AGENT_CONF} << 'EOF'
    UserParameter=mount_disk_discovery,/bin/bash /etc/zabbix/monitor_scripts/mount_disk_discovery.sh mount_disk_discovery
    EOF
    fi
    
    # 授权zabbix用户无密码运行/sbin/blockdev命令
    chmod +w /etc/sudoers 
    sed -i '/^Defaultss+requiretty/s/^/#/' /etc/sudoers
    grep -q '^zabbix ALL=(ALL).*blockdev' /etc/sudoers || echo 'zabbix ALL=(ALL)       NOPASSWD: /sbin/blockdev' >> /etc/sudoers
    chmod 440 /etc/sudoers
    
    # 重启agent服务
    [ -f '/etc/init.d/zabbix-agent' ] && /etc/init.d/zabbix-agent restart || echo "需手动重启zabbix agent服务."
    

    然后在zabbix_server的web端,导入下面的模板:

    模板的名子为: TemplateLinuxDiskIO.xml

    内容如下:<version>2.0</version>这里的版本号不能与zabbix_server的版本号差的太多,不然会失败!!!!!

    <?xml version="1.0" encoding="UTF-8"?>
    <zabbix_export>
        <version>2.0</version>
        <date>2017-02-15T05:18:12Z</date>
        <groups>
            <group>
                <name>Templates</name>
            </group>
        </groups>
        <templates>
            <template>
                <template>Template Linux DiskIO</template>
                <name>Template Linux DiskIO</name>
                <description/>
                <groups>
                    <group>
                        <name>Templates</name>
                    </group>
                </groups>
                <applications>
                    <application>
                        <name>Disk IO</name>
                    </application>
                </applications>
                <items/>
                <discovery_rules>
                    <discovery_rule>
                        <name>Mount Disk discovery</name>
                        <type>0</type>
                        <snmp_community/>
                        <snmp_oid/>
                        <key>mount_disk_discovery</key>
                        <delay>600</delay>
                        <status>0</status>
                        <allowed_hosts/>
                        <snmpv3_contextname/>
                        <snmpv3_securityname/>
                        <snmpv3_securitylevel>0</snmpv3_securitylevel>
                        <snmpv3_authprotocol>0</snmpv3_authprotocol>
                        <snmpv3_authpassphrase/>
                        <snmpv3_privprotocol>0</snmpv3_privprotocol>
                        <snmpv3_privpassphrase/>
                        <delay_flex/>
                        <params/>
                        <ipmi_sensor/>
                        <authtype>0</authtype>
                        <username/>
                        <password/>
                        <publickey/>
                        <privatekey/>
                        <port/>
                        <filter>
                            <evaltype>0</evaltype>
                            <formula/>
                            <conditions/>
                        </filter>
                        <lifetime>0</lifetime>
                        <description/>
                        <item_prototypes>
                            <item_prototype>
                                <name>Operations read per second on {#FS_NAME}</name>
                                <type>0</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.read[{#DEV_NAME},ops]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>oper/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params/>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                            <item_prototype>
                                <name>Operations write per second on {#FS_NAME}</name>
                                <type>0</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.write[{#DEV_NAME},ops]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>oper/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params/>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                            <item_prototype>
                                <name>Read speed on {#FS_NAME}</name>
                                <type>15</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.read[{#DEV_NAME},Bps]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>B/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params>last(&quot;vfs.dev.read[{#DEV_NAME},sps]&quot;)*{#SEC_SIZE}</params>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                            <item_prototype>
                                <name>Sectors read per second on {#FS_NAME}</name>
                                <type>0</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.read[{#DEV_NAME},sps]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>sec/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params/>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                            <item_prototype>
                                <name>Sectors write per second on {#FS_NAME}</name>
                                <type>0</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.write[{#DEV_NAME},sps]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>sec/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params/>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                            <item_prototype>
                                <name>Write speed on {#FS_NAME}</name>
                                <type>15</type>
                                <snmp_community/>
                                <multiplier>0</multiplier>
                                <snmp_oid/>
                                <key>vfs.dev.write[{#DEV_NAME},Bps]</key>
                                <delay>60</delay>
                                <history>90</history>
                                <trends>365</trends>
                                <status>0</status>
                                <value_type>0</value_type>
                                <allowed_hosts/>
                                <units>B/s</units>
                                <delta>0</delta>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <formula>1</formula>
                                <delay_flex/>
                                <params>last(&quot;vfs.dev.write[{#DEV_NAME},sps]&quot;)*{#SEC_SIZE}</params>
                                <ipmi_sensor/>
                                <data_type>0</data_type>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications>
                                    <application>
                                        <name>Disk IO</name>
                                    </application>
                                </applications>
                                <valuemap/>
                                <logtimefmt/>
                            </item_prototype>
                        </item_prototypes>
                        <trigger_prototypes/>
                        <graph_prototypes>
                            <graph_prototype>
                                <name>Operations read and write on {#FS_NAME}</name>
                                <width>900</width>
                                <height>200</height>
                                <yaxismin>0.0000</yaxismin>
                                <yaxismax>100.0000</yaxismax>
                                <show_work_period>1</show_work_period>
                                <show_triggers>1</show_triggers>
                                <type>0</type>
                                <show_legend>1</show_legend>
                                <show_3d>0</show_3d>
                                <percent_left>0.0000</percent_left>
                                <percent_right>0.0000</percent_right>
                                <ymin_type_1>0</ymin_type_1>
                                <ymax_type_1>0</ymax_type_1>
                                <ymin_item_1>0</ymin_item_1>
                                <ymax_item_1>0</ymax_item_1>
                                <graph_items>
                                    <graph_item>
                                        <sortorder>0</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>0000C8</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.read[{#DEV_NAME},ops]</key>
                                        </item>
                                    </graph_item>
                                    <graph_item>
                                        <sortorder>1</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>C800C8</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.write[{#DEV_NAME},ops]</key>
                                        </item>
                                    </graph_item>
                                </graph_items>
                            </graph_prototype>
                            <graph_prototype>
                                <name>Read and Write speed on {#FS_NAME}</name>
                                <width>900</width>
                                <height>200</height>
                                <yaxismin>0.0000</yaxismin>
                                <yaxismax>100.0000</yaxismax>
                                <show_work_period>1</show_work_period>
                                <show_triggers>1</show_triggers>
                                <type>0</type>
                                <show_legend>1</show_legend>
                                <show_3d>0</show_3d>
                                <percent_left>0.0000</percent_left>
                                <percent_right>0.0000</percent_right>
                                <ymin_type_1>0</ymin_type_1>
                                <ymax_type_1>0</ymax_type_1>
                                <ymin_item_1>0</ymin_item_1>
                                <ymax_item_1>0</ymax_item_1>
                                <graph_items>
                                    <graph_item>
                                        <sortorder>0</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>C80000</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.read[{#DEV_NAME},Bps]</key>
                                        </item>
                                    </graph_item>
                                    <graph_item>
                                        <sortorder>1</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>00C800</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.write[{#DEV_NAME},Bps]</key>
                                        </item>
                                    </graph_item>
                                </graph_items>
                            </graph_prototype>
                            <graph_prototype>
                                <name>Sectors read and write on {#FS_NAME}</name>
                                <width>900</width>
                                <height>200</height>
                                <yaxismin>0.0000</yaxismin>
                                <yaxismax>100.0000</yaxismax>
                                <show_work_period>1</show_work_period>
                                <show_triggers>1</show_triggers>
                                <type>0</type>
                                <show_legend>1</show_legend>
                                <show_3d>0</show_3d>
                                <percent_left>0.0000</percent_left>
                                <percent_right>0.0000</percent_right>
                                <ymin_type_1>0</ymin_type_1>
                                <ymax_type_1>0</ymax_type_1>
                                <ymin_item_1>0</ymin_item_1>
                                <ymax_item_1>0</ymax_item_1>
                                <graph_items>
                                    <graph_item>
                                        <sortorder>0</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>C80000</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.read[{#DEV_NAME},sps]</key>
                                        </item>
                                    </graph_item>
                                    <graph_item>
                                        <sortorder>1</sortorder>
                                        <drawtype>5</drawtype>
                                        <color>00C800</color>
                                        <yaxisside>0</yaxisside>
                                        <calc_fnc>2</calc_fnc>
                                        <type>0</type>
                                        <item>
                                            <host>Template Linux DiskIO</host>
                                            <key>vfs.dev.write[{#DEV_NAME},sps]</key>
                                        </item>
                                    </graph_item>
                                </graph_items>
                            </graph_prototype>
                        </graph_prototypes>
                        <host_prototypes/>
                    </discovery_rule>
                </discovery_rules>
                <macros/>
                <templates/>
                <screens/>
            </template>
        </templates>
    </zabbix_export>

    如图:

    Configuration------>Templates--------->import

    Configuration----->Templates 来查看导入的模板:

    查看添加的Template:

    现在就可以了,接下来要做的就是:把这个Template加入zabbix_agent的步骤如下:

    Configuration--->Host---->test2:如图:

    点击Templates,选择模板 下图所示:

    查看test2的items:

    下面看看一下效果:

    在部署后,不会马上看到效果,而是这种效果 Template Linux DiskIO: Disk IO 的Items (0) 等 一段时间 就会好的!!


  • 相关阅读:
    移动互联网全新体验Andoid
    《XNA高级编程:Xbox 360和Windows》51
    《XNA高级编程:Xbox 360和Windows》47
    让FCKeditor支持多用户环境(asp.net)
    《XNA高级编程:Xbox 360和Windows》45
    《XNA高级编程:Xbox 360和Windows》46
    《XNA高级编程:Xbox 360和Windows》44
    《XNA高级编程:Xbox 360和Windows》43
    hdu 4314 Save the dwarfs 夜
    poj 3150 Cellular Automaton 夜
  • 原文地址:https://www.cnblogs.com/bass6/p/6403311.html
Copyright © 2011-2022 走看看