nagios监控标准端口,非标准端口;监控httpd,监控weblogic;监控CPU,内存,硬盘,网卡流量
....
监控标准端口
########################
监控非标准端口
http://hx100.blog.51cto.com/44326/369427
define command{
command_name 4000
command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p 4000 $ARG2$
}
# Disable notifications for this service by default, as not all users may have HTTP enabled.
use local-service ; Name of service template to use
host_name web1
service_description 4000
check_command 4000
is_volatile 0
check_period 24x7
max_check_attempts 2
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_options w,u,c,r
notification_interval 960
notification_period 24x7
本文出自 “无云安全技术站” 博客,请务必保留此出处http://hx100.blog.51cto.com/44326/369427
http://www.lingang.gd.cn/?action=show&id=198
如果要检查非标准端口(比如,ftp开在了22222端口上),也是修改commands.cfg文件,对check_ftp的声明修改增加-p参数即可。
# 'check_ftp' command definition
define command{
command_name check_ftp
command_line $USER1$/check_ftp -H $HOSTADDRESS$ -p $ARG1$
}
默认大多数可以直接加端口,第一步可以不管
再把test.cfg中,对应服务的检测命令后面加一个端口号的参数:
define service {
host_name ...
...
check_command check_ftp!22222
}
这就可以对22222端口的FTP进行监控,要添加多个参数,也可以如法炮制。
define service{
use generic-service
host_name webserver
service_description SSH
check_command check_ssh! -p 1500!远程被监控服务器IP或者localhost
}
http://bbs.chinaunix.net/thread-1467863-1-1.html
我也最近才开始装nagios的。好像官方默认带的pluging文件都是编译好的不能修改,用守住每一天大侠的脚本就可以了
搞定!
|
http://blog.163.com/herod_xiao/blog/static/87188399200962214633436/
最近配置了nagios系统,也监控了公司相关行情服务器程序;基本上socket(收发通信协议)写的程序都会对应一个tcp端口出来,我们只要监控此端口就相当监控了此程序;如FTP 21 pop 110 smtp 25 这些是常见的tcp端口,常见的端口一般nagios内都有定义的check_command ,如果不是常见的端口,自定义的程序的tcp端口该如何设置呢?这是大多配置完Nagios后遇到的很严重的问题,我也遇到了,在多亏网友(守住每一天)帮忙得以解决,下面就让我分享给大家;我是怎样解决此问题的;
所有nagios配置完成后,下面我们要监控咱们公司服务器上的一个产品程序,此程序对应多个tcp端口,我们这里就拿一个tcp端口9000来说;
配置 # vi /usr/local/nagios/etc/nagios.cfg
添加cfg_file=/usr/local/nagios/etc/objects/ps2008_ip51.cfg
新增配置文件 #vi /usr/local/nagios/etc/objects/ps2008_ip51.cfg
define host{
use linux-server
host_name ps2008_ip51
alias ps2008_ip51
address 210.73.*.*
}
define service{
use generic-service
host_name ps2008_ip51
service_description SSH
check_command check_ssh
}
define service{
use generic-service
host_name ps2008_ip51
check_period 24x7
max_check_attempts 3
normal_check_interval 30
retry_check_interval 15
notification_interval 300
notification_period 24x7
notification_options w,u,c,r
service_description TCP9000
check_command check_tcp!9000
}
重启nagios 配置完成,看看如下效果图,呵呵
各位如果有问题可以给我留言!
完!
原创于2009-7-22 网友转载记得带上http://blog.163.com/herod_xiao/blog
#########################
监控httpd
http://www.uddtm.com/os/linux/NagiosjiankongHTTPfuwudeshiyonghecanshumiaoshu.php
监控主机设定文件
define host{
use linux-server; 继承模板中linux-server的监控参数
host_name remotehost1 ; 主机名称
alias Some Remote Host ; 别名
address 192.168.200.10; IP地址
hostgroups allhosts ; 所属主机群组
}
在nagios的官方配置文件中,是使用generic-host来作为继承参数。我在实际测试中发现无法通过nagios监测,提示错误为Error: Invalid max_check_attempts value for host 'remotehost1'
即使添加了这个参数,还是会提示警告信息 Warning: Host 'remotehost1' has no default contacts or contactgroups defined!
关于这两个模板的差异,我会在之后的文档里面进行进一步的比较和说明
HTTP监控配置文件描述
define service{
use generic-service
host_name remotehost1
service_description httpmonitor
check_command check_http
}
这样就能够监控http服务了
确认一下/usr/local/nagios/etc/object/command.cfg 是否有关于check_http的指令
define command{
command_name check_http
command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}
监控http服务参数描述
check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>][-w <warn time>] [-c <critical time>] [-t <timeout>] [-L][-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>][-s string] [-l] [-r <regex> | -R <case-insensitive regex>][-P string][-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string][-k string] [-S] [-C <age>] [-T <content-type>]
常用参数
-H 用于虚拟主机,并可以增加端口。例如,test.com:10000
-I IP地址
-S 基于SSL连接。默认端口为443
-u URL地址
-w 警告响应时间 响应时间超过指定时间则显示WARNING
-c 临界报警响应时间 响应时间超过设定时间则显示CRITICAL
-p 端口设定
-e 监测服务器反馈的第一行(状态)信息是否包含匹配字符
-N 不读取body部分,在读取header信息
-t timeout时间值
-v 显示服务器反馈的所有信息
-r 正则表达式匹配反馈页信息
-R 同上,但可以不考虑大小写问题
--invert-regex 反馈信息中包含字符则报警
-L 反馈信息包含URL link
-a 对需要基础认证的,提供用户名和密码,获取反馈值
#监控域名的反馈
./check_http -H www.sina.com.cn
#监测该IP的10000端口,并且使用SSL协议
./check_http -I 192.168.200.1 -S -p 10000
#监测反馈的第一行信息中是否包含302,可以作为web程序反馈信息检测
./check_http -I 192.168.200.1 -S -p 10000 -e 302
#对该IP的指定URL进行检测
./check_http -I 192.168.200.10 -u /session_login.cgi
#检测域名,并且只获取header部分。这样可以加快检测响应时间,对大量web服务进行检测时,可以降低nagios服务器负载
./check_http -H www.sina.com.cn -N
#检测反馈页的生成时间是否超过10小时
./check_http -H www.sina.com.cn -M 10h
#在监测新浪网站是反馈时间超过5秒警告,超过10秒报警
./check_http -w 5 -c 10 -H www.sina.com.cn
#检测新浪网反馈页的时间超过5秒,就反馈CRITICAL - Socket timeout after 1 seconds
./check_http -t 5 -H www.sina.com.cn
#显示反馈的所有信息,包含整个页面的信息
./check_http -H www.sina.com.cn -v
#对需要帐户密码登录的网站,使用-a参数来进行登录。正确则显示HTTP OK,否则显示HTTP WARNING
./check_http -I 192.168.200.249 -u /nagios/ -a nagiosadmin:123456
参考资料 http://nagiosplugins.org/man/check_http
http://blog.chinaunix.net/u3/93482/showart_1876495.html
http://yunhaozou.org/monitor/103.html
本文出自孤风颠影|网站运维 网址:http://yunhaozou.org/monitor/103.html.转载请保留.
##########################
监控weblogic
http://skymax.blog.51cto.com/365901/101603/
http://skymax.blog.51cto.com/365901/258593
Plugin Return Code
|
Service State
|
Host State
|
0
|
OK
|
UP
|
1
|
WARNING
|
UP or DOWN/UNREACHABLE*
|
2
|
CRITICAL
|
DOWN/UNREACHABLE
|
3
|
UNKNOWN
|
DOWN/UNREACHABLE
|
$ java weblogic.Admin -url ${URL} -username ${USER_NAME} -password ${PASS_WORD} get -pretty \
-mbean "${DOMAIN_NAME}:Location=${SERVER_NAME},Name=${SERVER_NAME},Type=ServerRuntime”
|
$ java weblogic.Admin -url ${URL} -username ${USER_NAME} -password ${PASS_WORD} GET -pretty \
-mbean "${DOMAIN_NAME}:Location=${SERVER_NAME},Name=${POOL_NAME},ServerRuntime=
${SERVER_NAME},Type=JDBCConnectionPoolRuntime"
|
${URL}
|
weblogic的URL,例如t3://192.168.1.2:7002
|
${USER_NAME}
|
用户名
|
${PASS_WORD}
|
密码
|
${DOMAIN_NAME}
|
weblogic域的名称,如mydomain
|
${SERVER_NAME}
|
Server名
|
${POOL_NAME}
|
JDBC Pool名称
|
#!/bin/ksh
#check_wls.sh --jdbcpool url username password domainname servername poolname
#check_wls.sh --server url username password domainname servername
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1749 $' | sed -e 's/[^0-9.]//g'`
. $PROGPATH/utils.sh
print_usage() {
echo "Usage:"
echo " $PROGNAME --jdbcpool url username password domainname servername poolname
echo " $PROGNAME --server url username password domainname servername
echo " $PROGNAME --help"
echo " $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "Check Weblogic status"
echo ""
echo "--jdbcpool url username password domainname servername poolname"
echo " Check Weblogic JDBC Pool"
echo "--server url username password domainname servername"
echo " Check Weblogic Server"
}
if [[ -z "$JAVA_HOME" ]]
then
echo "Please set JAVA_HOME!"
exit $STATE_UNKNOWN
fi
if [[ -z "$CLASSPATH" ]]
then
echo "Please set CLASSPATH!"
exit $STATE_UNKNOWN
else
echo $CLASSPATH | grep "weblogic.jar" | wc -l | read N
if [[ "$N" = "0" ]]
then
echo "Please add weblogic.jar to CLASSPATH!"
exit $STATE_UNKNOWN
fi
fi
PATH=$JAVA_HOME/bin:$PATH
export PATH
JDBC_TYPE="JDBCConnectionPoolRuntime"
SERVER_TYPE="ServerRuntime"
cmd="$1"
# Information options
case "$cmd" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
esac
case "$cmd" in
--server)
URL=${2}
USER_NAME=${3}
PASS_WORD=${4}
DOMAIN_NAME=${5}
SERVER_NAME=${6}
SERVER_INFO="${DOMAIN_NAME}:${SERVER_NAME}"
RE=`java weblogic.Admin -url ${URL} -username ${USER_NAME} -password ${PASS_WORD} get -pretty \
-mbean "${DOMAIN_NAME}:Location=${SERVER_NAME},Name=${SERVER_NAME},Type=${SERVER_TYPE}"`
printf "${RE}" | grep ^"-" | wc -l | read N
if [[ "$N" -lt "1" ]]
then
#error
printf "${RE}" | awk '{ printf $0 }' | read ERR_INFO
echo "CRITICAL - ${ERR_INFO}"
exit $STATE_CRITICAL
fi
if [[ "$N" -ge "1" ]]
then
HEALTH_STATE=""
RUN_STATE=""
#HealthState State
printf "${RE}" | while read NAME VALUE
do
#PoolState WaitingForConnectionCurrentCount State
#echo "NAME:${NAME} VALUE:${VALUE}"
case "${NAME}" in
HealthState:)
HEALTH_STATE=${VALUE}
;;
State:)
RUN_STATE=${VALUE}
;;
esac
done
#echo "HEALTH_STATE:${HEALTH_STATE}"
#echo "RUN_STATE:${RUN_STATE}"
HEALTH_STATE_INFO=${HEALTH_STATE}
echo ${HEALTH_STATE_INFO} | awk -F, '{ print $1 }' | awk -F: '{ print $2 }' | read HEALTH_STATE
#echo "HEALTH_STATE:${HEALTH_STATE}"
#HEALTH_OK HEALTH_WARN HEALTH_CRITICAL HEALTH_FAILED
if [[ "${RUN_STATE}" != "RUNNING" ]]
then
echo "CRITICAL - ${SERVER_INFO} State is ${RUN_STATE}"
exit $STATE_CRITICAL
fi
case "${HEALTH_STATE}" in
EALTH_OK)
;;
HEALTH_WARN)
echo "WARN - ${SERVER_INFO} HealthState is ${HEALTH_STATE_INFO}"
exit $STATE_WARNING
;;
HEALTH_CRITICAL)
echo "CRITICAL - ${SERVER_INFO} HealthState is ${HEALTH_STATE_INFO}"
exit $STATE_CRITICAL
;;
HEALTH_FAILED)
echo "FAILED - ${SERVER_INFO} HealthState is ${HEALTH_STATE_INFO}"
exit $STATE_CRITICAL
;;
esac
fi
echo "OK - ${SERVER_INFO} State is ${RUN_STATE},HealthState is ${HEALTH_STATE_INFO}"
exit $STATE_OK
;;
--jdbcpool)
URL=${2}
USER_NAME=${3}
PASS_WORD=${4}
DOMAIN_NAME=${5}
SERVER_NAME=${6}
POOL_NAME=${7}
POOL_INFO="${DOMAIN_NAME}:${SERVER_NAME}:${POOL_NAME}"
RE=`java weblogic.Admin -url ${URL} -username ${USER_NAME} -password ${PASS_WORD} GET -pretty \
-mbean "${DOMAIN_NAME}:Location=${SERVER_NAME},Name=${POOL_NAME},ServerRuntime=${SERVER_NAME},Type=${JDBC_TYPE}"`
printf "${RE}" | grep ^"-" | wc -l | read N
if [[ "$N" -lt "1" ]]
then
#error
printf "${RE}" | awk '{ printf $0 }' | read ERR_INFO
echo "CRITICAL - ${ERR_INFO}"
exit $STATE_CRITICAL
fi
if [[ "$N" -ge "1" ]]
then
POOL_STATE=""
WAIT_CNT=""
RUN_STATE=""
printf "${RE}" | while read NAME VALUE
do
#PoolState WaitingForConnectionCurrentCount State
#echo "NAME:${NAME} VALUE:${VALUE}"
case "${NAME}" in
PoolState:)
POOL_STATE=${VALUE}
;;
WaitingForConnectionCurrentCount:)
WAIT_CNT=${VALUE}
;;
State:)
RUN_STATE=${VALUE}
;;
esac
done
#echo "POOL_STATE:${POOL_STATE}"
#echo "WAIT_CNT:${WAIT_CNT}"
#echo "RUN_STATE:${RUN_STATE}"
if [[ "${POOL_STATE}" != "true" ]]
then
echo "CRITICAL - ${POOL_INFO} PoolState is ${POOL_STATE}"
exit $STATE_CRITICAL
fi
if [[ "${RUN_STATE}" != "Running" ]]
then
echo "CRITICAL - ${POOL_INFO} State is ${RUN_STATE}"
exit $STATE_CRITICAL
fi
if [[ "${WAIT_CNT}" -gt "0" ]]
then
echo "WARNING - ${POOL_INFO} WaitingForConnectionCurrentCount is ${WAIT_CNT}"
exit $STATE_WARNING
fi
else
#error
printf "${RE}" | awk '{ printf $0 }' | read ERR_INFO
echo "CRITICAL - ${ERR_INFO}"
exit $STATE_CRITICAL
fi
echo "OK - ${POOL_INFO} State is ${RUN_STATE},PoolState is ${POOL_STATE},WaitingForConnectionCurrentCount is ${WAIT_CNT}"
exit $STATE_OK
;;
*)
print_usage
exit $STATE_UNKNOWN
;;
esac
|
$ ln -s ./check_wls.sh ./check_wls
|
${URL}
|
t3://172.17.1.2:7001
|
${USER_NAME}
|
weblogic
|
${PASS_WORD}
|
weblogic
|
${DOMAIN_NAME}
|
mydomain
|
${SERVER_NAME}
|
myserver
|
${POOL_NAME}
|
mypool
|
$ vi ./nrpe.cfg
... .... ... .... ... .... ... .... ... .... ... ....
#check weblogic [check_wls]
command[check_wls_server_myserver]=/usr/local/nagios//libexec/check_wls --server t3://172.2.10.2:7001 weblogic weblogic mydomain myserver
command[check_wls_jdbcpool_mypool]=/usr/local/nagios//libexec/check_wls --jdbcpool t3://172.2.10.2:7001 weblogic weblogic mydomain myserver mypool
|
... .... ... .... ... .... ... .... ... .... ... ....
JAVA_HOME=/data/bea/bea/jdk142_05
export JAVA_HOME
CLASSPATH=/data/bea/bea/weblogic81/server/lib/weblogic.jar
export CLASSPATH
... .... ... .... ... .... ... .... ... .... ... ....
|
$ vi ./nagios.cfg
... .... ... .... ... .... ... .... ... .... ... ....
# Define a host for the local machine
define host{
use linux-box ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name sol_172.2.10.2
alias sol_172.2.10.2
address 172.2.10.2
}
#the check_wls_server_myserver on the remote host.
define service{
use generic-service
host_name sol_172.2.10.2
service_description Weblogic Server myserver
check_command check_nrpe!check_wls_server_myserver
}
#the check_wls_jdbcpool_mypool on the remote host.
define service{
use generic-service
host_name sol_172.2.10.2
service_description Weblogic JDBCPool mypool
check_command check_nrpe!check_wls_jdbcpool_mypool
}
|
图5.1 |
|
本文出自 “sky” 博客,请务必保留此出处http://skymax.blog.51cto.com/365901/101603
之前的文章中介绍了如何通过编写自己的脚本,并通过Nagios监控Weblogic服务。近日在实践中配置该监控,发现了之前脚本中的一些不足,进行了脚本修改。现将脚本共享。
脚本的名称是check_weblogic.sh,可以建立一个软link check_weblogic
1、使用的方法如下,
check_weblogic.sh -H host -p port -v '--type [jdbcpool|server] --username username --password password --domain domainname --server servername [--pool poolname]'
其中,
host -- 主机名/IP
port -- weblogic server的端口号
-v后面的参数是具体的监控内容,可监控server和jdbcpool。
一共三个参数。
例如 ,
要监控的weblogic配置情况如下
例1
主机IP:192.168.10.1
端口:9503
域:mydomain
server:myserver
用户名和密码:weblogic/weblogic
则,监控命令如下,
./check_weblogic.sh -H 192.168.10.1 -p 9503 -v '--type server --username weblogic --password weblogic --domain mydomain --server myserver'
运行结果
OK - mydomain:myserver State is RUNNING,HealthState is State:HEALTH_OK,ReasonCode:[,]
2、将其配置到Nagios中
首先需要修改${NAGIOS_HOME}/etc/objects/commands.cfg,增加一个命令配置。
添加如下内容,
# 'check_weblogic' command definition
define command{
command_name check_weblogic
command_line $USER1$/check_weblogic -H $HOSTADDRESS$ -p $ARG1$ -v "$ARG2$"
}
其中,HOSTADDRESS是主机IP,ARG1是端口号,ARG2是监控内容
然后就可以定义service了,我们通过一个例子来说明,监控的是“例1”中weblogic实例,具体的配置应如下,
define service{
use generic-service
host_name linux_192.168.10.1
service_description Weblogic myserver
check_command check_weblogic!9503!--type server --username weblogic --password weblogic --domain mydomain --server myserver
}
其中,linux_192.168.10.1是之前配置过的一个主机。
3、其他
当然如果你使用NRPE来获得被监控主机的信息,那么配置上就没这么繁琐了,至少commands.cfg的配置就省去了,可以直接将监控的内容配置成nrpe.cfg中的command就行了,例如,
command[check_wls_mydomain_myserver]=/usr/local/nagios/libexec/check_weblogic -H 192.168.10.1 -p 9503 -v '--type server --username weblogic --password weblogic --domain mydomain --server myserver'
Nagios端直接通过check_nrpe调用该command就可以获得相应server的健康情况了。
本文出自 “sky” 博客,请务必保留此出处http://skymax.blog.51cto.com/365901/258593
========================================
http://www.cnblogs.com/firstyi/archive/2007/09/24/904285.html
weblogic中snmp的使用
SNMP:简单网络管理协议,SNMP 使网络管理员能够管理网络效能,发现并解决网络问题以及规划网络增长。通过 SNMP 接收随机消息(及事件报告)网络管理系统获知网络出现问题。目前, SNMP 有 3 种: SNMPV1 、 SNMPV2 、 SNMPV3。第 1 版和第 2 版没有太大差距,但 SNMPV2 是增强版本,包含了其它协议操作。与前两种相比, SNMPV3 则包含更多安全和远程配置。为了解决不同 SNMP 版本间的不兼容问题, RFC3584 种定义了三者共存策略。
SNMP OID:SNMP Object Identifiers(对象标示符),SNMP对象标识符(OID)是定义在特定MIB模式中的值,来定义一个特定的在MIB数据库中SNMP目标。SNMP OID是划界序列数字组成a.b.c...x.y.z的周期。它对信息的一个项目是一个独特的标识符,其是一个MIB的一部分。典型的OIDs能够有与它们相关的名字。OIDs在自然中是分等级的。因此1.2.3出现在1.3之前但是在1.2之后。MIB 会为其描述的每个受管对象分配一个唯一的、不可变的编号,称为对象标识符(Object Identifier,简称 OID)。每个 OID 包含一个从左到右的整数序列。此序列定义 MIB 树中的对象的位置,并指定通过树到达此对象的唯一路径。此路径中的每个节点均有一个编号和一个与编号关联的名称。
路径 .1.3.6.1.4.1 定义 private.enterprises OID,树上此节点下的每个编号代表树中为特定供应商(如 BEA)保留的分支。BEA MIB 注册在树中的位置 .1.3.6.1.4.1.140,WebLogic Server MIB 包含 .1.3.6.1.4.1.140.625 下的所有 OID
管理信息库(MIB)是一个具有分层特性的信息的集合,我们可以通过 SNMP 去存取它。MIB 的成员是一些被管理的对象(Managed Object),以对象标示符(Object Identifiers)来区分它们。
在bea目录下有一个BEA-WEBLOGIC-MIB.asn1文件,保存了snmp的配置,具体配置的含义可以参照:http://e-docs.bea.com/wls/docs81/snmp/index.html
如果想加入自己的OID,可以将将OID 相应的包放到 %WL_HOME%\server\lib\mbeantypes 目录下就可以了(这个我也没有试过)
要使用weblogic的snmp功能首先要在weblogic的控制台中启用snmp功能,然后就可以使用oid来获得堆栈、内存等使用信息了
在Services/SNMP下:

在weblogic中提供了1万多的oid可以给第三方软件使用,我们也可以使用unix自带的snmpwalk命令去取得各个oid的值,以下列出几个例子:












其中第二个oid和jrockit有关,所有和jrockit有关的oid在默认情况下都是不可以使用的,必须在weblogic启动时将jdk改为jrockit jdk才可以,这个是bea公司自己的jdk
在java中我们也可以使用snmp4j去存取snmp的值,进行远程控制,下面一段代码就是用来取得所有的oid的:
























































































要特别注意ip、端口、版本号、community和配置的一致
....
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步