Skip to content

Commit 03559a8

Browse files
committedDec 1, 2015
added graph.php
1 parent 2e42f4d commit 03559a8

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
config.inc.php
22
~
33
alert.lock
4+
error.log

‎functions.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PHPMonitoring {
77

88
const ALERT_FILE = 'alert.lock';
99
const CONFIG_FILE = 'config.inc.php';
10-
const ERROR_LOG = '/var/log/php-monitoring.log';
10+
const ERROR_LOG = 'error.log';
1111
var $config;
1212

1313
/**
@@ -171,4 +171,20 @@ function getAlertFilePath(){
171171
function getServices(){
172172
return $this->config['services'];
173173
}
174+
175+
/**
176+
* Get log data
177+
* TODO set max lines to avoid memory limits
178+
*/
179+
function getLogData(){
180+
$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);
187+
}
188+
return array_values($data);
189+
}
174190
}

‎graph.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* PHP Monitoring graph page : show services graphics
4+
*/
5+
6+
require_once('functions.php');
7+
$p = new PHPMonitoring();
8+
?>
9+
<!DOCTYPE html>
10+
<html style="height: 100%;">
11+
<head>
12+
<title>PHP monitoring graph</title>
13+
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
14+
<script src="http://code.highcharts.com/highcharts.js"></script>
15+
<script src="https://code.highcharts.com/modules/exporting.js"></script>
16+
</head>
17+
<body style="height: 100%;">
18+
<div id="container" style="width: 100%; height: 100%;"></div>
19+
<script>
20+
$(document).ready(function(){
21+
$('#container').highcharts({
22+
chart: {
23+
type: 'column',
24+
zoomType: 'x'
25+
},
26+
title: {
27+
text: 'PHP monitoring graph'
28+
},
29+
xAxis: {
30+
type: 'datetime'
31+
},
32+
yAxis: {
33+
title: {
34+
text: 'down'
35+
},
36+
min: 0,
37+
max: 1
38+
},
39+
legend: {
40+
layout: 'vertical',
41+
align: 'right',
42+
verticalAlign: 'middle',
43+
borderWidth: 0
44+
},
45+
series: <?= json_encode($tmp = $p->getLogData()) ?>
46+
});
47+
});
48+
</script>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.