-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_data.php
More file actions
101 lines (95 loc) · 2.11 KB
/
show_data.php
File metadata and controls
101 lines (95 loc) · 2.11 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
ini_set('memory_limit', '2048M');
ini_set('max_execution_time', 600);
include_once("db_connect.php");
$db=new db();
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<canvas id="both-hourly" width="600" height="300"></canvas>
<canvas id="canvas"></canvas>
<?php
// calc intermediate line
$sum=$db->fetch("select sum(cpu) as sum from data where id=$_GET[id]");
$amount=$db->fetch("select count(cpu) as count from data where id=$_GET[id]");
$average=round($sum->sum/$amount->count);
// get data from DB
$set=$db->fetch("select * from datasets where id=$_GET[id]");
$data=$db->fetch("select * from data where id=$set->id");
$labels="";
$vals="";
$vals2="";
$vals3="";
$x=0;
foreach ($data as $res)
{
//$labels="$set->date,".$labels;
$labels=",".$labels;
$val=$res->cpu;
$vals="\"$val\",".$vals;
$val2=$res->ram;
$vals2="\"$val2\",".$vals2;
$vals3="\"$average\",".$vals3;
}
?>
<script>
new Chart(document.getElementById("both-hourly"),
{
type: 'line',
data:
{
labels: [<?php echo $labels; ?>],
datasets:
[
{
data: [<?php echo $vals2; ?>],
label: "RAM usage in GB",
borderColor: "orange",
fill: false
},
{
data: [<?php echo $vals3; ?>],
label: "Average CPU usage is <?php echo $average; ?>%",
borderColor: "green",
fill: false
},
{
data: [<?php echo $vals; ?>],
label: "CPU Total in % (Cores: <?php echo $set->cores; ?>)",
borderColor: "#3e95cd",
fill: false
}
]
},
options:
{
title:
{
display: true,
text: 'Performance Data of User <?php echo "$set->user on day $set->date"; ?>'
},
responsive: true,
elements:
{
point:
{
radius: 0
}
},
scales:
{
yAxes:
[
{
display: true,
ticks:
{
suggestedMin: 4,
suggestedMax: 13,
//beginAtZero: true // minimum value will be 0.
}
}
]
}
},
});
</script>