MegaCLI是LSI提供的用户空间管理RAID卡(LSI芯片)工具,适用于大多数的Dell服务器。

MegaCLI介绍:

http://zh.community.dell.com/techcenter/b/weblog/archive/2013/03/07/megacli-command-share

http://blog.chinaunix.net/uid-25135004-id-3139293.html

Zabbix提供low_level_discovery的机制去实现自动发现监控目标,自动添加监项的功能。Zabbix默认就基于low_level_discovery提供了文件系统挂载点和网卡的自动发现和监控。

所以,物理硬盘的自动发现和监控也是基于zabbix的low_level_discovery机制,我所需要做的就是写一个Python脚本来衔接Zabbix和MegaCLI。后面就不再阐述原理和细节了,过程如下:

1. 安装MegaCLI

去LSI官网上下载一个最新版本的MegaCLI,注意操作系统32位还是64位。

安装包默认是rpm的,CentOS等系统能轻松安装。

Ubuntu活debian可参考下面步骤安装:

mkdir /opt/MegaCLI
cd /opt/MegaCLI
wget -c http://xxx/8.07.14_MegaCLI.zip . unzip 8.07.14_MegaCLI.zip
cd /opt/MegaCLI/Linux
apt-get install rpm2cpio
rpm2cpio MegaCli-8.07.-.noarch.rpm | cpio -idmv
mv opt/MegaRAID /opt/ root@controller:~# ls -lh /opt/MegaRAID/MegaCli
total 5.7M
-rw-r--r-- 1 root root 296 Sep 24 19:10 CmdTool.log
-rwx------ 1 root root 528K Dec 16 2013 libstorelibir-2.so.14.07-0
-rwxr-xr-x 1 root root 2.4M Dec 16 2013 MegaCli
-rwsr-sr-x 1 root root 2.6M Dec 16 2013 MegaCli64
-rw-r--r-- 1 root root 139K Oct 10 17:43 MegaSAS.log

后面都默认MegaCli安装在/opt/MegaRAID/MegaCli

2. 编辑raid.py

https://gist.github.com/AlexYangYu/14161ce866417f817508

