Is there a way to tell Monit to monitor by default all new services?

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

Is there a way to tell Monit to monitor by default all new services?

Ciprian Dorin Craciun
(This email is related to my other one, where on reboot I sometimes
encounter a situation when Monit seems to forget its state and set all
services and items on unmonitored.)

At the moment I explicitly set for all my services and items `mode
passive onreboot nostart` because I don't want Monit to start / stop
any services;  I just want Monit to monitor and report.

However when adding a new service (or when Monit starts without a
state file), by default Monit sets all the services and items on the
state "unmonitored".

Is there a configuration option that would by default set everything
to monitored (but not start / stop)?  Something like say `mode monitor
onreboot nostart`.

Thanks,
Ciprian.

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Lutz Mader
Hello Ciprian,
to disable all automatic restarts by monit I use "mode passive" only.

> At the moment I explicitly set for all my services and items `mode
> passive onreboot nostart` because I don't want Monit to start / stop
> any services;  I just want Monit to monitor and report.

Monit do not start a service with "mode passive".

But "set onreboot nostart" set all services to "Not monitored" after the
monit restart. This seem to me normal behaviour, I do some tests with
monit 5.27.0 for macOS.

You can not use "set onreboot nostart", if you are interresting in the
monitoring data.

With regards,
Lutz



Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Ciprian Dorin Craciun
On Thu, Aug 6, 2020 at 8:30 PM Lutz Mader <[hidden email]> wrote:

> to disable all automatic restarts by monit I use "mode passive" only.
>
> Monit do not start a service with "mode passive".
>
> But "set onreboot nostart" set all services to "Not monitored" after the
> monit restart. This seem to me normal behaviour, I do some tests with
> monit 5.27.0 for macOS.
>
> You can not use "set onreboot nostart", if you are interresting in the
> monitoring data.


Thanks for the pointers.  It is interesting and quite strange at the
same time...  :)

I say "strange" because the behaviour is somewhat counter-intuitive to
the "words" in the configuration and the manual.  For example:

* `mode passive` -- will not start / restart any services
automatically but will monitor them by default;  (I've not tested
this, I base this on what you've said in the earlier email;)
* `mode passive + set onreboot nostart` -- will not start / restart
services automatically, but will also not **monitor** them either due
to the `onreboot nostart`;  (the confusing item is that `nostart`
actually implies "unmonitor" here;)

Moreover the documentation states:
~~~~
[mode section]
In active mode, Monit will pro-actively monitor a service and in case
of problems raise alerts and restart the service. Active is the
default mode.
The passive mode is similar to the active mode, except if the service
fails, monit will not try to fix a problem by restarting the service
and will raise alerts only.
[onreboot section]
In nostart mode, the service is never started automatically after reboot
~~~~

Which implies that `passive` will "pro-actively monitor a service" but
"will not try to fix a problem", and that `onreboot` is actually
involved with the starting or not the service once the system has been
rebooted.

My expectations (based on the manual) are as follows:
* `mode` involves the act of "fixing", i.e. restarting or not a
service if it goes down;
* `onreboot` involves the act of starting or not the service on reboot;
* none of these should impact in any manner the "monitored" /
"unmonitored" status of a service;

Thanks,
Ciprian.

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Lutz Mader
Hello Ciprian,
you are rigth.

The status "Not monitoring" means ignore the resource.
The status give the information the monitoring mode is "active". But
with "mode passive" the monitor mode became "passive".

For example
Remote Host 'SVNServe'
  status                       Not monitored
  monitoring status            Not monitored
  monitoring mode              active
  on reboot                    laststate
  data collected               Thu, 06 Aug 2020 19:27:47

This is a never ending discussion, the used status and state information
are not well described today, I think.

For services/resources I am interresting in information only I do not
define a start, stop and or restart command. Without a given command,
monit can not do any action. Unfortunately you can not start a process
via monit too.

I use "mode passive" for some resources only and sometimes I use
"if does not exist then alert" to override the automatic start for a
resource.

With regards,
Lutz

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Ciprian Dorin Craciun
In my case the current `monit status` command lists something like:
~~~~
Process '...'
  status                       OK
  monitoring status            Monitored
  monitoring mode              passive
  on reboot                    nostart
~~~~

And I assume that when it starts initially it is something like:
~~~~
Process '...'
  status                       Not monitored
  monitoring status            Not monitored
  monitoring mode              passive
  on reboot                    nostart
~~~~

My initial question was if there is any option to set `monitoring
status` to `Monitored`, while leaving alone the `monitoring mode` and
`on reboot` alone.


> For services/resources I am interresting in information only I do not
> define a start, stop and or restart command. Without a given command,
> monit can not do any action. Unfortunately you can not start a process
> via monit too.

This is an issue, because I do have `start` / `stop` / `restart`
commands defined, not for Monit, but mainly to allow an operator to
quickly control a service, without SSH-ing into the machine.


However it seems I'm in a deadlock...  I do want commands to be able
to use the UI as a simple controller, but I don't want Monit to
automatically control them itself, but I do want Monit to
automatically monitor services...  :)

My guess is that there is a missing option in the configuration...

Thanks,
Ciprian.

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Lutz Mader
Hello Ciprian
you are not in a deadlock, as long as you define "mode passive" for a
service monit does not restart the service but send an alert.

> However it seems I'm in a deadlock...  I do want commands to be able
> to use the UI as a simple controller, but I don't want Monit to
> automatically control them itself, but I do want Monit to
> automatically monitor services...  :)
>
> My guess is that there is a missing option in the configuration...

You can define the start/stop/restart commands and use the commands via
the web or m/monit or the command line, this works well.

The option is available, it is "mode passive" or you override the "if
does not exist then start" by "if does not exist then alert".

With regards,
Lutz

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to tell Monit to monitor by default all new services?

Lutz Mader
In reply to this post by Ciprian Dorin Craciun
Hello Ciprian,
nice to see what is going on.

> Once I experiment I'll report back.

This is one of my services with "mode passive".

check process Gen_lfbw matching "\/bin\/[Jj]ava.*genservers\/lfbw\/"
  start program "/usr/local/etc/monit/scripts/genlfbw.sh start" with
timeout 60 seconds
  stop program "/usr/local/etc/monit/scripts/genlfbw.sh stop" with
timeout 30 seconds
  restart program "/usr/local/etc/monit/scripts/genlfbw.sh restart" with
timeout 120 seconds
  mode passive
#  if not exist for 5 cycles then start
#  if 5 restarts within 50 cycles then unmonitor
  depends on Gen_lfbw_Dir
  group Liberty

With regards,
Lutz