Showing results for 
Search instead for 
Did you mean: 

HowTo: Using the RESTful Control API to get pool statistics with PHP

The following code uses Stingray's RESTful API to retrieve the statistics for a pool. The code is written in PHP and uses STMRESTClient.  This program does a single GET request for the statistics for the pool and then loops through response printing out each property and its value.




# Display the statistics for a pool  
require_once '';  
$pool = "testpool";  
print("<html><body>\n<br><b>Statistics for Pool $pool</b><br><br>\n");  
try {  
    $client = new STMRestClient();  
    $response = $client->get("pools/$pool", TYPE_STATS);  
    $stats = $response->statistics;  
    foreach ($stats as $field => $value) {  
} catch (STMConnectException $e) {  
    print ("Error connecting to the REST API: " . $e->getMessage());  
} catch (STMAuthException $e) {  
    print ("Error logging into the REST API: " . $e->getMessage());  
} catch (exception $e) {  
    print ('Error: ' . $e->getMessage());  


Running the example


This code was tested with PHP 5.3.3 and uses the STMRestClient class that can be found here: Tech Tip: A Stingray Traffic Manager REST Client for PHP


To run this program, Make it available via a web server and the output should be:


Statistics for Pool testpool


algorithm:        roundrobin

bytes_in:         16114052

bytes_out:        276005

conns_queued:     0

disabled:         1

draining:         1

max_queue_time:   0

mean_queue_time:  0

min_queue_time:   0

nodes:            2

persistence:      none

queue_timeouts:   0

session_migrated: 0

state:            active

total_conn:       4076


Read More


Version history
Revision #:
1 of 1
Last update:
‎02-06-2014 09:59:PM
Updated by:
Labels (1)