Thread: Extension to monitor errors in log

Extension to monitor errors in log

From
Святослав Ермилин
Date:
Hi!
I wrote extension for postgresql that is collecting statistics about errors in logfile.

This extension counts the number of messages of each type and code.
It's designed to enable monitoring tools. I'm going to use it as a data source for plot of number of errors, warnings
andfatals.
 
Source code is here: https://github.com/munakoiso/logerrors

Design considerations.
There is a hash table in shared memory that contains counters of each type (currently only fatal, error, warning) and
everypossible error code. 
 
In emit_log_hook messages are updating this info in hash table. Then bgworker every n seconds collects and prepares
thisinfo.
 
pg_log_errors_stats() function is using this table in shared memory can show stats at last n*k seconds.

Here is an example of usage:
postgres=# select * from pg_log_errors_stats();
     time_interval |  type   |       message        | count
    ---------------+---------+----------------------+-------
                   | WARNING | TOTAL                |     0
                   | ERROR   | TOTAL                |     3
               600 | ERROR   | ERRCODE_SYNTAX_ERROR |     3
                 5 | ERROR   | ERRCODE_SYNTAX_ERROR |     2
                   | FATAL   | TOTAL                |     0

It would be very cool if someone gave me some feedback.

-- 
Sviatoslav Ermilin
Yandex