check_logfiles postgres ログ監視

log_directory = '/var/log/pgsql' 
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' 
log_file_mode = 0644
log_rotation_age = 1d 
log_rotation_size = 0 

/var/log/pgsql/postgresql-2019-07-19_000000.log 
/usr/local/etc/check_logfiles_postgres.cfg

@searches = {
  tag => 'postgres',
  logfile => '/var/log/pgsql/dummy',
  archivedir => '/var/log/pgsql',
  rotation => 'postgresql-\d{4}-\d{2}-\d{2}_\d{6}.log',
  type => 'rotating::uniform',
  criticalpatterns => [
      '\] (ERROR|FATAL|PANIC):'
  ],
};

/usr/local/etc/nrpe.d/check_postgres.cfg 

command[check_logfiles_postgres]=/usr/local/libexec/nagios/check_logfiles -f /usr/local/etc/check_logfiles_postgres.cfg

  • /var/log/pgsql/dummy は存在しなくてOK

rotating::uniform

--tag failorder --type rotating::uniform --logfile /test/dummy \
--rotation "james-${date +"%F"}_\d+-${HOSTNAMEIP}-appserver0.log"

If you add a "-v" you can see what happens inside. Type rotating::uniform tells check_logfiles that the rotation scheme makes no difference between current log and rotated archives regarding the filename. (You frequently find something like xyz..log). What check_logfile does is to look into the directory where the logfiles are supposed to be. From /test/dummy it only uses the directory part. Then it takes all the files inside /test and compares the filenames with the --rotation argument. Those files which match are sorted by modification time. So check_logfiles knows which of the files in question was updated recently and the newest is considered to be the current logfile. And inside this file check_logfiles searches the criticalpattern. Gerhard
https://stackoverflow.com/questions/53369095/how-do-i-use-nagios-to-monitor-a-log-file-that-generates-a-random-id

参考

https://github.com/lausser/check_logfiles/issues/31#issuecomment-331728873
https://www.ashisuto.co.jp/db_blog/article/20151221_pg_monitoring.html
https://labs.consol.de/nagios/check_logfiles/examples/