-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathviewService.php
More file actions
75 lines (66 loc) · 2.23 KB
/
viewService.php
File metadata and controls
75 lines (66 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
include("header.php");
include("sqlConnection.php");
$pageId = $_GET["id"];
$rowLimit = 60;
if($_GET["show"] != "") {
$rowLimit = $_GET["show"];
}
$q = mysqli_query($connection, "select * from stats WHERE id='$pageId'");
$serviceName = mysqli_fetch_array($q)[nickname];
$showConnection = mysqli_fetch_array($q)[show_connection];
$serviceConnection = mysqli_fetch_array($q)[hostname];
$q = mysqli_query($connection, "select * from chart_stats WHERE service_id='$pageId' ORDER BY id DESC limit $rowLimit");
$sBuild = "[";
$tBuild = "[";
$pingResponses = [];
if(mysqli_num_rows($q) < 60) $rowLimit = mysqli_num_rows($q);
while($row = mysqli_fetch_array($q)) {
$sBuild .= "\"$row[timestamp]\", ";
$tBuild .= "$row[ping_response], ";
array_push($pingResponses, $row[ping_response]);
}
$sBuild .= "]";
$tBuild .= "]";
$a = 0;
foreach($pingResponses as $i) {
$a += $i;
}
$a = $a / $rowLimit; // Average
?>
<div class="container">
<h1 class="display-1" style="text-align:center">
<?php echo $serviceName; ?>
<?php if($showConnection == "true") echo "hi" . $serviceConnection; ?></h1>
<h3 style="text-align:center">Ping within the last hour (avg. <?php echo round($a); ?>ms)</h3>
<?php
if(is_nan($a)) { echo "<div class='jumbotron' style='text-align:center'><h1 class='display-3'>No chart data available yet.</h1></div>"; return; }
?>
<canvas id="pingChart" width="100%" >
<script>
var ctx = document.getElementById("pingChart");
var myChart = new Chart(ctx, {
type: 'bar',
data: {
//labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
<?php echo "labels: $sBuild,"; ?>
datasets: [{
label: 'Ping',
//data: [12, 19, 3, 5, 2, 3],
<?php echo "data: $tBuild,"; ?>
borderWidth: 2
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
</script>
</canvas>
</div>