• Hey Guest, we're evolving the future of TeaSpeak.
    You're invited to join the discussion here!

Release Web: Server Stats highcharts live

Kevinos

Fanatic member
Premium User
Capture.PNG
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>
live-server-data.php

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);
?>
config.php

Code:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

$querypw = "PASSWORD";

$roots = array(
    array("IP",QUERYPORT)
);
?>
This script works in direct, it does not take the given already passed. But you can modify it to save the data, in a database
 

BIOS

TeaSpeak Team
Staff member
TeaTeam
I also have a blank page
I had the same problem and solved it like this:

Original from Index.php

Code:
       <!-- 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>
changed

Code:
<script
              src="https://code.jquery.com/jquery-3.3.1.js"
              integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
              crossorigin="anonymous"></script>
       <script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script>
and works great for me
 

Alexandru Andrei

Well-known member
I've been there for 10 minutes and it's all right
Files are put on a webhosting
Uptime:105 day(s) 19 hour(s) 40 minute(s) 59 second(s)
Current Clients:15 / 32
Current Channels:58
 

Attachments

mkll11one

TeaSpeak Team
Staff member
TeaTeam
Possible to set the double virtual server on config.php??

When I trying I getting an error:

PHP Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' in /var/www/html/stats/config.php on line 8
Code:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

$querypw = "*********";

$roots = array(
    array("IPhere1",10011)
    array("IPhere2",10101)
);
?>
Do you know? @Kevinos
 

BIOS

TeaSpeak Team
Staff member
TeaTeam
Possible to set the double virtual server on config.php??

When I trying I getting an error:

PHP Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' in /var/www/html/stats/config.php on line 8
Code:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

$querypw = "*********";

$roots = array(
    array("IPhere1",10011)
    array("IPhere2",10101)
);
?>
Do you know? @Kevinos
you use same password on both servers?
 

xDyego

Well-known member
Is it possible to do this verification with several servers with different passwords, of course?
 

Kevinos

Fanatic member
Premium User
Possible to set the double virtual server on config.php??

When I trying I getting an error:

PHP Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting ')' in /var/www/html/stats/config.php on line 8
Code:
<?php
require_once("libraries/TeamSpeak3/TeamSpeak3.php");

$querypw = "*********";

$roots = array(
    array("IPhere1",10011),
    array("IPhere2",10101)
);
?>
Do you know? @Kevinos
you need add (,) after the first IP

array("IPhere1",10011),
array("IPhere2",10101)

---- Automatically Merged Double Post ----

Is it possible to do this verification with several servers with different passwords, of course?
yes

after
$servip = $roots[$count][0];
$servport = $roots[$count][1];

add this :

$querypw = $roots[$count][2];

and on config change this too :
$roots = array(
array("IP",QUERYPORT)

to

$roots = array(
array("IP",QUERYPORT,QUERYPW)
 
Last edited:

mkll11one

TeaSpeak Team
Staff member
TeaTeam
you need add (,) after the first IP

array("IPhere1",10011),
array("IPhere2",10101)
@Kevinos
Nothing happens =/
because of this:

Code:
PHP Fatal error:  Uncaught TeamSpeak3_Adapter_Exception: invalid reply from the server Tea(m)Speak
Only happen on 10101

Edit: Updated. (Fixed.. MOTD wrong. xD I will wish, it was possible to reload-config so "MOTD" will be updated (without to restart)
 
Last edited:

mkll11one

TeaSpeak Team
Staff member
TeaTeam