Live data | Highcharts | Ts3 Users

freets3.ovh

Active Member
Sep 19, 2015
150
105
85
Demo : http://kingts3.com/kevin/1.php

1.php
PHP:
<!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: 800px; height: 400px; margin: 0 auto"></div>
       
       <div style="width: 800px; margin: 0 auto">

           
       </div>
   </body>
</html>
 

freets3.ovh

Active Member
Sep 19, 2015
150
105
85
live-server-data.php

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;
    }
}
?>

<?
                                    $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);
?>
 

Cparty

New Member
Nov 30, 2016
12
1
15
dzpmya
http://prntscr.com/dzpmya
 

anibalabel

Member
Feb 10, 2016
9
0
36
Very good, it works perfectly, in my file, error log, I get this
PHP Warning: Cannot modify header information - headers already sent by (output started at /home/gamerfa1/public_html/live-server-data.php:26) in /home/gamerfa1/public_html/live-server-data.php on line 58
 
Last edited:

Pain

Member
Feb 20, 2016
102
17
53
bueno ,
me sal este erro
PHP Warning: Cannot modify header information - headers already sent by (output started at /home/gamerfa1/public_html/live-server-data.php:26) in /home/gamerfa1/public_html/live-server-data.php on line 58

pero todo lo demas muy bien
English language only please !
 

ptR

Member
Nov 15, 2015
47
0
38
Its oke but doesnt show clients and the graph
 
Last edited:

Ch4ch4rR4t0

Active Member
Aug 19, 2016
77
7
83
Much thanks bro, working :D <3

For fix only change <? to <?php and add this in live-server-data.php

$serv_limit = 0;
$servers = 0;
$clients = 0;
$band = 0;
 

Corne

Member
Jan 12, 2016
39
4
40
Much thanks bro, working :D <3

For fix only change <? to <?php and add this in live-server-data.php

$serv_limit = 0;
$servers = 0;
$clients = 0;
$band = 0;


Where exactly should i aff the 4 lines?
Also im getting the below errors
Can you provide any assistance?


#apache2/logs/error_log

PHP Notice: Undefined variable: serv_limit in ///////htdocs/stats/live-server-data.php on line 17
PHP Notice: Undefined variable: curservers in ///////htdocs/stats/live-server-data.php on line 17
PHP Fatal error: Uncaught exception 'TeamSpeak3_Transport_Exception' with message 'php_network_getaddresses: getaddrinfo failed: Name or service not known' in //////htdocs/stats/libraries/TeamSpeak3/Transport/TCP.php:54\nStack trace:\n#0 ///////htdocs/stats/libraries/TeamSpeak3/Transport/TCP.php(108): TeamSpeak3_Transport_TCP->connect()\n#1 ///////htdocs/stats/libraries/TeamSpeak3/Adapter/ServerQuery.php(76): TeamSpeak3_Transport_TCP->readLine()\n#2 ///////htdocs/stats/libraries/TeamSpeak3/Adapter/Abstract.php(60): TeamSpeak3_Adapter_ServerQuery->syn()\n#3 //////htdocs/stats/libraries/TeamSpeak3/TeamSpeak3.php(320): TeamSpeak3_Adapter_Abstract->__construct(Array)\n#4 ////////htdocs/stats/live-server-data.php(32): TeamSpeak3::factory('serverquery://s...')\n#5 {main}\n thrown in //////htdocs/stats/libraries/TeamSpeak3/Transport/TCP.php on line 54
 

MCGFX

Member
Dec 5, 2015
15
0
33
Hi, Very nice script but you could do that also in the "Highstock" variant

If it would be very nice if you could post it :)

MFG
MCGFX
 
Top