Topics


Blogs


Forums


Samples


Media


Labs


Resources

Login | Register




Subscriptions: Video  |  Audio  |  Tutorials  |  Tech Tips  |  Features  |  More...
Docs & Tips

Current Articles | Categories | Search | Syndication

PHP and iControl: HTTP Statistics and Version Info

posted @ Monday, December 15, 2008 4:28 AM by macvittie - 1874 views


Last year we kicked off some PHP and iControl with a “Getting Started” article that’s been enhanced and added to by a couple of users (thanks rpaan and orangepeelbeef).

I recently decided to integrate my BIG-IP with Twitter so that it could accept commands via tweets as well as send updates. In the course of doing that, it was necessary to write a couple of PHP functions to return statistics and information from BIG-IP.

One of the most frustrating parts of the solution was simply dealing with 64-bit integers. The System.Statistics objects in iControl used to return statistics information from BIG-IP return a 64-bit integer split into its high and low values. That means you need to recreate the 64-bit integer. PHP isn't necessarily very friendly to 64-bit integers natively, but after a bit of searching, the answer was found on the Internet and is included in the code along with kudos to the developer who offered the solution (which works great, by the way).

If you haven’t previously set up your environment to handle iControl via PHP, you’ll want to check out the Getting Started article. Please be sure to read through rpaan’s recreated solution, as he’s offered up a solution that doesn’t require PEAR.

This solution still assumes the use of PEAR, but should be easily ported to rpaan’s solution.

This solution implements two functions. The first can be used to retrieve a specific HTTP statistic from BIG-IP via the get_http_statistics call. The complete list of enumerated statistics types can be found here (#170-#214, statistics beginning with STATISTIC_HTTP) as this solution uses only a subset of the statistics available via the get_http_statistics operation.  

The second function returns version information as returned by the get_version operation.

The code is included below.

<?

require_once 'SOAP/Client.php';

 

// Thanks to "thegeek" for a solution to dealing with 64-bit integers in PHP

// http://www.gerd-riesselmann.net/archives/2006/01/a-64-bit-integer-for-php

 

define("BIGINT_DIVIDER", 0x7fffffff + 1);

 

// This function takes one parameter: $reqstat that indicates which statistic is being

// requested. Possible values are:

//

// ALL       Return number of total requests handled

// 200       Return number of 2xx responses returned

// 400       Return number of 4xx responses returned

// 500       Return number of 5xx responses returned

// GET       Return number of GET requests handled

// POST      Return number of POST requests handled

//

// This function returns a string containing the label and the value of the statistic requested

// in the following format:   label:value

 

function getstats($reqstat) {

  $soapoptions = array('namespace' => 'urn:iControl');

  $wsdl_url = 'http://<BIG-IP hostname>/bigip/wsdl/System.Statistics.wsdl';

 

  $proxy_parms = array( 'user' => '<username here>', 'pass' => '<password here>');

 

  $params = array();

  $client = new SOAP_Client($wsdl_url, true, '', $proxy_parms ); 

  $client->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);

  $client->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);

 

  // call to get_http_statistics takes no parms, returns a System.Statistics structure

  $response    = $client->call('get_http_statistics', $params, $soapoptions);

 

  if (PEAR::isError($response)) {       

          print "an error occurred in the call " . $response;

  }

  else {

         $finalresponse = "";

          foreach ($response as $stat) {  

              foreach ($stat as $stats) {  

                 $label = "";

                 if ($stats->type == 'STATISTIC_HTTP_TOTAL_REQUESTS' && $reqstat == "ALL") {

                      $label = "TOTAL REQUESTS";

                  }   

                  else

                  if ($stats->type == 'STATISTIC_HTTP_2XX_RESPONSES' && $reqstat == "200") {

                     $label = "HTTP 2xx RESPONSES";

                  }

                  else

                  if ($stats->type == 'STATISTIC_HTTP_4XX_RESPONSES' && $reqstat == "400") {

                     $label = "HTTP 4xx RESPONSES";

                  }

                  else

                  if ($stats->type == 'STATISTIC_HTTP_5XX_RESPONSES' && $reqstat == "500") {

                     $label = "HTTP 5xx RESPONSES";

                  }

                  else

                  if ($stats->type == 'STATISTIC_HTTP_GET_REQUESTS' && $reqstat == "GET") {

                     $label = "GET REQUESTS";

                  }

                  else

                  if ($stats->type == 'STATISTIC_HTTP_POST_REQUESTS' && $reqstat == "POST") {

                     $label = "POST REQUESTS";

                  }

                

                  // if the label has been set recreate the value by recombining the high and low

                  // bit values into a 64-bit integer value

                  if ($label != "" ) {

                    $realvalue1 = $stats->value->high * BIGINT_DIVIDER + $stats->value->low;

                    $finalresponse .= "$label:$realvalue1   ";

                  }

              }

          }

       return $finalresponse;

  }

 

}

 

