2010-03-03 203 views
23

我們正在使用Nagios來監控我們的網絡並取得巨大成功。但是,我們有一個關鍵應用程序錯誤的系統日誌,雖然我設置了check_log,但似乎無法像監控設備一樣工作。如何使用Nagios監控日誌文件

的問題是:

  • 只顯示最後一個條目
  • 似乎沒有被承認的嚴重錯誤的方式和 顯示器恢復到良好的狀態

nagios是錯誤的工具,還是我們只是沒有建立服務監督權?

這裏是我的條目

# log file 
define command{ 
     command_name check_log 
     command_line $USER1$/check_log -F /var/log/applications/appcrit.log -O /tmp/appcrit.log -q ? 
} 


# Define the log monitering service 
define service{ 
     name       logfile-check   ; 
     use        generic-service   ; 
     check_period     24x7     ; 
     max_check_attempts    1      ; 
     normal_check_interval   5      ; 
     retry_check_interval   1      ; 
     contact_groups     admins     ; 
     notification_options   w,u,c,r     ; 
     notification_period    24x7     ; 
     register      0      ; 
     } 

define service{ 
     use        logfile-check 
     host_name      localhost 
     service_description    CritLogFile 
     check_command     check_log 
} 
+0

你可以發佈一份你的服務支票和你的支票指令嗎? – 2010-03-03 17:26:23

回答

3

由於有很多方法可以實現一個目標,也有來自康壽一個不錯的插件可供選擇: https://labs.consol.de/lang/en/nagios/check_logfiles/

  • 支持正則表達式
  • 支持日誌輪換

要使用它,你需要一個CFG文件,這是Oracle數據庫爲例

@searches = ({ 
    tag => 'oraalerts', 
options => 'sticky=28800', 
    logfile => '/u01/app/oracle/diag/rdbms/davmdkp/DAVMDKP1/trace/alert_DAVMDKP1.log', 
    criticalpatterns => [ 
     'ORA\-0*204[^\d]',  # error in reading control file 
     'ORA\-0*206[^\d]',  # error in writing control file 
     'ORA\-0*210[^\d]',  # cannot open control file 
     'ORA\-0*257[^\d]',  # archiver is stuck 
     'ORA\-0*333[^\d]',  # redo log read error 
     'ORA\-0*345[^\d]',  # redo log write error 
     'ORA\-0*4[4-7][0-9][^\d]',# ORA-0440 - ORA-0485 background process failure 
     'ORA\-0*48[0-5][^\d]', 
     'ORA\-0*6[0-3][0-9][^\d]',# ORA-6000 - ORA-0639 internal errors 
     'ORA\-0*1114[^\d]',  # datafile I/O write error 
     'ORA\-0*1115[^\d]',  # datafile I/O read error 
     'ORA\-0*1116[^\d]',  # cannot open datafile 
     'ORA\-0*1118[^\d]',  # cannot add a data file 
     'ORA\-0*1122[^\d]',  # database file 16 failed verification check 
     'ORA\-0*1171[^\d]',  # datafile 16 going offline due to error advancing checkpoint 
     'ORA\-0*1201[^\d]',  # file 16 header failed to write correctly 
     'ORA\-0*1208[^\d]',  # data file is an old version - not accessing current version 
     'ORA\-0*1578[^\d]',  # data block corruption 
     'ORA\-0*1135[^\d]',  # file accessed for query is offline 
     'ORA\-0*1547[^\d]',  # tablespace is full 
     'ORA\-0*1555[^\d]',  # snapshot too old 
     'ORA\-0*1562[^\d]',  # failed to extend rollback segment 
     'ORA\-0*162[89][^\d]',  # ORA-1628 - ORA-1632 maximum extents exceeded 
     'ORA\-0*163[0-2][^\d]', 
     'ORA\-0*165[0-6][^\d]', # ORA-1650 - ORA-1656 tablespace is full 
     'ORA\-16014[^\d]',  # log cannot be archived, no available destinations 
     'ORA\-16038[^\d]',  # log cannot be archived 
     'ORA\-19502[^\d]',  # write error on datafile 
     'ORA\-27063[^\d]',   # number of bytes read/written is incorrect 
     'ORA\-0*4031[^\d]',  # out of shared memory. 
     'No space left on device', 
     'Archival Error', 
    ], 
    warningpatterns => [ 
     'ORA\-0*3113[^\d]',  # end of file on communication channel 
     'ORA\-0*6501[^\d]',   # PL/SQL internal error 
     'ORA\-0*1140[^\d]',   # follows WARNING: datafile #20 was not in online backup mode 
     'Archival stopped, error occurred. Will continue retrying', 
    ] 
}); 
3

