服務監控的配置
Nagios 監控的主要內容,也是我們最爲關注的內容是對服務的監控。Nagios中對服務的定義方式與上文中定義主機的方式一致,參數也大體相同。下面列出定義servce的參數,其含義大多在上文中介紹過了,此處及就不再介紹了。
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]
}
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分鐘之後仍然沒有恢復,再發送一次告警。
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
}
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
}
host_name Web.TEST
service_description check_ssh
check_period 24x7
……
check_command check_ssh
}
其他配置文件contacts、timeperiods等
nagios中還有非常豐富的個性配置,這裏我們先簡單的配置一些,讓nagios可以先用起來。
1、文件contactgroups.cfg,用來定義聯繫人組。多個組員用“,”隔開。
nagios中還有非常豐富的個性配置,這裏我們先簡單的配置一些,讓nagios可以先用起來。
1、文件contactgroups.cfg,用來定義聯繫人組。多個組員用“,”隔開。
代碼:
define contactgroup {
contactgroup_name mygroup
alias network administrator group
members feiyang,bb,cc
}
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]
}
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
}