Add host uptime in _status/format=xml page

Issue #1070 resolved
B created an issue

I am using monit status page formatted as xml to track health data of hosts and monitored services.

One of the things that is of interest to me is the host uptime, but that is not present in the xml, while it is present in the txt format.

Adding something like the following snippet after line 502 ( if (S->type == Service_System) { ) in src/http/xml.c could solve this problem:

StringBuffer_append(B, "<uptime>%lld</uptime>", (Time_now() - systeminfo.booted) );

Comments (10)

  1. Lutz Mader

    Nice idea, I think.
    In "<monit><server>" the uptime depend to the monit process and in "<service name="PROC"><type>3</type>" to the monitored process uptime. In "<service name="SYSTEM"><type>5</type>" the uptime is not available.

    But the system uptime is available via command line or web access in the system status overview. The uptime data should be availabel in the xml output (the uptime in secounds) too.

    A usefull idee/suggestion,

  2. Lutz Mader

    I add the uptime and boottime to “xml.c” and do some more testing, I’ll be back with a pull request.

    case Service_System:
                    (long long)(Time_now() - systeminfo.booted),
                    (long long)(systeminfo.booted),



    The boot time is available via the command line and web interface too.

  3. B reporter

    Thank you so much Lutz!

    I could’ve also used the txt format, or any other method to get the system uptime, but having it in the xml would make life a lot easier for me. I’m using the xml to get the status of some monitored devices in zabbix. I get everything I need from the xml, except the system uptime. I was interested in raising some alarms when one of the monitored services restarts, or when the host restarts. For the host restart I had to compare the current system uptime (which was in fact monit uptime) with the uptime of other services, to see if only monit restarted or the host restarted. But this broke some things in zabbix, because I had to insert some artificial dependencies between the monitored services templates. Having the system uptime in the xml can keep the templates clean, with no other dependencies, and also make sure that the data is accurate by not having to get other infos by other methods (which in turn would cause other uncertainties… is the web page filtered? did something change in the web page format? was there an error running an ssh script? is ssh active? was there an error parsing the response? etc)

    Thank you again and all the best!


  4. Lutz Mader

    Hello Bogdan,
    I will add a _runtime/format=xml post to retrieve some additional information from the monitor.

    See #1087: Runtime information command line option

    A runtime command line option is available yet (in my environment).

    For your information only,

  5. Log in to comment