Monitoring ZM state

Forum for questions and support relating to the 1.30.x releases only.
Locked
stevewrightnz1
Posts: 55
Joined: Mon Jun 08, 2015 9:57 am
Location: New Zealand
Contact:

Monitoring ZM state

Post 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
gert
Posts: 14
Joined: Fri Jul 01, 2016 12:43 am

Re: Monitoring ZM state

Post 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
User avatar
knight-of-ni
Posts: 2404
Joined: Thu Oct 18, 2007 1:55 pm
Location: Shiloh, IL

Re: Monitoring ZM state

Post 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.
Visit my blog for ZoneMinder related projects using the Raspberry Pi, Orange Pi, Odroid, and the ESP8266
All of these can be found at https://zoneminder.blogspot.com/
Tantamount
Posts: 76
Joined: Wed Feb 03, 2016 7:51 am

Re: Monitoring ZM state

Post 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.
3 ReoLink RLC-410
2 Annke NC800
Kubernetes 1.22.6 statefulset of 5 Ubuntu 20.04 pods using iconnor's repository
ZoneMinder Version 1.36.12
stevewrightnz1
Posts: 55
Joined: Mon Jun 08, 2015 9:57 am
Location: New Zealand
Contact:

Re: Monitoring ZM state

Post 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
c128
Posts: 88
Joined: Sat Sep 14, 2013 3:36 pm

Re: Monitoring ZM state

Post 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 4928 times
Locked