From: | Andy Colson <andy(at)squeakycode(dot)net> |
---|---|
To: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Log file monitoring and event notification |
Date: | 2014-04-05 15:47:14 |
Message-ID: | 53402582.8040002@squeakycode.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi All.
I've started using replication, and I'd like to monitor my logs for any errors or problems. I don't want to do it manually, and I'm not interested in stats (a la PgBadger).
What I'd like, is the instant PG logs: "FATAL: wal segment already removed" (or some such bad thing), I'd like to get an email.
1st: is anyone using a program that does something like this? What do you use? How do you like it?
My thinking has been along these lines:
+ log to syslog doesnt really help, and I recall seeing somewhere "syslog may not capture everything". I still have monitoring and log rotation problems.
+ log to stderr and write my own collector works, but then I have to duplicate what logging_collector already does (rotating, truncating, age, size, etc). Too much work.
+ log with logging_collector, then write a thing to figure out what file its writing to and tail it, watch for rotation, etc. This is just messy.
If there isn't a program already available (which I've searched for, believe me), I'd like to get feedback on extending logging_collector with some lua scriptable event notification.
Lua is small, fast, and mostly easy to embed. It would allow an admin to customize whatever kind of monitoring they want. When an event matches logging_collector would spawn off a different app to handle the event notification. The app would be launched in the background and forgotten about so that logging isn't delayed.
I'm thinking:
function checkLine(item)
if item:find('FATAL') then
launch('/usr/bin/mynotify.pl', item)
end
end
Logging_collector would then do something like (forgive the perl pseudo code):
... regular log file rotation stuff ..
open OUT
while ($line = <stderr>)
{
checkLine($line);
print OUT $line;
}
... etc, etc ...
Lua could also have another handy events defined:
OnLogRotate(newFile)
OnStartup()
OnShutdown()
Lua can also keep state, so maybe you dont want to email on the first FATAL, but on the third.
local cc = 0
function checkLine(item)
if item:find('FATAL') then
cc = cc + 1
if cc > 2 then
launch('/usr/bin/mynotify.pl', item)
cc = 0
end
end
end
Thoughts?
-Andy
From | Date | Subject | |
---|---|---|---|
Next Message | Antman, Jason (CMG-Atlanta) | 2014-04-05 19:17:49 | Re: Log file monitoring and event notification |
Previous Message | Scott Marlowe | 2014-04-05 15:26:00 | Re: SSD Drives |