index.php
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Stats Kingts3.com & Freets3.ovh</title>
<!-- 1. Add these JavaScript inclusions in the head of your page -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
<!-- 2. Add the JavaScript to initialize the chart on document ready -->
<script>
var chart; // global
function requestData() {
$.ajax({
url: 'live-server-data.php',
success: function(point) {
var series = chart.series[0],
shift = series.data.length > 20; // shift if the series is longer than 20
// add the point
chart.series[0].addPoint(eval(point), true, shift);
// call it again after one second
setTimeout(requestData, 1000);
},
cache: false
});
}
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'spline',
events: {
load: requestData
}
},
title: {
text: 'Clients Online Now, Freets3.ovh & Kingts3.com'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 150,
maxZoom: 20 * 1000
},
yAxis: {
minPadding: 0.2,
maxPadding: 0.2,
title: {
text: 'Value',
margin: 80
}
},
series: [{
name: 'Clients online',
data: []
}]
});
});
</script>
</head>
<body>
<!-- 3. Add the container -->
<div id="container" style="width: 1024px; height: 400px; margin: 0 auto"></div>
<div style="width: 1024px; margin: 0 auto">
</div>
</body>
</html>
Code:
<?php
require("config.php"); // DB stuff and variables
$count = 0;
foreach(array_reverse($roots) as $serv){
$servip = $roots[$count][0];
$servport = $roots[$count][1];
try{
$con = TeamSpeak3::factory("serverquery://serveradmin:{$querypw}@{$servip}:{$servport}/");
$curservers = $con["virtualservers_running_total"];
}catch(Exception $e){
echo "Error (ID ".$e->getCode().") <b>".$e->getMessage()."</b> on IP: $servip:$servport<br/>";
}
$count++;
if($curservers < $serv_limit){
$curport = $servport;
$curip = $servip;
$servno = $count;
break;
}
}
?>
<?php
$count = 0;
foreach($roots as $serv){
$servip = $roots[$count][0];
$servport = $roots[$count][1];
//Create connection
$con = TeamSpeak3::factory("serverquery://serveradmin:{$querypw}@{$servip}:{$servport}/");
// Get info
$curservers = $con["virtualservers_running_total"];
$curclients = $con["virtualservers_total_clients_online"];
$curbytes = ($con["connection_bytes_received_total"] / 1024);
if($curservers < 1000){
$class = " class=\"success\"";
}else{
$class = " class=\"danger\"";
}
// Calculate totals
$servers = ($con["virtualservers_running_total"] + $servers);
$clients = ($con["virtualservers_total_clients_online"] + $clients);
$band = ($con["connection_bytes_received_total"] + $con["connection_bytes_sent_total"] + $band);
$count++; // Increment counter
} ?>
<?php
// Set the JSON header
header("Content-type: text/json");
// The x value is the current JavaScript time, which is the Unix time multiplied by 1000.
$x = time() * 1000;
// The y value is a random number
$y = $clients;
// Create a PHP array and echo it as JSON
$ret = array($x, $y);
echo json_encode($ret);
?>
Code:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");
$querypw = "PASSWORD";
$roots = array(
array("IP",QUERYPORT)
);
?>