-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph-ajax.php
More file actions
34 lines (24 loc) · 965 Bytes
/
graph-ajax.php
File metadata and controls
34 lines (24 loc) · 965 Bytes
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
<?php if ( !defined( 'STUZZPANEL' ) ) exit;
ob_start( 'ob_gzhandler' );
global $db;
$res = $db->query( 'SELECT `timestamp`, `data` FROM `mc_server_stats` WHERE `username` = \'' . $db->escape_string( USERNAME ) . '\' ORDER BY `timestamp` DESC;' );
$graphs = array();
$i = 0;
while ( $row = $res->fetch_assoc() ) {
if ( $i++ != 0 ) {
if ( $i == 4 ) {
$i = 0;
}
continue;
}
$timestamp = strtotime( $row['timestamp'] );
$data = unserialize( $row['data'] );
$graphs['players' ]['Player limit' ][$timestamp] = $data['max_players'];
$graphs['players' ]['Online players' ][$timestamp] = count( $data['online_players'] );
$graphs['cpumem' ]['CPU' ][$timestamp] = $data['cpu'];
$graphs['cpumem' ]['Memory' ][$timestamp] = $data['mem'] / $data['max_mem'] * 100;
$graphs['tickrate']['Ticks per second'][$timestamp] = $data['tick'];
}
$res->close();
header( 'Content-Type: application/json' );
echo json_encode( $graphs );