/** * @test */ public function secondsConvert() { // this is incorrect $this->assertEquals('4 days, 4 hours, 30 seconds', Common::secondsConvert(360000)); // this says '1 hours, 30 seconds' instead. need to find out why... #$this->assertEquals('1 hours', Common::secondsConvert(3600)); }
public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } // Use sysctl to get unix timestamp of boot. Very elegant! if (preg_match('/^\\{ sec \\= (\\d+).+$/', $this->sysctl['kern.boottime'], $m) == 0) { return ''; } // Boot unix timestamp $booted = $m[1]; // Give it return array('text' => Common::secondsConvert(time() - $booted), 'bootedTimestamp' => $booted); }
public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } // Short and sweet $booted = $this->sysctl['kern.boottime']; if ($booted == false) { return 'Unknown'; } // Is it not a timestamp? if (!is_numeric($booted)) { $booted = strtotime($booted); } // Give it return array('text' => Common::secondsConvert(time() - $booted), 'bootedTimestamp' => $booted); }
/** * getUpTime. * * @return string uptime */ public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } $booted_str = ''; foreach ($this->wmi->ExecQuery('SELECT LastBootUpTime FROM Win32_OperatingSystem') as $os) { $booted_str = $os->LastBootUpTime; break; } $booted = array('year' => substr($booted_str, 0, 4), 'month' => substr($booted_str, 4, 2), 'day' => substr($booted_str, 6, 2), 'hour' => substr($booted_str, 8, 2), 'minute' => substr($booted_str, 10, 2), 'second' => substr($booted_str, 12, 2)); $booted_ts = mktime($booted['hour'], $booted['minute'], $booted['second'], $booted['month'], $booted['day'], $booted['year']); return array('text' => Common::secondsConvert(time() - $booted_ts), 'bootedTimestamp' => $booted_ts); }
public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } // Extract boot part of it if (preg_match('/^\\{ sec \\= (\\d+).+$/', $this->sysctl['kern.boottime'], $m) == 0) { return ''; } return array('text' => Common::secondsConvert(time() - $m[1]), 'bootedTimestamp' => $m[1]); }
/** * Return result. * * @return false on failure|array of the torrents */ public function result() { // Don't bother if it didn't go well if ($this->_res === false) { return false; } // it did; continue // Store rows here $rows = array(); // Start showing connections $rows[] = array('type' => 'header', 'columns' => array('Torrent', array(1, 'Done', '10%'), 'State', 'Have', 'Uploaded', 'Time Left', 'Ratio', 'Up', 'Down')); // No torrents? if (count($this->_torrents) == 0) { $rows[] = array('type' => 'none', 'columns' => array(array(9, 'None found'))); } else { // Store a total amount of certain torrents here: $status_tally = array(); // As well as uploaded/downloaded $status_tally['Downloaded'] = 0; $status_tally['Uploaded'] = 0; $status_tally['Ratio'] = ''; // Go through each torrent foreach ($this->_torrents as $torrent) { // Status count tally $status_tally[$torrent['state']] = !array_key_exists($torrent['state'], $status_tally) ? 1 : $status_tally[$torrent['state']] + 1; // Make some sense of the have so we can get it into bytes, which we can then have fun with $have_bytes = false; if ($torrent['have'] != 'None') { $have_parts = explode(' ', $torrent['have'], 2); if (is_numeric($have_parts[0]) && $have_parts[0] > 0) { switch ($have_parts[1]) { case 'TiB': $have_bytes = (double) $have_parts[0] * 1099511627776.0; break; case 'GiB': $have_bytes = (double) $have_parts[0] * 1073741824; break; case 'MiB': $have_bytes = (double) $have_parts[0] * 1048576; break; case 'KiB': $have_bytes = (double) $have_parts[0] * 1024; break; } } } // Try getting amount uploaded, based upon ratio and exact amount downloaded above $uploaded_bytes = false; if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($torrent['ratio']) && $torrent['ratio'] > 0) { $uploaded_bytes = $torrent['ratio'] * $have_bytes; } // Save amount uploaded/downloaded tally if (is_numeric($have_bytes) && $have_bytes > 0 && is_numeric($uploaded_bytes) && $uploaded_bytes > 0) { $status_tally['Downloaded'] += $have_bytes; $status_tally['Uploaded'] += $uploaded_bytes; } // Save result $rows[] = array('type' => 'values', 'columns' => array(wordwrap(htmlspecialchars($torrent['torrent']), 50, ' ', true), '<div class="bar_chart"> <div class="bar_inner" style="width: ' . (int) $torrent['done'] . '%;"> <div class="bar_text"> ' . ($torrent['done'] ? $torrent['done'] . '%' : '0%') . ' </div> </div> </div> ', $torrent['state'], $have_bytes !== false ? Common::byteConvert($have_bytes) : $torrent['have'], $uploaded_bytes !== false ? Common::byteConvert($uploaded_bytes) : 'None', $torrent['eta'], $torrent['ratio'], Common::byteConvert($torrent['up']) . '/s', Common::byteConvert($torrent['down']) . '/s')); } // Finish the size totals $status_tally['Ratio'] = $status_tally['Downloaded'] > 0 && $status_tally['Uploaded'] > 0 ? round($status_tally['Uploaded'] / $status_tally['Downloaded'], 2) : 'N/A'; $status_tally['Downloaded'] = $status_tally['Downloaded'] > 0 ? Common::byteConvert($status_tally['Downloaded']) : 'None'; $status_tally['Uploaded'] = $status_tally['Uploaded'] > 0 ? Common::byteConvert($status_tally['Uploaded']) : 'None'; // Create a row for the tally of statuses if (count($status_tally) > 0) { // Store list of k: v'ish values here $tally_contents = array(); // Populate that foreach ($status_tally as $state => $tally) { $tally_contents[] = "{$state}: {$tally}"; } // Save this final row $rows[] = array('type' => 'values', 'columns' => array(array(9, implode(', ', $tally_contents)))); } } // Handle stats which might not exist if (is_array($this->_stats) && array_key_exists('downloaded-bytes', $this->_stats) && array_key_exists('uploaded-bytes', $this->_stats) && array_key_exists('seconds-active', $this->_stats)) { $extra_vals = array('title' => 'Transmission Stats', 'values' => array(array('Total Downloaded', Common::byteConvert($this->_stats['downloaded-bytes'])), array('Total Uploaded', Common::byteConvert($this->_stats['uploaded-bytes'])), $this->_stats['uploaded-bytes'] > 0 && $this->_stats['downloaded-bytes'] > 0 ? array('Total Ratio', round($this->_stats['uploaded-bytes'] / $this->_stats['downloaded-bytes'], 3)) : false, array('Duration', Common::secondsConvert($this->_stats['seconds-active'])))); } else { $extra_vals = false; } // Give it off return array('root_title' => 'Transmission Torrents', 'rows' => $rows, 'extra_type' => 'k->v', 'extra_vals' => $extra_vals); }
public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } // Use sysctl $booted = strtotime($this->sysctl['kern.boottime']); // Give it return array('text' => Common::secondsConvert(time() - $booted), 'bootedTimestamp' => $booted); }
private function _call() { // Time this $t = new Timer('apcaccess Extension'); // Deal with calling it try { $result = $this->_CallExt->exec('apcaccess'); } catch (Exception $e) { // messed up somehow Errors::add('apcaccess Extension', $e->getMessage()); $this->_res = false; // Don't bother going any further return false; } // Store them here $this->_res = array(); // Get name if (preg_match('/^UPSNAME\\s+:\\s+(.+)$/m', $result, $m)) { $this->_res['name'] = $m[1]; } // Get model if (preg_match('/^MODEL\\s+:\\s+(.+)$/m', $result, $m)) { $this->_res['model'] = $m[1]; } // Get battery voltage if (preg_match('/^BATTV\\s+:\\s+(\\d+\\.\\d+)/m', $result, $m)) { $this->_res['volts'] = $m[1]; } // Get charge percentage, and get it cool if (preg_match('/^BCHARGE\\s+:\\s+(\\d+(?:\\.\\d+)?)/m', $result, $m)) { $charge = (int) $m[1]; $this->_res['charge'] = ' <div class="bar_chart"> <div class="bar_inner" style="width: ' . (int) $charge . '%;"> <div class="bar_text"> ' . ($charge ? $charge . '%' : '?') . ' </div> </div> </div> '; } // Get time remaning if (preg_match('/^TIMELEFT\\s+:\\s+([\\d\\.]+)/m', $result, $m)) { $this->_res['time_left'] = Common::secondsConvert($m[1] * 60); } // Get status if (preg_match('/^STATUS\\s+:\\s+([A-Z]+)/m', $result, $m)) { $this->_res['status'] = $m[1] == 'ONBATT' ? 'On Battery' : ucfirst(strtolower($m[1])); } // Load percentage looking cool if (preg_match('/^LOADPCT\\s+:\\s+(\\d+\\.\\d+)/m', $result, $m)) { $load = (int) $m[1]; $this->_res['load'] = ' <div class="bar_chart"> <div class="bar_inner" style="width: ' . (int) $load . '%;"> <div class="bar_text"> ' . ($load ? $load . '%' : '?') . ' </div> </div> </div> '; } // Attempt getting wattage if (isset($load) && preg_match('/^NOMPOWER\\s+:\\s+(\\d+)/m', $result, $m)) { $watts = (int) $m['1']; $this->_res['watts_used'] = $load * round($watts / 100); } else { $this->_res['watts_used'] = false; } // Apparent success return true; }
public function getUpTime() { // Time? if (!empty($this->settings['timer'])) { $t = new Timer('Uptime'); } // Get contents $contents = Common::getContents('/proc/uptime', false); // eh? if ($contents === false) { $this->error->add('Linfo Core', '/proc/uptime does not exist.'); return 'Unknown'; } // Seconds list($seconds) = explode(' ', $contents, 1); // Get it textual, as in days/minutes/hours/etc $uptime = Common::secondsConvert(ceil($seconds)); // Now find out when the system was booted $contents = Common::getContents('/proc/stat', false); // Ugh if ($contents === false) { return $uptime; } // Settle for just uptime // Get date of boot if (preg_match('/^btime (\\d+)$/m', $contents, $boot) != 1) { return $uptime; } // Okay? list(, $boot) = $boot; return array('text' => $uptime, 'bootedTimestamp' => $boot); }
public function getUpTime() { $booted = $this->kstat['unix:0:system_misc:boot_time']; return array('text' => Common::secondsConvert(time() - $booted), 'bootedTimestamp' => $booted); }