System uptime on main page.

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
ryscar
Posts: 9
Joined: Tue Jul 10, 2007 1:45 pm
Location: Mesa, AZ

System uptime on main page.

Post by ryscar »

I know this can be accomplished via the command line but, for those who are not granted access to this, it would be helpful. It would let someone know if the power had been shut off to the box.
apcyberax
Posts: 30
Joined: Tue Jun 12, 2007 6:56 pm

Post by apcyberax »

a better idea is to use a UPS like me then it won't matter if the power fails. unless its down for hours
User avatar
AmmarossDanan
Posts: 19
Joined: Tue Jul 03, 2007 10:05 pm
Location: Salt Lake, UT, US

Post by AmmarossDanan »

Place this in the area of your zm_html_view_console.php script you want to display the system uptime. (Mine is right under the date/time in upper-left).
Starting with line 224:
! <td class="smallhead" style="line-height:11px" align="left"><?= preg_match( '/%/', DATE_FMT_CONSOLE_LONG )?strftime( DATE_FMT_CONSOLE_LONG ):date( DATE_FMT_CONSOLE_LONG ) ?><br/>
+ <? /* Display system uptime */
+ $uptime = `uptime`;
+ $start = strpos( $uptime, "up " );
+ $length = strpos( $uptime, ", ", $start )-$start;
+ print( substr( $uptime, $start, $length ) ); ?></td>
<td class="bighead" align="center"><strong><a href="http://www.zoneminder.com" ...
! <td class="smallhead" align="right" valign="top"><?= $zmSlangLoad ?>: <?= ...
I would use reg expressions, but I'm not the best at those just yet. :P Anyway, strpos is a faster routine.
Ammaross Danan
KegRaider
Posts: 25
Joined: Mon Sep 05, 2005 5:06 am
Location: Townsville/Queensland/Australia

Post by KegRaider »

Cool mod AmmarossDanan,

I just finished applying it, and looks great. Is there a way to get the hours too? I tried modifying the "+$length = " section, but ended up with all the info (users, load etc).

--> Troy.
User avatar
ammaross
Posts: 61
Joined: Mon Mar 12, 2007 8:34 pm
Location: Utah, USA

Post by ammaross »

Unfortunately, the method being used (the uptime command) only displays days of uptime, unless you've been up for less than a day, then it gives hours (or minutes if up for less than an hour).

If you want, you can pull the exact uptime (in seconds) from /proc/uptime and use that:

Code: Select all

if ( ($uptime = file("/proc/uptime")) != NULL )
{
   if ( ($base = explode( " ", $uptime[0] )) != NULL )
   {
        $days = floor($base[0]/(24*60*60));
        $base[0] -= ($days*24*60*60);
        $hours = floor($base[0]/(60*60));
        $base[0] -= ($hours*60*60);
        $minutes = floor($base[0]/60);
        $base[0] -= ($minutes*60);
        $seconds = floor($base[0]);
        if ($days > 0) print( "$days day" . ($days>1?"s":"") . ", " );
        print(" $hours hr" . ($hours>1?"s":"") . ",
                 $minutes min" . ($minutes>1?"s":"") . ",
                 $seconds sec" . ($seconds>1?"s":"") );

   }
}
else
{
   $uptime = `uptime`;
   $start = strpos( $uptime, "up " );
   $length = strpos( $uptime, ", ", $start )-$start;
   print( substr( $uptime, $start, $length ) );
}
Just plug that in in place of the other uptime code and it should work. If you have any problems, let me know.

($base[1] will contain the idle time of the CPU, in case you wanted to use that for anything as well.)
Post Reply