×

扫描二维码登录本站

QQ登录

只需一步,快速开始

标签: 暂无标签
来自:网络



[ ttp://my.oschina.net/jastme/blog/280735#]?[/url]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
# -*- coding:utf-8 -*- from optparse import OptionParser import subprocess import sys """            nagios培训
    Nagios plugin to report the io utils by shell command iostat
    by jastme """
parser = OptionParser(usage="%prog -w <warning threshold> -c <critical threshold> [ -h ]",version="%prog ")

parser.add_option("-d", "--partion",action="store", type="string", dest="partion", help="choose the parion from the disk")

parser.add_option("-w", "--warning",action="store", type="string", dest="warn_threshold", help="Warning threshold in percentage")

parser.add_option("-c", "--critical",action="store", type="string", dest="crit_threshold", help="Critical threshold in percentage")

(options, args) = parser.parse_args()                   nagios实施

def ioutil():
    utils=subprocess.Popen("iostat -x 1 2 -d %s | grep %s | awk 'NR==2{print $NF}'" %           (options.partion,options.partion),shell=True,stdout=subprocess.PIPE)
    utils.wait()
    utilss=utils.communicate()[0][:-1]                 监控软件
    return eval(utilss)

def jastme():
    util=ioutil()
    if not options.crit_threshold:
        print "UNKNOWN: Missing critical threshold value."                   nagios配置
        sys.exit(3)
    if not options.warn_threshold:
        print "UNKNOWN: Missing warning threshold value."
        sys.exit(3)
    if int(util) >= int(options.crit_threshold):
        print "Criticl, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %(options.partion,util,util,options.warn_threshold,options.crit_threshold)
        sys.exit(2)

    elif int(options.crit_threshold) > int(util) >= int(options.warn_threshold):             开源监控软件
        print "Warning, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %       (options.partion,util,util,options.warn_threshold,options.crit_threshold)
        sys.exit(1)

    else:
        print "OK, the partion %s IO_utils is nearly %s%% | io_utils=%s%%;%s;%s;0" %(options.partion,util,util,options.warn_threshold,options.crit_threshold)
        sys.exit(0)
if __name__ == '__main__':
    jastme()



  • 修改了一个bug,iostat命令第一次取的值是系统从重启到现在的平均值,所以我们选择第2次的值,这样才准确。             nagios安装
  • 修复一个bug.  用eval来返回值,然后用整数来比较,字符串比较有BUG


想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427





上一篇:nagios之安装配置
下一篇:nagios插件(磁盘IO监控)脚本
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部