Check file and match behavior

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Check file and match behavior

Lutz Mader
Hi all folks,
a question of understanding.

One of my applications hangs sometimes after the start.
But the only hint that something is going wrong, the application does
not continue to start, is the last message in the application log on the
one hand. It's always the same message, I think.
And on the other, that no additional messages are written to the log.

Unfortunately, if everything works well, all the messages are written to
the log and some more messages also.
And it is normal behaviour that the application stop writing messages to
the log after the start, for a short time, sometimes.

My question,
any suggestion how to check a message is the last one in the log for a
given time. In my understanding, monit doesn't check a message already
checked again, monit knows the last line in the log already checked.

A suggestion,
any plan to set the service status based on messages.
Today I use the port to check the application is up and running or
restart the application if the port is not available.
I use something like this.
if failed host TheHostName port 5001 protocol http for 10 cycles then alert
if failed host TheHostName port 8080 protocol http for 20 cycles then
restart

Some of my application doesn't open a socket, I can't check a port also.
But the log contain messages like "manager initialized" or "manager
started".

Today I use commands to restart applications or disable the monitoring
for applications based on messages are written to the application log or
send mails.
I use something like this.
if match ".*Too many open files.*" then exec "/etc/monit/scripts/em.sh
restart"
if match ".*An attempt is made to stop the.*" then exec
"/etc/monit/scripts/serv.sh unmonitor server1"
if match "Press 'Enter' to acknowledge...." then alert

But I don't know a command to set the service status.
"monitor" or "unmonitor" enable/disable the monitoring only.

With regards,
Lutz

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Check file and match behavior

martinp@tildeslash.com
Hi Lutz,

if your application log is set to a standalone file, you can test a modification timestamp if it logs some messages while it is running. For example (syntax for Monit >= 5.22.0):

        check file myapp_log with path /var/log/myapp.log
                if timestamp is older than 1 hour then exec "/usr/bin/monit restart myapp"

The test will restart "myapp" service if the timestamp was not modified within last hour.

You can see more details in monit manual: https://mmonit.com/monit/documentation/monit.html#TIMESTAMP-TEST

Best regards,
Martin


> On 10 Jul 2017, at 14:08, Lutz Mader <[hidden email]> wrote:
>
> Hi all folks,
> a question of understanding.
>
> One of my applications hangs sometimes after the start.
> But the only hint that something is going wrong, the application does
> not continue to start, is the last message in the application log on the
> one hand. It's always the same message, I think.
> And on the other, that no additional messages are written to the log.
>
> Unfortunately, if everything works well, all the messages are written to
> the log and some more messages also.
> And it is normal behaviour that the application stop writing messages to
> the log after the start, for a short time, sometimes.
>
> My question,
> any suggestion how to check a message is the last one in the log for a
> given time. In my understanding, monit doesn't check a message already
> checked again, monit knows the last line in the log already checked.
>
> A suggestion,
> any plan to set the service status based on messages.
> Today I use the port to check the application is up and running or
> restart the application if the port is not available.
> I use something like this.
> if failed host TheHostName port 5001 protocol http for 10 cycles then alert
> if failed host TheHostName port 8080 protocol http for 20 cycles then
> restart
>
> Some of my application doesn't open a socket, I can't check a port also.
> But the log contain messages like "manager initialized" or "manager
> started".
>
> Today I use commands to restart applications or disable the monitoring
> for applications based on messages are written to the application log or
> send mails.
> I use something like this.
> if match ".*Too many open files.*" then exec "/etc/monit/scripts/em.sh
> restart"
> if match ".*An attempt is made to stop the.*" then exec
> "/etc/monit/scripts/serv.sh unmonitor server1"
> if match "Press 'Enter' to acknowledge...." then alert
>
> But I don't know a command to set the service status.
> "monitor" or "unmonitor" enable/disable the monitoring only.
>
> With regards,
> Lutz
>
> --
> To unsubscribe:
> https://lists.nongnu.org/mailman/listinfo/monit-general


--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general
Reply | Threaded
Open this post in threaded view
|

Re: Check file and match behavior

Lutz Mader
Hello Martin,
this is a nice idea, but doesn't work, I think, because it is necessary
to correlate the message and the timestamp check.

> check file myapp_log with path /var/log/myapp.log
> if timestamp is older than 1 hour then exec "/usr/bin/monit restart myapp"

Something like the following should work, but is not available.

if match "The message.*" and
   timestamp is older than 1 hour then alert

I try to start a script with an additional check of the last lines in
the log.

Nice suggestion,
thanks for your help,
Lutz

--
To unsubscribe:
https://lists.nongnu.org/mailman/listinfo/monit-general