緊接前面兩篇,前面已經搭建了.111上icinga的伺服器,並且監控了遠程.131Linux伺服器的HTTP服務。
因為HTTP服務屬於public service, 不需要在遠程機器上安裝agent,但是如果需要監控.131的本地資源,比如磁碟,CPU等,就需要安裝一個軟體。
icinga提供了兩種模式,一種叫做active check,就是server .111輪詢.131,這種效率不搞,不推薦。還有另一種模式,passive check, 是等待遠程agent發送訊息。
NSCA外掛程式和icinga配合使用就能達到這種效果。這是推薦的,很可惜,該項目已經從去年終止了,如果想繼續,就得自己來了。
先看看怎麼用吧。這篇文檔可以協助我們安裝和使用。http://docs.icinga.org/latest/en/nsca.html
我只說要點:
1. 當運行
./nsca -c ../sample-config/nsca.cfg
出現許可權不足時,簡單點,直接用chmod -R 777 修改該目錄許可權
2. 10.3.6中選擇xinetd方式,Ubuntu下先要安裝:
apt-et install xinetd
然後編輯/etc/hosts.allow 檔案,加一行:
ALL: 10.112.18.131
3. 把一些檔案拷貝的131機器上後,沒有必要建立什麼incinga使用者,直接用root就可以測試
4. .111 icinga server上linux.cfg檔案配置如下:
define host{ use linux-server ; Inherit default values from a template host_name StaticFileServer ; The name we're giving to this host alias static filer server for 3D and jenksins server for CloudEngine ; A longer name associated with the host address 10.112.18.131 ; IP address of the host contact_groups admins ; Host groups this host is associated with } # check that web services are running define service{ host_name StaticFileServer service_description HTTP check_command check_http use generic-service action_url http://10.112.18.131/ArcGIS/rest/services/SanFrancisco/3DFeatureServer notification_interval 0 ; set > 0 if you want to be renotified } define service{ use generic-service ; template to inherit from name passive-service ; name of this template active_checks_enabled 0 ; no active checks passive_checks_enabled 1 ; allow passive checks check_command check_dummy!0 ; use "check_dummy", RC=0 (OK) check_period 24x7 ; check active all the time check_freshness 0 ; do not check if check result is stale register 0 ; this is a template, not a real service } define service{ use passive-service ; template to inherit from host_name StaticFileServer ; host where send_nsca is located service_description Diskspace ; service to be checked }
5. 記錄檔位置: /usr/local/icinga/var/icinga.log
6. commands.cfg中已經定義了check_dummy命令,不需要修改
7. .131上運行命令測試發送資料:
echo -e "StaticFileServer\tDiskspace\t0\t/var=78%\n" | /usr/local/icinga/bin/send_nsca -H 10.112.18.111 -c /usr/local/icinga/etc/send_nsca.cfg
注意StaticFileServer大小寫不能錯, /var=78% 是發送的資訊。
-H後面是icinga server的IP地址
8. 最後看日誌中有了:
[1368620324] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;StaticFileServer;Diskspace;0;/var=78%[1368620332] PASSIVE SERVICE CHECK: StaticFileServer;Diskspace;0;/var=78%
9. web 頁面上也能看到一行記錄。
不過寫完文章就看不到了,還是對icinga不熟悉啊。回頭找到了再。
總結:NSCA就是解決了監控終端發送訊息給伺服器的通訊問題,監控指令碼要自己編寫,用來採集資料。因此這個架構很靈活,可以隨便發揮。不過就是做的事情不少,後面會嘗試整體解決方案:Check_MK, 如果能夠在這上面二次開發,功能就非常強大了。