分享一个监控MFS的nagios插件

简介:

最近线上刚好有监控MFS服务器的需求,本来准备自己完全写一个nagios插件出来的,但是又懒不想写就搜了一下,还真有网友分享出来了。他的连接地址是:http://blog.csdn.net/liuyunfengheda/article/details/5606830

   我把脚本拿下来测试了一下,貌似有些小错误,不知道是不是系统不一样的原因。

   我的测试环境是centos 6.5 86_64。

   以下是我在centos 6.5 86_64环境下做了修改的脚本,分享给大家。

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
#by cuiyuanrong
#QQ:295749093
# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# Set MFS Path And Warning/CRITICAL Value
MFS_Path= "/usr/sbin"
MFS_Mount_Point= "/mnt/mfs"
WARNING_Value=85
CRITICAL_Value=95
#Get Master server Process
Master(){
MFS_PID=` ps  -ef |  grep  mfsmaster |  grep  ${mfspath} |  awk  '{print $2}' `
if  "${MFS_PID}"  ""  ]; then
     echo  "ERROR : mfs master does not start"
     exit  $STATE_CRITICAL
else
     echo  "OK : mfs master server running OK!"
      exit  $STATE_OK
fi
}
#Get chunker server Process
Chunker(){
MFS_PID=` ps  -ef |  grep  mfschunkserver |  grep  ${mfspath} |  awk  '{print $2}' `
if  "${MFS_PID}"  ""  ]; then
     echo  "ERROR : mfs chunkserver does not start"
     exit  $STATE_CRITICAL
else
     echo  "OK : mfs master chunkserver running OK!"
     exit  $STATE_OK
fi
}
Disk_used(){
Disk_used=` df  -h |  grep  ${mountpoint} |  awk  '{print $5}'  awk  -F%  '{print $1}' `
if  [ ${Disk_used} - ge  ${warningdiskused} -a ${Disk_used} -lt ${criticaldiskused} ]; then
     echo  "Waring :mfs disk used Rate is " ${Disk_used} ""
     exit  $STATE_WARNING
elif  [ ${Disk_used} - ge  ${criticaldiskused} ]; then
     echo  "CRITICAL :mfs disk used Rate is " ${Disk_used} ""
     exit  $STATE_CRITICAL
elif  "${Disk_used}"  ""  ]; then
     echo  "CRITICAL :mfs client not mount on"
     exit  $STATE_CRITICAL
else
     echo  "OK : MFS client mount on and disk used rate is ${Disk_used}% , Everything is OK!"
     exit  $STATE_OK
fi
}
#Get metalogger server Process
Metalogger(){
MFS_PID=` ps  -ef |  grep  mfsmetalogger |  grep  ${mfspath} |  awk  '{print $2}' `
if  "${MFS_PID}"  ""  ]; then
     echo  "ERROR : mfs mfsmetalogger does not start"
     exit  $STATE_CRITICAL
else
     echo  "OK : mfs master mfsmetalogger running OK!"
     exit  $STATE_OK
fi
}
# Functions plugin usage
print_usage()
{
     Program_name=$( basename  $0)
     echo  ""
     echo  " -M MFS master server status "
     echo  " -C MFS chunker server status "
     echo  " -U MFS client disk used Rate "
     echo  " -L MFS metalogger server status "
     echo  " -h Show this page "
     echo  ""
     echo  " Usage1 : ${Program_name} -M mfsmasterpath"
     echo  "    ex : ${Program_name} -M ${MFS_Path}"
     echo  " Usage2 : ${Program_name} -C mfschunkpath"
     echo  "    ex : ${Program_name} -C ${MFS_Path}"
     echo  " Usage3 : ${Program_name} -U mountpoint warningrate criticalrate"
     echo  "    ex : ${Program_name} -U ${MFS_Mount_Point} 60 80"
     echo  " Usage4 : ${Program_name} -L mfsmetaloggerpath"
     echo  "    ex : ${Program_name} -L ${MFS_Path}"
     echo  "     ex : ${Program_name} -h"
     echo  ""
     exit  0
}
# Parse parameter
while  [ $ # -gt 0 ]
do
     case  "$1"  in
         -h | --help)
             print_usage
             exit  $STATE_OK
             ;;
         -M | --master)
             mfspath=${2:- "${MFS_Path}" }
             Master
             ;;
         -C | --chunker)
             mfspath=${2:- "${MFS_Path}" }
             Chunker
             ;;
         -U | --usedwarning)
             mountpoint=${2:- "${MFS_Mount_Point}" }
             warningdiskused=${3:- "${WARNING_Value}" }
             criticaldiskused=${4:- "${CRITICAL_Value}" }
             Disk_used
                         ;;
         -L | --metalogger)
             mfspath=${2:- "${MFS_Path}" }
             Metalogger
             ;;
         *)    
             echo  "Unknown argement: $1"
             exit  $STATE_UNKNOWN
             ;;
     esac
shift
done



本文转自 cyr520 51CTO博客,原文链接:http://blog.51cto.com/cyr520/1359463

相关文章
|
Web App开发 开发工具 机器学习/深度学习
|
Web App开发 开发工具 机器学习/深度学习
|
网络协议 关系型数据库 测试技术
nagios插件详解
一、check_apt 作用:debain相关系统的更新机制检查 update更新软件列表信息,包括版本,依赖关系等 upgrade在不改变现有软件设置的基础上更新软件 dist-upgrade会改变配置文件,改变旧的依赖关系 语法:check_apt [[-d|-u|-U]opts] [-n] [-t timeout] >#check_apt --help //查看具体使用说明 -d opts:--dist-upgrade=OPTS:执行dist-upgrade升级。
1629 0
|
监控 测试技术 PHP
|
监控 Unix Linux