From e9aa7ceb89c487f5d2c2bb102f67618ebfcae08b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 24 Apr 2017 16:05:13 +0200 Subject: [statistics_reporting] Extend remote report by hwstats, date ranges, userstats This implements #3108 --- .../statistics_reporting/inc/remotereport.inc.php | 62 ++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'modules-available/statistics_reporting/inc/remotereport.inc.php') diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 4c5f604b..68a3e95e 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -63,19 +63,63 @@ class RemoteReport * Generate the multi-dimensional array containing the anonymized * (weekly) statistics to report. * - * @param int $from start timestamp * @param int $to end timestamp + * @param int[] $days list of days to generate aggregated stats for * @return array wrapped up statistics, ready for reporting */ - public static function generateReport($from, $to) { - GetData::$from = $from; - GetData::$to = $to; + public static function generateReport($to, $days = false) { + if ($days === false) { + $days = [7, 30, 90]; + } GetData::$salt = bin2hex(Util::randomBytes(20, false)); - $data = GetData::total(GETDATA_ANONYMOUS); - $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); - $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); - $data['tsFrom'] = $from; - $data['tsTo'] = $to; + GetData::$lowerTimeBound = 7; + GetData::$upperTimeBound = 20; + $result = array(); + foreach ($days as $day) { + if (isset($result['days' . $day])) + continue; + $from = strtotime("-{$day} days", $to); + GetData::$from = $from; + GetData::$to = $to; + $data = array('total' => GetData::total(GETDATA_ANONYMOUS)); + $data['perLocation'] = GetData::perLocation(GETDATA_ANONYMOUS); + $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); + $data['tsFrom'] = $from; + $data['tsTo'] = $to; + $data['dozmod'] = Queries::getDozmodStats($from, $to); + $data['machines'] = Queries::getAggregatedMachineStats($from); + $result['days' . $day] = $data; + } + $result['server'] = self::getLocalHardware(); + $result['version'] = CONFIG_FOOTER; + return $result; + } + + private function getLocalHardware() + { + $cpuInfo = file_get_contents('/proc/cpuinfo'); + $uptime = file_get_contents('/proc/uptime'); + $memInfo = file_get_contents('/proc/meminfo'); + preg_match_all('/\b(\w+):\s+(\d+)\s/s', $memInfo, $out, PREG_SET_ORDER); + $mem = array(); + foreach ($out as $e) { + $mem[$e[1]] = $e[2]; + } + // + $data = array(); + $data['cpuCount'] = preg_match_all('/\bprocessor\s+:\s+(.*)$/m', $cpuInfo, $out); + if ($data['cpuCount'] > 0) { + $data['cpuModel'] = $out[1][0]; + } + if (preg_match('/^(\d+)\D/', $uptime, $out)) { + $data['uptime'] = $out[1]; + } + if (isset($mem['MemTotal']) && isset($mem['MemFree']) && isset($mem['SwapTotal'])) { + $data['memTotal'] = $mem['MemTotal']; + $data['memFree'] = ($mem['MemFree'] + $mem['Buffers'] + $mem['Cached']); + $data['swapTotal'] = $mem['SwapTotal']; + $data['swapUsed'] = ($mem['SwapTotal'] - $mem['SwapFree']); + } return $data; } -- cgit v1.2.3-55-g7522