System uptime on main page.
System uptime on main page.
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.
- AmmarossDanan
- Posts: 19
- Joined: Tue Jul 03, 2007 10:05 pm
- Location: Salt Lake, UT, US
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:
Starting with line 224:
I would use reg expressions, but I'm not the best at those just yet. Anyway, strpos is a faster routine.! <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 ?>: <?= ...
Ammaross Danan
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:
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.)
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 ) );
}
($base[1] will contain the idle time of the CPU, in case you wanted to use that for anything as well.)