Skip to content

Commit 3219cce

Browse files
committed
graph : sort+hide series, parse only MAX_LOG_DATA last lines
1 parent 03559a8 commit 3219cce

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

functions.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class PHPMonitoring {
88
const ALERT_FILE = 'alert.lock';
99
const CONFIG_FILE = 'config.inc.php';
1010
const ERROR_LOG = 'error.log';
11+
const MAX_LOG_DATA = 10000;
1112
var $config;
1213

1314
/**
@@ -174,17 +175,18 @@ function getServices(){
174175

175176
/**
176177
* Get log data
177-
* TODO set max lines to avoid memory limits
178178
*/
179179
function getLogData(){
180180
$data = array();
181-
if (($handle = fopen(self::ERROR_LOG, 'r')) !== FALSE) {
182-
while ((list($date, $time, $junk, $junk, $service) = fgetcsv($handle, 128, ' ')) !== FALSE) {
183-
if (!isset($data[$service])) $data[$service] = array('name' => $service);
184-
$data[$service]['data'][] = array(strtotime(ltrim($date, '[') . ' ' . $time)*1000, 1);
185-
}
186-
fclose($handle);
181+
$file = new SplFileObject(self::ERROR_LOG);
182+
$file->seek(PHP_INT_MAX);
183+
$file->seek($file->key() - self::MAX_LOG_DATA);
184+
while (!$file->eof()) {
185+
list($date, $time, $junk, $junk, $service) = $file->fgetcsv(' ');
186+
if (!isset($data[$service])) $data[$service] = array('name' => $service, 'visible' => false);
187+
$data[$service]['data'][] = array(strtotime(ltrim($date, '[') . ' ' . substr($time,0,5))*1000, 1);
187188
}
189+
ksort($data);
188190
return array_values($data);
189191
}
190192
}

graph.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
text: 'PHP monitoring graph'
2828
},
2929
xAxis: {
30-
type: 'datetime'
30+
type: 'datetime',
31+
startOnTick: true,
32+
endOnTick: true,
33+
minTickInterval: 60000
3134
},
3235
yAxis: {
3336
title: {
@@ -36,6 +39,14 @@
3639
min: 0,
3740
max: 1
3841
},
42+
plotOptions: {
43+
series: {
44+
pointPadding: 0,
45+
groupPadding: 0,
46+
borderWidth: 0,
47+
shadow: false
48+
}
49+
},
3950
legend: {
4051
layout: 'vertical',
4152
align: 'right',

0 commit comments

Comments
 (0)