KPI (Key Performance Indicators) are quantifiable metrics that can be measured against organizational goals. KPIs vary from business to business, based on what the company does. If it's a sales oriented company, a KPI might be something like "increase sales by X% year over year"; if it's a retail company it might be both "increase sales" and "increase customer retention". The key is that a KPI must be measurable in some way. That's why most KPIs are directly related to revenue, customer retention/churn, and other quantifiable aspects of doing business.

Aggregating this measurable data is generally the responsibility of BI (Business Intelligence) suites. These products aggregate and assemble massive amounts of data, usually on a weekly or monthly basis, into a form that analysts can use to determine whether the company is on track to meeting its goals. These forms are often OLAP cubes and require lengthy processing to assemble, so they're usually only created on a weekly or nightly basis.

But what if you wanted something a bit more "real time"? Maybe you wanted to know on an hourly basis how sales was doing so you weren't surprised when you finally got the weekly or daily update.

If you've got a BIG-IP (v9.2+) and it's part of the infrastructure managing transactions, you're in luck. Using iRules and custom statistics profiles you can collect that data in real-time so you can satisfy your curiosity any time of the day or week.

What You Need

First you'll need a custom statistics profile so you have a place to store the data as it's collected. Joe's got a great article on how to create a custom statistics profile and walks through the steps required to assign it to the appropriate virtual server.

As an example, I created a custom statistics profile with two custom fields: total_value and orders. After saving it, I then assigned it to a virtual server. Use the Advanced settings to find the "Statistics Profile" drop-down associated with your virtual server, and choose your newly created custom profile.

The last step is to create an iRule that extracts the data you're interested in and stores it in your custom statistics profile. You might also add a few additional processing-oriented rules within the iRule to handle resetting the statistics as well as displaying the statistics.

Basically, we're creating a KPIService with a REST style interface. By default, the rule will extract the appropriate data and update the statistics profile, but by directly invoking a specific URI, e.g. /statistics/display, /statistics/reset, you can create a service that provides some amount of control over your custom profile.

The iRule

The following iRule is not optimized and it's rather simplistic in its nature, but it does present the basic concept of extracting specific data from transactions and storing them in a custom profile for retrieval whenever you desire. If you were really ambitious, you could output the statistics in XML or CSV and import them right into something like Microsoft Excel so you could view the data over time.


set t [STATS::get $PROFILE_NAME "total_value"]
set o [STATS::get $PROFILE_NAME "orders"] 
set uri [HTTP::uri]
set FIELD_NAME "totalvalue" 
if {$uri starts_with "/statistics/display"} {
   HTTP::respond 200 content ""
else if {$uri starts_with "/statistics/reset"} {
    STATS::set $PROFILE_NAME "total_value" 0
    STATS::set $PROFILE_NAME "orders" 0
    HTTP::respond 200 content "Statistics have been reset"
} else {
   set postvalues [split [HTTP::payload] "&"]
   foreach p $postvalues {
      set pval [split $p "="] 
      if {[lindex $pval 0] eq $FIELD_NAME} {      
         set newtotal [expr [lindex $pval 1] + $t]
   STATS::set $PROFILE_NAME "total_value" $newtotal
   // This piece of the profile counts the number of orders we've received 
   set neworders [expr $o + 1]
   STATS::set $PROFILE_NAME "orders" $neworders



KPIs aren't the only thing you could capture with custom profiles - you could measure a lot of customer-oriented actions as well, such as the number of users who loaded the "checkout" page and how many loaded the "final_checkout" page, as a real time view of abandonment rates. While iRules aren't meant to - and won't - take the place of business intelligence suites, they can provide some interesting real-time visibility into your business without requiring modification to existing applications or the purchase of additional software.

Imbibing: Coffee

Published Jul 13, 2007
Version 1.0

Was this article helpful?

No CommentsBe the first to comment