/opt/DiskMonitoring/raid.py (chmod +x /opt/DiskMonitoring/raid.py)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Description:
# This application is used to discovery the pyhsical disk by using the MegaCLI tool.
#
# Author: Alex Yang <alex890714@gmail.com>
# import commands
import os
import sys
import json
from optparse import OptionParser MEGACLI_EXEC = '/opt/MegaRAID/MegaCli/MegaCli64'
LIST_DISK_OPT = '-PDList -aALL' SLOT_NUMBER = 'Slot Number'
DEVICE_ID = 'Device Id'
WWN = 'WWN'
MEC = 'Media Error Count'
OEC = 'Other Error Count'
PFC = 'Predictive Failure Count'
PD_TYPE = 'PD Type'
RAW_SIZE = 'Raw Size'
FIRMWARE_STATE = 'Firmware state'
INQUIRY_DATA = 'Inquiry Data' class Disk(object):
def __init__(self, dev_id, slot_number, wwn, mec, oec, pfc, pd_type,
raw_size, firmware_state, inquiry_data):
self.dev_id = dev_id
self.slot_number = slot_number
self.wwn = wwn
# Media Error Count
self.mec = mec
# Other Error Count
self.oec = oec
# Predictive Failure Count
self.pfc = pfc
# PD Type
self.pd_type = pd_type
# Size
self.raw_size = raw_size
# Firmware State ("Failed", "Online, Spun Up", "Online, Spun Down", "Unconfigured(bad)", "Unconfigured(good), Spun down", "Hotspare, Spun down", "Hotspare, Spun up" or "not Online")
self.firmware_state = firmware_state
# Inquiry data
self.inquiry_data = inquiry_data def jsonfiy(self):
pass def __str__(self):
return '%s %s %s %s %s %s %s %s %s %s' % (
self.dev_id, self.slot_number, self.wwn, self.mec, self.oec,
self.pfc, self.pd_type, self.raw_size, self.firmware_state,
self.inquiry_data
) def check_megacli(cli_path):
if not os.path.exists(cli_path) or not os.access(cli_path, os.X_OK):
print 'MegaCLI is needed in %s with executable priviledge.' % (cli_path)
os.exit(1) def line_generator(string):
line = []
for c in string:
if c != '\n':
line.append(c)
else:
yield ''.join(line)
line = [] def get_value(line):
return line.split(':')[1].strip() def make_disk_array(mega_output):
disk_array = []
for line in line_generator(mega_output):
if line.startswith(SLOT_NUMBER):
slot_number = get_value(line)
elif line.startswith(DEVICE_ID):
dev_id = get_value(line)
elif line.startswith(WWN):
wwn = get_value(line)
elif line.startswith(MEC):
mec = get_value(line)
elif line.startswith(OEC):
oec = get_value(line)
elif line.startswith(PFC):
pfc = get_value(line)
elif line.startswith(PD_TYPE):
pd_type = get_value(line)
elif line.startswith(RAW_SIZE):
raw_size = get_value(line)
elif line.startswith(FIRMWARE_STATE):
fw_state = get_value(line)
elif line.startswith(INQUIRY_DATA):
inquiry_data = get_value(line) disk = Disk(dev_id, slot_number, wwn, mec, oec, pfc, pd_type,
raw_size, fw_state, inquiry_data)
disk_array.append(disk)
return disk_array def discovery_physical_disk(disk_array):
array = []
for d in disk_array:
disk = {}
disk['{#DISK_ID}'] = d.dev_id
disk['{#WWN}'] = d.wwn
array.append(disk)
return json.dumps({'data': array}, indent=4, separators=(',',':')) def count_media_error(disk_array, disk_id):
for disk in disk_array:
if int(disk.dev_id) == int(disk_id):
return disk.mec
return '-1' def count_other_error(disk_array, disk_id):
for disk in disk_array:
if int(disk.dev_id) == int(disk_id):
return disk.oec
return '-1' def count_predictive_error(disk_array, disk_id):
for disk in disk_array:
if int(disk.dev_id) == int(disk_id):
return disk.pfc
return '-1' def get_disk_array():
check_megacli(MEGACLI_EXEC)
(status, output) = commands.getstatusoutput('%s %s' % (MEGACLI_EXEC, LIST_DISK_OPT))
if status != 0:
print 'Exec MegaCLI failed, please check the log.'
os.exit(1)
disk_array = make_disk_array(output)
return disk_array def init_option():
usage = """
"""
parser = OptionParser(usage=usage, version="0.1")
return parser parser = init_option() if __name__ == '__main__':
(options, args) = parser.parse_args() if len(args) < 1:
print parser.print_help()
sys.exit(1) disk_array = get_disk_array() command = args.pop(0)
if command == 'pd_discovery':
print discovery_physical_disk(disk_array)
elif command == 'mec':
print count_media_error(disk_array, args.pop())
elif command == 'oec':
print count_other_error(disk_array, args.pop())
elif command == 'pfc':
print count_predictive_error(disk_array, args.pop())

3. 配置Zabbix Agent

编辑zabbix_agentd.conf,确保如下两个配置正确。

Include=/etc/zabbix/zabbix_agentd.conf.d/
UnsafeUserParameters=

将zabbix用户添加到sudoers中

echo "zabbix ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/zabbix

编辑/etc/zabbix/zabbix_agentd.conf.d/disk.conf, 添加自定义用户参数

UserParameter=raid.phy.discovery,sudo /opt/DiskMonitoring/raid.py pd_discovery
UserParameter=raid.phy.mec[*],sudo /opt/DiskMonitoring/raid.py mec $
UserParameter=raid.phy.oec[*],sudo /opt/DiskMonitoring/raid.py oec $
UserParameter=raid.phy.pfc[*],sudo /opt/DiskMonitoring/raid.py pfc $

4. 配置Zabbix Server

创建一个template,然后创建一个discovery rule,然后创建3个ITEM原型

Media Error Count的配置参考

后面只需要将模板关联到相关机器,并在相关机器上部署监控脚本即可。报警什么的就可以按自己的需求去设置。

