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.
getpoolstats.php
<?php # Display the statistics for a pool require_once 'stmrestclient.inc'; $pool = "testpool"; print("<html><body>\n<br><b>Statistics for Pool $pool</b><br><br>\n"); print("<table>\n"); try { $client = new STMRestClient(); $response = $client->get("pools/$pool", TYPE_STATS); $stats = $response->statistics; foreach ($stats as $field => $value) { print("<tr><td>$field:</td><td>$value</td></tr>\n"); } print("</table>\n"); } 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()); } print("</body></html>\n"); ?>
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