LINUX开源监控平台Nagios(服务监控配置)

服务监控的配置

Nagios
监控的主要内容,也是我们最为关注的内容是对服务的监控。Nagios中对服务的定义方式与上文中定义主机的方式一致,参数也大体相同。下面列出定义servce的参数,其含义大多在上文中介绍过了,此处及就不再介绍了。
 
代码:
define service {
host_name host_name
service_description service_description
servicegroups servicegroup_names
is_volatile [0/1]  # 是否启用“volatile”模式。这个模式的含义是说名这个服务是不稳定的,或者说是危险的。只要其状态改变了,就不会再自己被恢复回来。这个参数很少使用,等到使用的时候我们再来细说。
check_command command_name
max_check_attempts #
normal_check_interval #
retry_check_interval #
active_checks_enabled [0/1]
passive_checks_enabled [0/1]
check_period timeperiod_name
parallelize_check [0/1]
obsess_over_service [0/1]
check_freshness [0/1]
freshness_threshold #
event_handler command_name
event_handler_enabled [0/1]
low_flap_threshold #
high_flap_threshold #
flap_detection_enabled [0/1]
process_perf_data [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
notification_interval #
notification_period timeperiod_name n
otification_options [w,u,c,r,f]
notifications_enabled [0/1]
contact_groups contact_groups
stalking_options [o,w,u,c]
}
ok ,还是让我们来举例说明一下吧。

1
、随时监控Web.TEST主机上的HTTP服务(80端口),发生两次不能访问及认定是发生故障,故障累计3次告警,联系人组是mygroup。告警之后每两分钟再进行一次检查,如果10分钟之后仍然没有恢复,再发送一次告警。
 
代码:
define service {
host_name Web.TEST
service_description check_tcp 80
check_period 24x7
max_check_attempts 2
normal_check_interval 3
retry_check_interval 2
contact_groups mygroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80
}
如果要检测其他服务,则将代码中蓝色的两行修改即可。例如,要检查默认的ssh服务是否开启:
 
代码:
define service {
host_name Web.TEST
service_description check_ssh
check_period 24x7
……
check_command check_ssh
}

其他配置文件contactstimeperiods

nagios
中还有非常丰富的个性配置,这里我们先简单的配置一些,让nagios可以先用起来。

1
、文件contactgroups.cfg,用来定义联系人组。多个组员用隔开。
 
代码:
define contactgroup {
contactgroup_name mygroup
alias network administrator group
members feiyang,bb,cc
}
2 、文件contacts.cfg,用来定义联系人。
 
代码:
define contact {
contact_name feiyang
alias hosts & network administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email host_notification_commands notify-by-email
email [email protected]
}
3 、文件timeperiods.cfg,用来定义时间段
 
代码:
define timeperiod {
timeperiod_name WorkTime
alias 10 Hours A Day, 5.5 Days A Week
sunday 07:30-17:30
monday 07:30-17:30
tuesday 07:30-17:30
wednesday 07:30-17:30
thursday 07:30-17:30
friday 07:30-17:30
saturday 07:30-12:00
}

你可能感兴趣的:(linux,职场,nagios,休闲)