在你的配置沒有跳出我爲錯誤配置。

通過設計,check_log將只顯示一個OK消息或觸發警報的最後一個日誌條目。如果您需要查看多個條目,則需要修改該插件。

但是,我發現你沒有得到恢復有點奇怪。 check_log的工作方式(通過比較當前日誌與以前的版本),您應該在下一次服務檢查時獲得恢復。當然,除了自上次檢查以來還有額外的匹配條目添加到日誌中。

是否強制另一個服務檢查(或幾個)導致它恢復?

此外,我不打算用這種方式,但要確保它確實發生了故障。 您的日誌是否在兩次檢查之間獲得額外的匹配條目,導致它不能恢復?您的支票符合「?」這將匹配日誌中的新內容。是否有其他東西(非錯誤)被添加到日誌中,並無意中造成了匹配?

如果以上都是問題,我建議採取的Nagios的方程縮小下來。嘗試手動運行check_log(從命令行,但與nagios相同的用戶),並使用不同的舊日誌。它應該是這樣的 -

  1. 運行檢查了全新的「oldlog」 - 獲得初始化消息
  2. 運行檢查 - 檢查OK
  3. 作任何改動日誌
  4. 運行檢查 - 檢查失敗
  5. 運行檢查 - 檢查OK

如果這不起作用,那麼你知道把重點放在日誌中,oldlog,以及如何check_log做檢查。

如果它有效,那麼它更多地指向你的nagios配置的問題。

+0

謝謝。我們只是要編寫一個自定義perl腳本來做我們想要的。 – Kenoyer130 2010-03-03 21:51:08

27

對於監控日誌與Nagios的,通常在日誌檢查器將返回警告只能對每個調用時新發現的錯誤信息(因此它必須爲了保持一定的狀態,要知道忽略他們在之後的運行)。因此,我通常設置:

max_check_attempts    1 
is_volatile      1 

這使Nagios的要immeidately發出警報,但只有一次,然後回到正常。

我最喜歡的日誌檢查爲logwarn,但我有偏見,因爲我沒有找到任何現有的,我喜歡照顧自己寫的。 logwarn軟件包包含一個Nagios插件。

+3

遲到聖潔比永不迴應! – Kenoyer130 2011-01-27 17:15:24

3

有一個一個Nagios的插件,你可以用它來檢查日誌文件,它的check_logfiles,它用於掃描的正則表達式的文件的行。 此鏈接顯示,如何安裝和配置它的Nagios和opsview http://www.osupport.net/2011/log-files-monitoring-with-nagios-opsview/

+0

+1 check_logfiles,它通常還不錯。但仍然只會顯示錯誤的最後一場比賽。注意:如果沒有嚴重黑客行爲,NRPE不支持多行響應。 – 2014-10-30 01:55:55

1

我相信現在有能夠有效監控日誌真正的Nagios的插件。

http://support.nagios.com/forum/viewtopic.php?f=6&t=8851&p=42088&hilit=unixautomation#p42088

該網頁上的Nagios的插件的主頁是Nagios Log Monitor

Your [ commands.cfg file ] will contain: 

define command { 
          command_name   NagiosLogMonitor 
          command_line   $USER1$/NagiosLogMonitor $HOSTNAME$ $ARG1$ $ARG2$ $ARG3$ $ARG4$ '$ARG5$' '$ARG6$' $ARG7$ $ARG8$ $ARG9$ $ARG10$ 
} 


OR 


define command { 
          command_name   NagiosLogMonitor 
          command_line   $USER1$/NagiosLogMonitor $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$ '$ARG5$' '$ARG6$' $ARG7$ $ARG8$ $ARG9$ $ARG10$ 
} 




Your [ services.cfg file ] will look similar to: 

define service { 
         check_command       NagiosLogMonitor!logrobot!autofig!/var/log/proteus.log!15!500.html!500 Internal Server Error!1!2!-foundn 
         max_check_attempts     1 
         service_description      500_ERRORS_LOGCHECK 
         host_name         sky.blat-01.net,sky.blat-02.net,sky.blat-03.net 
         use            fifteen-minute-interval 
} 
0

的Nagios現在有與Nagios的核心,十一緊密集成的解決方案,等等。

Nagios Log Server這可以在基礎結構中任何系統上的任何日誌文件上發出任何查詢時發出警報