[PHP] Server Status Multiple IP

freets3.ovh

Active Member
Sep 19, 2015
150
105
85
Hello, I decided to share my status script with you, here is a demo : http://admin.freets3.ovh/stats.php


PHP:
status.php

<?

require("config.php");
$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;
    }
}
?>

<table class="table table-bordered table-hover table-striped">
                                <thead>
                                    <tr>
                                        <th>Server</th>
                                        <th>Servers Online</th>
                                        <th>Clients Online</th>
                                        <th>Bandwidth</th>
                                        <th>IP</th>
                                    </tr>
                                </thead>
                                <tbody><?
                                    $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
                                    
                                        echo "<tr$class>";
                                            echo "<td>Query #$count</td>";
                                            echo "<td>".number_format($curservers)."</td>";
                                            echo "<td>".number_format($curclients)."</td>";
                                            echo "<td>".TeamSpeak3_Helper_Convert::bytes($curbytes)."</td>";
                                            echo "<td>$servip:$servport</td>";
                                        echo "</tr>";
                                    } ?>
                                    <tr>
                                        <td>
                                            <b>Totals</b>
                                        </td>
                                        <td><?
                                            echo number_format($servers)?>
                                        </td>
                                        <td><?
                                            echo number_format($clients)?>
                                        </td>
                                        <td><?
                                            echo TeamSpeak3_Helper_Convert::bytes($band)?>
                                        </td>
                                        <td>
                                            All
                                        </td>
                                    </tr>
                                </tbody>
                            </table>

PHP:
config.php

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

$serv_limit = 1000;

$querypw = "Query Password";

$roots = array(
    array("149.202.65.197",10011),
    array("149.202.65.197",10012),
    array("149.202.65.197",10013),
    array("149.202.65.197",10014),
    array("149.202.65.197",10016),
    array("149.202.65.197",10017),
    array("149.202.65.197",10018),
    array("149.202.65.197",10020),
    array("149.202.65.197",10022),
    array("149.202.65.197",10023),
    array("149.202.65.197",10024),
    array("149.202.65.197",10025),
    array("149.202.65.197",10026)
);
?>

I think you forgot to mention that you need bootstrap for that table :D
 
Last edited:

Najsr

Moderator
TeamSpeak Developer
Apr 23, 2016
483
249
167
I think you forgot to mention that you need bootstrap for that table :D
 

Derp

Retired Staff
Contributor
Apr 30, 2015
933
1,014
217
btw, I suggest you consider hosting part of your code on github :3
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
@Archie @MadKill That means that an error occurred either while connecting to the server or while getting this variable $con["virtualservers_running_total"];. Try to check your connection details.
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
or not have php on vps ... :p
I just saw that the stuff which gets triggered as soon as an error occurres is shown at the site so I guessed that this is the issue. But trying to run php without having php installed is really smart :D
 

iAndrewGG

Member
Mar 9, 2016
34
4
40
This ain't working. It's giving the same error as the guys above. Provide a tutorial or simple installation steps. Something is missing here, I got the permissions/credentials all right, no clue what's going on here. You didn't even provide fucking requirements.
 

Norvik

Retired Staff
Contributor
Jul 18, 2015
635
588
157
This ain't working. It's giving the same error as the guys above. Provide a tutorial or simple installation steps. Something is missing here, I got the permissions/credentials all right, no clue what's going on here. You didn't even provide fucking requirements.
Did you add "php" behind the "<?" Like the guy above you said? It seems like your servers aren't configured to allow "<?" instead of "<?php". But adding requirements would also be nice even tho it shouldn't require anything special.
 

iAndrewGG

Member
Mar 9, 2016
34
4
40
Did you add "php" behind the "<?" Like the guy above you said? It seems like your servers aren't configured to allow "<?" instead of "<?php". But adding requirements would also be nice even tho it shouldn't require anything special.
Yes I did, in fact that was the first thing I did in order to avoid any errors.
 

h3o66

Member
Apr 23, 2016
2
0
35
$curbytes = ($con["connection_bytes_received_total"] / 1024);
I dont think this is intended that it divides the recieved traffic through 1024.
Maybe you should exchange this with the following code in your status page. :)
PHP:
$curbytes = ($con["connection_bytes_received_total"] + $con["connection_bytes_sent_total"] );
 
Top