……
![nagios-monitor-01](http://www.linuxcache.com/wp-content/uploads/2013/04/nagios-monitor-01.png)
主配置文件nagios.cfg默认引用的对象配置文件
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
Localhost监控对象配置文件分析
定义主机
define host{
use linux-server
host_name localhost
alias localhost
address 127.0.0.1
}
use 定义当前主机使用的主机模板,引用在templates.cfg中已定义的linux-server主机模板
hostname 定义显示在nagios web管理界面中的主机名称
alias 别名,主机名的完整描述
address 定义当前主机IP地址
定义主机组
define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members localhost
}
主机组用来定相似服务类型或处于同一地域的一组主机
hostgroup_name 定义当前主机组名称
alias 主机组别名,主机组名称的完整描述
members 定义当前主机组中包含的主机,使用已定义主机名称并使用逗号分隔
定义服务(定义具体的监控项目)
监控已定义主机localhost的ping响应
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
use 引用在templates.cfg中已定义的服务模板
hostname 指定启用此监控项目的已定义的主机名
service_description 显示在nagios web界面的服务名称
check_command
配置文件中检测命令的完整工作过程
查看
[root@monitor objects]# pwd
/usr/local/nagios/etc/objects
[root@monitor objects]# ls ../../libexec/check_ping
../../libexec/check_ping
[root@monitor objects]#
[root@monitor objects]# ../../libexec/check_ping
check_ping: Could not parse arguments
Usage:
check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>%
[-p packets] [-t timeout] [-4|-6]
[root@monitor objects]#
-w 指定警告数值和百分比
-c 指定临界数值和百分比
nagios检测命令的完整格式及返回结果
[root@monitor objects]# ../../libexec/check_ping -H localhost -w 100.0,20% -c 500.0,60%
PING OK - Packet loss = 0%, RTA = 0.05 ms|rta=0.046000ms;100.000000;500.000000;0.000000 pl=0%;20;60;0
[root@monitor objects]#
响应时间达到或超过100毫秒进入警告状态,响应时间达到或超过500毫秒进入临界状态
检测得到的实际响应时间为0.05毫秒
监控已定义主机的localhost的根分区(/)可用磁盘容量
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
check_command中的check_local_disk实际为引用命令定义文件commands.cfg已定义命令名称
# ‘check_local_disk’ command definition
define command{
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
nagios检测命令的完整格式及返回结果
[root@monitor libexec]# ./check_disk
check_disk: Could not parse arguments
Usage:
check_disk -w limit -c limit [-W limit] [-K limit] {-p path | -x device}
[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]
[-t timeout] [-u unit] [-v] [-X type]
[root@monitor libexec]# ./check_disk -w 20% -c 10% -p /
DISK OK – free space: / 45970 MB (96% inode=98%);| /=1866MB;40316;45356;0;50396
[root@monitor libexec]#
监控已定义主机的localhost的当前登录用户
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
监控已定义主机的localhost的进程数量
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
监控已定义主机的localhost的负载状态
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Current Load
check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}
监控已定义主机的localhost的磁盘交换空间使用状态
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Swap Usage
check_command check_local_swap!20!10
}
监控已定义主机的localhost的ssh服务或端口开启状态
define service{
use local-service ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
监控已定义主机的localhost的web服务或80端口状态
define service{
use local-service ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
}