Page 1 of 1

Monitoring ZM state

Posted: Tue Nov 01, 2016 10:03 pm
by stevewrightnz1
Hi guy's

I want to be able to monitor the status of ZM to ensure that it up as much as possible.

My thoughts are along the lines of a python of perl script triggered by cron say every 15-30 minutes that sends an email if I get a "Stopped" status.

Is there a map somewhere of where variables are stored in the sql database of choice?

I'm think I'm possibly looking to test the "Running" part of this "ZoneMinder Console - Running - default v1.30.0" on the ZM console page which I assume is pulled from somewhere in the MySQL database when the page is generated?

Any Ideas??

Steve

Re: Monitoring ZM state

Posted: Tue Nov 01, 2016 10:50 pm
by gert
If you're running on the machine with zoneminder, you can just use `sudo service zoneminder status`. I'm looking into this myself, and would also monitor mysql, as in my case, that has been the source of my downtime. Having not messed with cron jobs, I tend to default to creating upstart jobs.

Relevant notes:
Return code of `sudo service XXXX status`:
mysql stopped: 0
mysql running: 0
zoneminder stopped: 1
zoneminder running: 0

Output of `sudo service XXXX status`:
mysql stopped: mysql stop/waiting
mysql running: mysql start/running, process #####
zoneminder stopped: ZoneMinder is stopped
zoneminder running: ZoneMinder is running

Re: Monitoring ZM state

Posted: Tue Nov 01, 2016 11:40 pm
by knight-of-ni
Why roll your own solution when you can use a health monitoring solution, like Zabbix? It can get send emails and can log just about anything for you.

If you are running a recent distro (i.e. have systemd) and simply want to restart zoneminder if it stops (and you don't want to figure out why it stopped in the first place), then just put "Restart=Always" into your zoneminder service file, then issue a daemon-reload.

Also note that, if you have a "Requires" statement in your service file, systemd will stop zoneminder if mysql or http stop for any reason.... so the cause of zoneminder stopping might be due one of those other services.

Re: Monitoring ZM state

Posted: Wed Nov 02, 2016 12:02 am
by Tantamount
Some quick ways to check the health:

look at "ps" output and check to see if zmc processes exist. No zmc == no working monitors.

Query the "Logs" table for recent entries. It's fairly noisy and contains timestamps, so should have recent timestamps. Can't query table? mysql trouble. Timestamps too old? trouble. Lots of recent entries with "ERR" code? Could be trouble.

Re: Monitoring ZM state

Posted: Sat Nov 05, 2016 3:08 am
by stevewrightnz1
Looks like monitoring the Logs table might work for what I want. Judging by the entries it looks like a ton of stuff gets written to the MySQL table so I'm guessing that if nothing is written for say 5 minutes (300 seconds) then something is probably awry? Really just looking for an email telling me to have a look.

Will write a small perl script and run a cron job every 30 minutes to see what happens.

Steve

Re: Monitoring ZM state

Posted: Sat Nov 05, 2016 11:16 pm
by c128
You *could* roll something yourself, or you could just make use of the free offering from Datadog: https://www.datadoghq.com/pricing/

The no cost option with them will cover 5 hosts, and if you install the Datadog agent on your Zoneminder box you can trigger email alerts based on whatever you want (as well as see past metrics history for memory usage, CPU usage etc. on your box).

I use Datadog at work for monitoring AWS services, but it works great (for free) for monitoring a handful of home servers - been using it recently to understand some Zoneminder-related CPU issues, and have an email monitor setup based on a CPU metric from the agent. Uptime can be dealt with in a similar way:

http://docs.datadoghq.com/integrations/process/
https://www.datadoghq.com/blog/introduc ... onitoring/

Most of the other (mostly cloud) monitoring services have a similar free offering (New Relic, etc.) - unless you're running on ARM, then their agents install quickly and easily and with very little overhead.

Incidentally, Datadog also has integrations for MySQL, Apache etc. So, if you want, you can get specific metrics on those too.

Attached is an example of some of my Zoneminder host's stats from the last month, just to see the sort of "extras" you get (for nothing).
datadog_zoneminder.png
datadog_zoneminder.png (168.78 KiB) Viewed 5533 times