?>

 

<? 
require_once 'SOAP/Client.php';
 
// This function takes no parameters. It makes a call to get_version and returns the information
// in a string formatted as follows: Version:value 
 
function getversion() {
 
  $soapoptions = array('namespace' => 'urn:iControl'); 
  $wsdl_url = 'http://<BIG-IP host name>/bigip/wsdl/System.SystemInfo.wsdl'; 
 
  $proxy_parms = array( 'user' => '<username here>', 'pass' => '<password here>');
 
  $params = array(); 
  $client = new SOAP_Client($wsdl_url, true, '', $proxy_parms );  
  $client->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); 
  $client->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); 
 
  $response    = $client->call('get_version', $params, $soapoptions);
  
  if (PEAR::isError($response)) {        
          print "an error occurred in the call " . $response;
  }
  else {
         $finalresponse = "Version: $response";
          return $finalresponse;
  }
 
}
 
?> 

 

Email This   Bookmark and Share

Previous Page | Next Page

COMMENTS

Only registered users may post comments.

Essentials

Features

 Videos

 Audio
v10.1 - Configuring GTM's DNS Security Extensions
v.10 - Remote Authorization via TACACS+
v.10 - New class features in iRules
v.10 - iRules and the after command
v.10 - FastHTTP and Cookie Persistence
v.10 - A new iRules Namespace
Unbind your LDAP servers with iRules
Ten Steps to iRules Optimization
Ruby Meets iControl: Switching Policies
Ruby meets iControl: Making Wide IPs
Ruby meets iControl: Creating VIPs
Replacing the WebSphere Apache Plugin with iRules
Persisting SSL Connections
Managing The System Boot Location with iControl
iRules Event Order
iRules 101 - #15 - TCL List Handling Commands
iRules 101 - #14 - TCL String Commands Part 2
Investigating the LTM TCP Profile: Windows & Buffers
Investigating the LTM TCP Profile: The Finish Line
Investigating the LTM TCP Profile: Nagle’s Algorithm
Investigating the LTM TCP Profile: ECN & LTR
Investigating the LTM TCP Profile: Congestion Control Algorithms
Investigating the LTM TCP Profile: Acknowledgements
iControl Apps - #18 - Virtual Server Reverse Lookup
iControl Apps - #14 - Global Statistics
iControl Apps - #13 - System PVA Statistics
iControl Apps - #12 - Global SSL Statistics
iControl Apps - #11 - Global GTM Statistics
iControl Apps - #10 - Bigpipe List
iControl Apps - #09 - TMM Statistics
iControl Apps - #08 - System IP Statistics
iControl Apps - #07 - System Http Statistics
iControl Apps - #06 - Configuration Archiving
iControl Apps - #05 - Rate Based Statistics
iControl Apps - #04 - Graceful Server Shutdown
iControl Apps - #03 - Local Traffic Map
iControl 101 - #22 - GTM Data Centers
iControl 101 - #21 - Rate Classes
iControl 101 - #20 - Port Lockdown
iControl 101 - #19 - Time Conversions
Getting Started with pyControl
FTPS Offload via iRules
Exchange Persistence Duality and iRules
Custom SNMP Traps
Creating An iControl PowerShell Monitoring Dashboard With Google Charts
Cookie LoJack vi iRules
Concurrent iControl Programming Explained
Can iRules fix my cert mismatch errors?
Cache in with LTM and iRules
Investigating the LTM TCP Profile: Max Syn Retransmissions & Idle Timeout


Quick Start Guides

Tutorials

iControl

iRules

Monitoring & Management

Advanced Design & Config

DC4
ASM       Best Practices       BIG-IP       cacti       cookie       DNS       FirePass       http redirect       https       iControl       iRule Editor       iRules       LB_FAILED       log       matchclass       monitor       persist       persistence       pool       PowerShell       proxy       radius       redirect       SIP       SNAT       SNMP       SSL       stream       switch       syslog       wiki       X-Forwarded-For