Zabbix整合MegaCLI实现物理硬盘的自动发现和监控的更多相关文章

  1. Zabbix自动发现并监控磁盘IO、报警

    本文转载自: https://www.93bok.com 引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务 ...

  2. 添加zabbix自动发现(监控多tomcat实例)

    说明 何为自动发现?首先我们监控多tomcat实例,如果一个个实例地添加或许可以完成当前需求.但是日后随着实例的增多,再手动一个个去添加就十分不方便了.这时候需要自动发现这个功能,来帮助我们自动添加监 ...

  3. zabbix主机自动发现和监控

    在主机较多的时候,配置主机自动发现并加入监控可以代替手动的添加主机,减轻工作量,自动发现由服务端主动发起,Zabbix Server开启发现进程,定时扫描局域网中IP服务器.设备.可以根据需要,在对主 ...

  4. Zabbix 自动发现并监控磁盘IO、报警 引言

    引言 Zabbix并没有提供模板来监控磁盘的IO性能,所以我们需要自己来创建一个,由于一台服务器中磁盘众多,如果只有一两台可以手动添加,但服务集群达到几十那就非常麻烦,因此需要利用自动发现这个功能,自 ...

  5. zabbix自动发现与监控内存和CPU使用率最高的进程,监测路由器

    https://cloud.tencent.com/info/488cfc410f29d110c03bcf0faaac55b2.html         (未测试) https://www.cnblo ...

  6. Zabbix - LINUX下CPU,硬盘,流量,内存监控

    转载自:https://blog.csdn.net/jxzhfei/article/details/47191431 1.LINUX下zabbix客户端安装 [root@mongodb114 ~]# ...

  7. zabbix3.2自动发现批量监控redis端口状态

    使用nmap提示被防火墙阻挡,实际没有启用防火墙 [root@eus_chinasoft_haproxy:/usr/local/aegis]# nmap 172.20.103.202 -p 7000 ...

  8. Prometheus + Consul 自动发现服务监控

    一.Prometheus支持的多种服务发现机制(常用如下) static_configs: 静态服务发现 file_sd_configs: 文件服务发现 dns_sd_configs: DNS 服务发 ...

  9. 【Zabbix】Zabbix Server自动发现

    Zabbix自动发现 由于有上百台的虚拟机需要监控,如果一个个去添加配置,费时费力.Zabbix的自动发现,可以自动发现需要监控的机器,监控相应指标. 前置条件 安装部署好Zabbix Server. ...

随机推荐

  1. C语言异常处理编程的三个境界

    http://blog.csdn.net/treefish2012/article/details/17466487 这是上一次看完Herb Sutter的<Exceptional C++> ...

  2. Java统计用户年/月/周/日网站访问量

    一:准备工作,引入相关依赖: 二:运行效果图: 下一次访问 三:具体代码如下  (1):CountObjectInfo.java package cn.csrc.base.count; import ...

  3. 前端面试题1:Object.prototype.toString.call() 、instanceof 以及 Array.isArray()三种方法判别数组的优劣和区别

    1. Object.prototype.toString.call() 每一个继承 Object 的对象都有 toString 方法,如果 toString 方法没有重写的话,会返回 [Object ...

  4. select * 比select column快很多奇怪案例分析

    遇到MYSQL傻傻的地方,下面给个案例,大家感受下: 注意以下两个sql只有select *和select g.id区别. SQL1:SELECT g.idFROM table1 gINNER JOI ...

  5. 【Linux】安装mysql之设置远程访问权限

    最近重装了云主机,又要安装各种东西,其中一个就要设置mysql权限 出于学习方便,我在自己的云主机上安装的是phpstudy集成环境,所以要进入mysql控制台不能直接用“mysql -u root ...

  6. CI框架 重定向redirect()

    CI框架不能使用$this->redirect(),只能使用redirect():并且默认重定向地址带有index.php,如果需要去掉,请使用绝对地址. 使用示例: 通过发送HTTP头,命令客 ...

  7. PHP操作redis的常用例子

    Redis常用的例子 1,connect 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE 示例: &l ...

  8. 【java】A local class access to local variables

    内部类参考 A local class has access to local variables. However, a local class can only access local vari ...

  9. commons-logging日志实现解耦

    一.需要解耦      日志是实际应用中的一个重要部分,日志系统也有许多开源的实现,如java.util.logging, logback, log4j系列等.      在使用日志系统时,如果与具体 ...

  10. 数论:HDU1066-Last non-zero Digit in N!

    题目: Last non-zero Digit in N! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...