diff --git a/data/update.php b/data/update.php index 0c28daa..c4a4b11 100755 --- a/data/update.php +++ b/data/update.php @@ -1,14 +1,14 @@ errorCode() && $SQL->errorCode() !== '00000') { die($SQL->errorCode()); } - + $SQL->query('CREATE TABLE IF NOT EXISTS service_status(service TEXT, timestamp DATETIME DEFAULT CURRENT_TIMESTAMP, ping INTEGER, status INTEGER, PRIMARY KEY(service, timestamp))'); - + foreach($CONFIG['services'] as $id=>$data) { $services[$id] = array( 'name'=>$data['name'], @@ -23,7 +23,7 @@ $pings = array(); $i = 0; foreach ($data['ports'] as $port) { $starttime = microtime(true); - if ($fp = fsockopen($data['hostname'],$port,$errno,$errstr,15)) { + if ($fp = @fsockopen($data['hostname'],$port,$errno,$errstr,15)) { $stoptime = microtime(true); $newping = ($stoptime - $starttime) * 1000; $pings[$i++] = $newping; @@ -34,20 +34,20 @@ else if ($i > 0 && ($ping_sum = array_sum($pings)) > 0) $ping = round($ping_sum / $i, 2); } - + // Check for PID (status) if (isset($data['pidfile'])) { if (!posix_getpgid(file_get_contents($data['pidfile']))) $status = -1; } - + // Check for process (status) if (isset($data['process']) && !isset($data['pidfile'])) { $otp; $rtn; exec('pgrep -fl "'.$data['process'].'"', $otp, $rtn); if ($rtn!=0) $status = -1; } - + if ($stmt = $SQL->prepare('INSERT INTO service_status(service, timestamp, ping, status) VALUES (?, ?, ?, ?)')) { $stmt->bindParam(1, $id); $stmt->bindParam(2, $timestamp); @@ -56,7 +56,7 @@ $stmt->execute(); $stmt->closeCursor(); } - + if ($stmt = $SQL->prepare('SELECT timestamp,ping,status FROM service_status WHERE service = ? ORDER BY timestamp DESC LIMIT ?')) { $stmt->bindParam(1, $id); $stmt->bindParam(2, $CONFIG['max_slices']); @@ -69,46 +69,53 @@ $stmt->closeCursor(); } $services[$id]['status'] = array_reverse($services[$id]['status']); + + if ($stmt = $SQL->prepare('DELETE FROM service_status WHERE service = :service AND timestamp NOT IN ( SELECT timestamp FROM service_status WHERE service = :service ORDER BY timestamp DESC LIMIT :limit )')) { + $stmt->bindParam('service', $id); + $stmt->bindParam('limit', $CONFIG['max_slices']); + $stmt->execute(); + $stmt->closeCursor(); + } } ?> <?=$CONFIG['page_name'];?> - '> - - '> - '> - - - - - + ' /> + + ' /> + ' /> + + + + +
- - $service) { - echo ''; - echo ''; - echo ''; - foreach ($service['status'] as $slice) { + + $service): ?> +
'; - if (!empty($service['message'])) { - echo '
'; - if (!empty($service['icon'])) - echo ' '; - echo $service['name'].''.$service['message'].'
'; - } else { - if (!empty($service['icon'])) - echo ' '; - echo ''.$service['name'].''; - } - echo '
+ + + + + 0 || ($slice['status'] == -1 && $slice['ping'] > 0)) { $cell_status = 'partial'; $bgclrstyle = sprintf("#%02x%02x%02x", 255, 128, 0); @@ -118,19 +125,20 @@ } else { $cell_status = 'ok'; $bgclrstyle = sprintf( - "#%02x%02x%02x", + "#%02x%02x%02x", $slice['ping']!=-1?max(0, min(255, round($slice['ping'])*2)):0, max(0, min(255, 128+(round($slice['ping'])/2))), 0 ); } - - echo ''; - } - echo '
'> + +
+ ' height='16' /> + +
+ + ' height='16' /> + +
'."\n"; - } - ?> -
+ ?> + + '> + + + + +
\ No newline at end of file