加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

nagios插件--监控inodes

发布时间:2020-05-24 23:29:04 所属栏目:Python 来源:互联网
导读:nagios插件--监控inodes

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

#!/bin/env python
#-*-coding:utf-8-*-

'''
Create date: 2015-12-01
Version: 1.0
Description: Monitor inodes
Author: Linjianying
QQ: 122517575
'''

import os
import sys

##############################################################
############################说明区############################
##############################################################
#帮助页
def help():
	print '''check_inodes.py V1.0
This plugin checks the amount of disk inode space is free on a mounted file system
and generates an alert if free inode space is less than one of the threshold values
Exit with WARNING status if less than PERCENT of inode space is free !!!'''
	print 'Usage:','n',sys.argv[0],'-w <Warning_threshold> -c <Critical_threshold>'
	print 'Example:','-w 20% -c 10%'

if len(sys.argv) < 5:
	help()
	sys.exit(3)
elif sys.argv[1] != '-w':
	help()
	sys.exit(3)
elif sys.argv[3] != '-c':
	help()
	sys.exit(3)
elif sys.argv[2].strip("%") < sys.argv[4].strip("%"):
	print 'Critical_threshold must be less than Warning_threshold'
	sys.exit(3)

##############################################################
############################功能区############################
##############################################################
#挂载点
dflist = []
mtlist = []
mtdict = {}
dfinfo = os.popen("df -h")
for line in dfinfo.readlines():
	dflist.append(line)
for every in dflist[2:len(dflist)+1]:
	result = every.split(' ')
	mtlist.append(result[len(result)-1].strip("n"))
#inodes
def getinodes(mt):
	return "{0:.0f}%".format(float(os.statvfs(mt).f_favail) / os.statvfs(mt).f_files * 100 )
for mt in mtlist:
	mtdict[mt] = getinodes(mt)
###print mtdict.values()

##############################################################
############################输出区############################
##############################################################
#check
intmt = [int(i.strip("%")) for i in mtdict.values()]
if min(intmt) < int(sys.argv[4].strip("%")):
	print 'Critical -',mtdict
	sys.exit(2)
elif int(sys.argv[2].strip("%")) > min(intmt) > int(sys.argv[4].strip("%")):
	print 'Warning -',mtdict
	sys.exit(1)
else:
	print 'OK -',mtdict
	sys.exit(0)

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读