nagios插件--监控inodes
- 作者: 听说名字长的都长的非常非常的叼是么
- 来源: 51数据库
- 2022-08-12
#!/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:','\n', sys.argv[0], '-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)
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
