Python 运维Linux运维我用 Linux

zabbix 硬件 | 磁盘读写异常监控

2016-11-18  本文已影响0人  _简_述_

服务器在运行期间会出现各种故障,其中一个比较常见的问题就是磁盘无法写入,成为只读状态,导致靠写入信息的服务出现问题,造成业务崩溃。通常会从上至下的排查很多久才能找到问题的根源。
好了领导交给的任务不会硬着头皮上,在网上找了许久,没有发现很好的监控模板,只好自己动手丰衣足食。


解决思路:
既然是监控磁盘可写状态,那么只要写入成功输出0失败输出1,然后告警就可以了。

1.创建zabbix key

vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/disk.conf

UserParameter=disk.health.check,/usr/bin/python /usr/local/zabbix/scripts/disk_health_check.py

2.创建disk_health_check 脚本(需要执行权限)

vim /usr/local/zabbix/scripts/disk_health_check.py

#!/usr/bin/python
#磁盘只读检测脚本正常0,异常1
#jipeng 2016/3/26
import time
try:
    fileDisk = open ( '/usr/local/zabbix/scripts/disk_health_check.log', 'w' )
    old = str(time.time())
    fileDisk.write(old)
    fileDisk = open ( '/usr/local/zabbix/scripts/disk_health_check.log' )
    new=fileDisk.read()
    if (old==new):
        print '0'
    else:
        print '1'
    fileDisk.close()
except:
    print '1'

3.zbx_export_templates.xml 模板文件

本地创建xml文件然后导入即可使用

<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
    <version>3.0</version>
    <date>2016-11-18T05:15:07Z</date>
    <groups>
        <group>
            <name>Template-Hardware</name>
        </group>
    </groups>
    <templates>
        <template>
            <template>DiskHealth-Check</template>
            <name>DiskHealth-Check</name>
            <description>磁盘写入输出状态0正常,1异常</description>
            <groups>
                <group>
                    <name>Template-Hardware</name>
                </group>
            </groups>
            <applications>
                <application>
                    <name>diskHealth</name>
                </application>
            </applications>
            <items>
                <item>
                    <name>DiskHealthCheck</name>
                    <type>0</type>
                    <snmp_community/>
                    <multiplier>0</multiplier>
                    <snmp_oid/>
                    <key>disk.health.check</key>
                    <delay>60</delay>
                    <history>90</history>
                    <trends>365</trends>
                    <status>0</status>
                    <value_type>3</value_type>
                    <allowed_hosts/>
                    <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>diskHealth</name>
                        </application>
                    </applications>
                    <valuemap/>
                    <logtimefmt/>
                </item>
            </items>
            <discovery_rules/>
            <macros/>
            <templates/>
            <screens/>
        </template>
    </templates>
    <triggers>
        <trigger>
            <expression>{DiskHealth-Check:disk.health.check.count(#2,1,"eq")}>1</expression>
            <name>DiskHealthCheck</name>
            <url/>
            <status>0</status>
            <priority>2</priority>
            <description>2次内触发器等于1的次数大于1(等于2)次就会告警
判断两次都异常即告警</description>
            <type>0</type>
            <dependencies/>
        </trigger>
    </triggers>
    <graphs>
        <graph>
            <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>3</drawtype>
                    <color>00C800</color>
                    <yaxisside>0</yaxisside>
                    <calc_fnc>7</calc_fnc>
                    <type>0</type>
                    <item>
                        <host>DiskHealth-Check</host>
                        <key>disk.health.check</key>
                    </item>
                </graph_item>
            </graph_items>
        </graph>
    </graphs>
</zabbix_export>

上一篇下一篇

猜你喜欢

热点阅读