mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Device Availability Calculation (#11784)
* Device Availability Calculation * Travis fix * . * schema corrections * flexible duration * travis * . * . * . * . * remove not needed code * line Text to RRD * update humantime * . * only set up again if device was marked as down * set RRD area transparency * save uptime also, to keep last availability as good as possible * file description correction * look for outages even if uptime > duration
This commit is contained in:
@@ -83,4 +83,54 @@ class Time
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @param integer seconds of a time period
|
||||
* @return string human readably time period
|
||||
*/
|
||||
public static function humanTime($s)
|
||||
{
|
||||
$ret = [];
|
||||
|
||||
if ($s >= 86400) {
|
||||
$d = floor($s / 86400);
|
||||
$s -= $d * 86400;
|
||||
if ($d == 1) {
|
||||
$ret[] = $d . " day";
|
||||
} else {
|
||||
$ret[] = $d . " days";
|
||||
}
|
||||
}
|
||||
|
||||
if ($s >= 3600) {
|
||||
$h = floor($s / 3600);
|
||||
$s -= $h * 3600;
|
||||
if ($h == 1) {
|
||||
$ret[] = $h . " hour";
|
||||
} else {
|
||||
$ret[] = $h . " hours";
|
||||
}
|
||||
}
|
||||
|
||||
if ($s >= 60) {
|
||||
$m = floor($s / 60);
|
||||
$s -= $m * 60;
|
||||
if ($m == 1) {
|
||||
$ret[] = $m . " minute";
|
||||
} else {
|
||||
$ret[] = $m . " minutes";
|
||||
}
|
||||
}
|
||||
|
||||
if ($s > 0) {
|
||||
if ($s == 1) {
|
||||
$ret[] = $s . " second";
|
||||
} else {
|
||||
$ret[] = $s . " seconds";
|
||||
}
|
||||
}
|
||||
|
||||
return implode(' ,', $ret);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user