Heatmaps, iRules Style: Part 4, Meaningful numbers

All right, so far I’ve built a heatmap of the US, expanded it to show the entire world with zoom capability, and allowed you to sort the views of those different dynamically generated maps by URLs of your own choosing.  So far so good, but a very important piece of this puzzle is still missing.  So you show off the fancy new heatmaps your LTM can generate and people are oohing and ahhing, but then someone asks, “So what does this dark green mean? How many requests have we actually seen to url123 from California?”. At which point you say, “uhhhhhh….” and suddenly look far less impressive.  Well we can’t have that, can we?

In this fourth installment of my Heatmaps, iRules Style series I’ll show you how to add a little bit of extra HTML and counter logic to the already nifty heatmap code so that you can display the actual data being collected in an easy to consume format so that you can back up the pretty pictures with hard numbers to make everyone happy.

First, we’re using the exact code from Part 3 of the series (found here) as our starting point.  All we’re really trying to do is get a list of all states or countries and the total number of connections we’ve received for that region.  Keep in mind, though, that we’re not storing the connection count on a per state or per country basis. We’re using the URL for sorting as the key in the tables, so we need to throw together a sum of the requests to each URL for a given region (state or country).  To do that we’ll just add in some logic that gets the numberic value of requests for each URL at the time when we’re appending things to the chld and chd for the API call, then total those for each subtable, since we have one subtable per region anyway (what, you thought that was arbitrary?) That looks like this:

<span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">append</span> chld <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2]"</span>
<span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 0, 255);">append</span> chd <span style="color: rgb(0, 96, 128);">"[table lookup -subtable $mysub $myurl],"</span>
<span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> <span style="color: rgb(0, 0, 255);">set</span> urlTotal [<span style="color: rgb(0, 0, 255);">table</span> lookup -subtable $mysub $myurl]
<span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> }
<span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> <span style="color: rgb(0, 0, 255);">set</span> regionTotal [<span style="color: rgb(0, 0, 255);">expr</span> $regionTotal + $urlTotal]
<span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span> <span style="color: rgb(0, 0, 255);">set</span> urlTotal 0

That will give us the number of connections for each region, now let’s pair that with the region name.  We already have the logic we need to grab the name of the region from the append chld line, so all we need to do is pair it with the new regionTotal we’ve just created:

<span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">append</span> regions <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2] : $regionTotal<br>"</span>
<span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 0, 255);">set</span> regionTotal 0

So now if we’ve done things right we should have an entry that looks like “WA : 589” if the region in question is Washington State, for example. If we add this logic in the right places in the loops that build the API call we’ll have a nice list of the data we’re looking for.  Now all we need to do is tweak the HTML a bit to add some structure to the whole thing and allow us to display this neat new info. To do so, the RULE_INIT section changes to:

<span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp1 <span style="color: rgb(0, 96, 128);">"<HTML><table width='100%' border='0'><tr><td></td><td><center><font size=5>Here is your site's \</span>
<span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> usage:</font></td></tr><tr><td align='center' rowspan='5'><b><u>Connections per Region:</u></b><br><br>"
<span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp2  <span style="color: rgb(0, 96, 128);">"</td><td><center><img src='http://chart.apis.google.com/chart?cht=t&chd=&chs=440x220&chtm="</span>
<span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp3 <span style="color: rgb(0, 96, 128);">"&chco=f5f5f5,edf0d4,6c9642,365e24,13390a' border='0'></center></td></tr><td><center><br><br>\</span>
<span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> Zoom to region: <a href='/asia'>Asia</a> | <a href='/africa'>Africa</a> | <a href='/europe'>Europe</a> | \
<span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span> <a href='/middle_east'>Middle East</a> | <a href='/south_america'>South America</a> | <a href='/usa'>United States</a> | \
<span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span> <a href='/heatmap'>World</a><br><br></td></tr><tr><td><center>"
<span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span> <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp4 <span style="color: rgb(0, 96, 128);">"<tr><td><center><br><br><br><a href='/resetmap'>Reset All Counters</a></center></td></tr><tr></tr></HTML>"</span>

And the HTTP::respond portion changes to:

<span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">HTTP::respond</span> 200 content <span style="color: rgb(0, 96, 128);">"${static::resp1}${regions}${static::resp2}${zoom}&chd=t:${chd}&chld=${chld}${static::resp3} \</span>
<span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> Filter by URL: <a href='/$zoom'>All URLs</a> | $filters\
<span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> $static::resp4"

Note that all that needed to be added to the HTTP::respond code was a single variable, hence some of the craziness in the RULE_INIT section. I’m trying to keep things in the functional part of the code as simple as I can within reason.

That’s it, we should now have a list of all the regions and their total number of connections.  The only real caveat is that there’s no good way to only display the countries listed in the zoom region (I.E. only African sub-regions when viewing Africa or only countries in the Asian via when viewing Asia) since google is the one dictating which countries show up in each zoom view, so you get a list of all countries recorded on all views.  The cool part, however, is that because of the way the logic is structured and the way the counters were implemented your totals for region update based on the filter URL!

So now you can view a pretty map of any region of the world you want, filter that view based on a URL of your choosing to see how a given portion of your application is doing in that region, and have a key of sorts to see the actual number of connections in addition to the pretty picture.  Neat, if you ask me, and pretty easy to boot, all things considered.

Pictures of the output and complete source below, as always. That wraps up my immediate ideas for the Heatmap series, but if you have any cool ideas or requests, let me know and I might just crank out a fifth installment or beyond.

image_275938.png

image_275938.png

<span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">when</span> <span style="color: rgb(204, 102, 51);">RULE_INIT</span> {
<span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 128, 0);">##  Configure static portions of the HTML response for the heatmap pages</span>
<span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>   <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp1 <span style="color: rgb(0, 96, 128);">"<HTML><table width='100%' border='0'><tr><td></td><td><center><font size=5>Here is your site's usage:\</span>
<span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> </font></td></tr><tr><td align='center' rowspan='5'><b><u>Connections per Region:</u></b><br><br>"
<span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>   <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp2  <span style="color: rgb(0, 96, 128);">"</td><td><center><img src='http://chart.apis.google.com/chart?cht=t&chd=&chs=440x220&chtm="</span>
<span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>   <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp3 <span style="color: rgb(0, 96, 128);">"&chco=f5f5f5,edf0d4,6c9642,365e24,13390a' border='0'></center></td></tr><td><center><br><br>Zoom to region:\</span>
<span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>  <a href='/asia'>Asia</a> | <a href='/africa'>Africa</a> | <a href='/europe'>Europe</a> | <a href='/middle_east'>Middle East</a> | \
<span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span> <a href='/south_america'>South America</a> | <a href='/usa'>United States</a> | <a href='/heatmap'>World</a><br><br></td></tr><tr><td><center>"
<span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>   <span style="color: rgb(0, 0, 255);">set</span> <span style="color: rgb(0, 0, 255);">static</span>::resp4 <span style="color: rgb(0, 96, 128);">"<tr><td><center><br><br><br><a href='/resetmap'>Reset All Counters</a></center></td></tr><tr></tr></HTML>"</span>
<span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span> }
<span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span> 
<span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span> <span style="color: rgb(0, 0, 255);">when</span> <span style="color: rgb(204, 102, 51);">HTTP_REQUEST</span> <span style="color: rgb(0, 0, 255);">timing</span> on {
<span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span>   <span style="color: rgb(0, 0, 255);">switch</span> -glob [<span style="color: rgb(0, 0, 255);">string</span> tolower [<span style="color: rgb(0, 0, 255);">HTTP::uri</span>]] {
<span id="lnum14" style="color: rgb(96, 96, 96);">  14:</span>     <span style="color: rgb(0, 96, 128);">"/asia*"</span> -
<span id="lnum15" style="color: rgb(96, 96, 96);">  15:</span>     <span style="color: rgb(0, 96, 128);">"/africa*"</span> -
<span id="lnum16" style="color: rgb(96, 96, 96);">  16:</span>     <span style="color: rgb(0, 96, 128);">"/europe*"</span> -
<span id="lnum17" style="color: rgb(96, 96, 96);">  17:</span>     <span style="color: rgb(0, 96, 128);">"/middle_east*"</span> -
<span id="lnum18" style="color: rgb(96, 96, 96);">  18:</span>     <span style="color: rgb(0, 96, 128);">"/south_america*"</span> -
<span id="lnum19" style="color: rgb(96, 96, 96);">  19:</span>     <span style="color: rgb(0, 96, 128);">"/usa*"</span> -
<span id="lnum20" style="color: rgb(96, 96, 96);">  20:</span>     <span style="color: rgb(0, 96, 128);">"/world*"</span> -
<span id="lnum21" style="color: rgb(96, 96, 96);">  21:</span>     <span style="color: rgb(0, 96, 128);">"/heatmap*"</span> {
<span id="lnum22" style="color: rgb(96, 96, 96);">  22:</span>       <span style="color: rgb(0, 0, 255);">set</span> chld <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum23" style="color: rgb(96, 96, 96);">  23:</span>       <span style="color: rgb(0, 0, 255);">set</span> chd <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum24" style="color: rgb(96, 96, 96);">  24:</span>       <span style="color: rgb(0, 0, 255);">set</span> zoom <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum25" style="color: rgb(96, 96, 96);">  25:</span>       <span style="color: rgb(0, 0, 255);">set</span> zoomURL <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum26" style="color: rgb(96, 96, 96);">  26:</span>       <span style="color: rgb(0, 0, 255);">set</span> regions <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum27" style="color: rgb(96, 96, 96);">  27:</span>       <span style="color: rgb(0, 0, 255);">set</span> urlTotal 0
<span id="lnum28" style="color: rgb(96, 96, 96);">  28:</span>       <span style="color: rgb(0, 0, 255);">set</span> regionTotal 0
<span id="lnum29" style="color: rgb(96, 96, 96);">  29:</span> <span style="color: rgb(0, 128, 0);">##  Split apart the zoom region from the filter URL in the request  </span>
<span id="lnum30" style="color: rgb(96, 96, 96);">  30:</span>       <span style="color: rgb(0, 0, 255);">set</span> zoom [<span style="color: rgb(0, 0, 255);">getfield</span> [<span style="color: rgb(0, 0, 255);">string</span> map {<span style="color: rgb(0, 96, 128);">"/"</span> <span style="color: rgb(0, 96, 128);">""</span> <span style="color: rgb(0, 96, 128);">"heatmap"</span> <span style="color: rgb(0, 96, 128);">"world"</span>} [<span style="color: rgb(0, 0, 255);">HTTP::uri</span>]] <span style="color: rgb(0, 96, 128);">"?"</span> 1]
<span id="lnum31" style="color: rgb(96, 96, 96);">  31:</span>       <span style="color: rgb(0, 0, 255);">set</span> zoomURL [<span style="color: rgb(0, 0, 255);">getfield</span> [<span style="color: rgb(0, 0, 255);">string</span> map {<span style="color: rgb(0, 96, 128);">"/"</span> <span style="color: rgb(0, 96, 128);">""</span> <span style="color: rgb(0, 96, 128);">"heatmap"</span> <span style="color: rgb(0, 96, 128);">"world"</span>} [<span style="color: rgb(0, 0, 255);">HTTP::uri</span>]] <span style="color: rgb(0, 96, 128);">"?"</span> 2]
<span id="lnum32" style="color: rgb(96, 96, 96);">  32:</span> <span style="color: rgb(0, 128, 0);">##  Get a list of all states or countries, applying the URL filter where necessary</span>
<span id="lnum33" style="color: rgb(96, 96, 96);">  33:</span> <span style="color: rgb(0, 128, 0);">##  and retrieve the associated count of requests from that area to that URL</span>
<span id="lnum34" style="color: rgb(96, 96, 96);">  34:</span>   <span style="color: rgb(0, 128, 0);">##  First step through the mytables table, which is a pointer table referencing all subtables with counter values in them</span>
<span id="lnum35" style="color: rgb(96, 96, 96);">  35:</span>       <span style="color: rgb(0, 0, 255);">foreach</span> mysub [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable mytables] {
<span id="lnum36" style="color: rgb(96, 96, 96);">  36:</span>   <span style="color: rgb(0, 128, 0);">##  Next determine whether to search state or country tables</span>
<span id="lnum37" style="color: rgb(96, 96, 96);">  37:</span>         <span style="color: rgb(0, 0, 255);">if</span> {$zoom eq <span style="color: rgb(0, 96, 128);">"usa"</span>} {
<span id="lnum38" style="color: rgb(96, 96, 96);">  38:</span>           <span style="color: rgb(0, 0, 255);">if</span> {$mysub <span style="color: rgb(0, 0, 255);">starts_with</span> <span style="color: rgb(0, 96, 128);">"state:"</span>} {
<span id="lnum39" style="color: rgb(96, 96, 96);">  39:</span>   <span style="color: rgb(0, 128, 0);">##  For each state sub table step through each key, which will be a URL, and count the request to that URL.</span>
<span id="lnum40" style="color: rgb(96, 96, 96);">  40:</span>   <span style="color: rgb(0, 128, 0);">##  This is also where URL filtering is applied if applicable</span>
<span id="lnum41" style="color: rgb(96, 96, 96);">  41:</span>             <span style="color: rgb(0, 0, 255);">foreach</span> myurl [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable $mysub] {
<span id="lnum42" style="color: rgb(96, 96, 96);">  42:</span>               <span style="color: rgb(0, 0, 255);">if</span> {$zoomURL ne <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum43" style="color: rgb(96, 96, 96);">  43:</span>                 <span style="color: rgb(0, 0, 255);">if</span> {$myurl eq $zoomURL} {
<span id="lnum44" style="color: rgb(96, 96, 96);">  44:</span>                   <span style="color: rgb(0, 0, 255);">append</span> chld <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2]"</span>
<span id="lnum45" style="color: rgb(96, 96, 96);">  45:</span>                   <span style="color: rgb(0, 0, 255);">append</span> chd <span style="color: rgb(0, 96, 128);">"[table lookup -subtable $mysub $myurl],"</span>
<span id="lnum46" style="color: rgb(96, 96, 96);">  46:</span>                   <span style="color: rgb(0, 0, 255);">set</span> urlTotal [<span style="color: rgb(0, 0, 255);">table</span> lookup -subtable $mysub $myurl]
<span id="lnum47" style="color: rgb(96, 96, 96);">  47:</span>                 }
<span id="lnum48" style="color: rgb(96, 96, 96);">  48:</span>               } <span style="color: rgb(0, 0, 255);">else</span> {
<span id="lnum49" style="color: rgb(96, 96, 96);">  49:</span>                 <span style="color: rgb(0, 0, 255);">append</span> chld <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2]"</span>
<span id="lnum50" style="color: rgb(96, 96, 96);">  50:</span>                 <span style="color: rgb(0, 0, 255);">append</span> chd <span style="color: rgb(0, 96, 128);">"[table lookup -subtable $mysub $myurl],"</span>
<span id="lnum51" style="color: rgb(96, 96, 96);">  51:</span>                 <span style="color: rgb(0, 0, 255);">set</span> urlTotal [<span style="color: rgb(0, 0, 255);">table</span> lookup -subtable $mysub $myurl]
<span id="lnum52" style="color: rgb(96, 96, 96);">  52:</span>               }
<span id="lnum53" style="color: rgb(96, 96, 96);">  53:</span>               <span style="color: rgb(0, 0, 255);">set</span> regionTotal [<span style="color: rgb(0, 0, 255);">expr</span> $regionTotal + $urlTotal]
<span id="lnum54" style="color: rgb(96, 96, 96);">  54:</span>               <span style="color: rgb(0, 0, 255);">set</span> urlTotal 0
<span id="lnum55" style="color: rgb(96, 96, 96);">  55:</span>             }
<span id="lnum56" style="color: rgb(96, 96, 96);">  56:</span>             <span style="color: rgb(0, 0, 255);">append</span> regions <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2] : $regionTotal<br>"</span>
<span id="lnum57" style="color: rgb(96, 96, 96);">  57:</span>             <span style="color: rgb(0, 0, 255);">set</span> regionTotal 0
<span id="lnum58" style="color: rgb(96, 96, 96);">  58:</span>           }
<span id="lnum59" style="color: rgb(96, 96, 96);">  59:</span>         } <span style="color: rgb(0, 0, 255);">else</span> {
<span id="lnum60" style="color: rgb(96, 96, 96);">  60:</span>           <span style="color: rgb(0, 0, 255);">if</span> {$mysub <span style="color: rgb(0, 0, 255);">starts_with</span> <span style="color: rgb(0, 96, 128);">"country:"</span>} {
<span id="lnum61" style="color: rgb(96, 96, 96);">  61:</span>             <span style="color: rgb(0, 0, 255);">foreach</span> myurl [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable $mysub] {
<span id="lnum62" style="color: rgb(96, 96, 96);">  62:</span>               <span style="color: rgb(0, 0, 255);">if</span> {$zoomURL ne <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum63" style="color: rgb(96, 96, 96);">  63:</span>                 <span style="color: rgb(0, 0, 255);">if</span> {$myurl eq $zoomURL} {
<span id="lnum64" style="color: rgb(96, 96, 96);">  64:</span>                   <span style="color: rgb(0, 0, 255);">append</span> chld <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2]"</span>
<span id="lnum65" style="color: rgb(96, 96, 96);">  65:</span>                   <span style="color: rgb(0, 0, 255);">append</span> chd <span style="color: rgb(0, 96, 128);">"[table lookup -subtable $mysub $myurl],"</span>
<span id="lnum66" style="color: rgb(96, 96, 96);">  66:</span>                   <span style="color: rgb(0, 0, 255);">set</span> urlTotal [<span style="color: rgb(0, 0, 255);">table</span> lookup -subtable $mysub $myurl]
<span id="lnum67" style="color: rgb(96, 96, 96);">  67:</span>                 }
<span id="lnum68" style="color: rgb(96, 96, 96);">  68:</span>                 <span style="color: rgb(0, 0, 255);">set</span> regionTotal [<span style="color: rgb(0, 0, 255);">expr</span> $regionTotal + $urlTotal]
<span id="lnum69" style="color: rgb(96, 96, 96);">  69:</span>                 <span style="color: rgb(0, 0, 255);">set</span> urlTotal 0
<span id="lnum70" style="color: rgb(96, 96, 96);">  70:</span>               } <span style="color: rgb(0, 0, 255);">else</span> {
<span id="lnum71" style="color: rgb(96, 96, 96);">  71:</span>                 <span style="color: rgb(0, 0, 255);">append</span> chld <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2]"</span>
<span id="lnum72" style="color: rgb(96, 96, 96);">  72:</span>                 <span style="color: rgb(0, 0, 255);">append</span> chd <span style="color: rgb(0, 96, 128);">"[table lookup -subtable $mysub $myurl],"</span>
<span id="lnum73" style="color: rgb(96, 96, 96);">  73:</span>                 <span style="color: rgb(0, 0, 255);">set</span> urlTotal [<span style="color: rgb(0, 0, 255);">table</span> lookup -subtable $mysub $myurl]
<span id="lnum74" style="color: rgb(96, 96, 96);">  74:</span>               }
<span id="lnum75" style="color: rgb(96, 96, 96);">  75:</span>                 <span style="color: rgb(0, 0, 255);">set</span> regionTotal [<span style="color: rgb(0, 0, 255);">expr</span> $regionTotal + $urlTotal]
<span id="lnum76" style="color: rgb(96, 96, 96);">  76:</span>                 <span style="color: rgb(0, 0, 255);">set</span> urlTotal 0
<span id="lnum77" style="color: rgb(96, 96, 96);">  77:</span>             }
<span id="lnum78" style="color: rgb(96, 96, 96);">  78:</span>             <span style="color: rgb(0, 0, 255);">append</span> regions <span style="color: rgb(0, 96, 128);">"[getfield $mysub "</span>:<span style="color: rgb(0, 96, 128);">" 2] : $regionTotal<br>"</span>
<span id="lnum79" style="color: rgb(96, 96, 96);">  79:</span>             <span style="color: rgb(0, 0, 255);">set</span> regionTotal 0
<span id="lnum80" style="color: rgb(96, 96, 96);">  80:</span>           }
<span id="lnum81" style="color: rgb(96, 96, 96);">  81:</span>         }
<span id="lnum82" style="color: rgb(96, 96, 96);">  82:</span>       }
<span id="lnum83" style="color: rgb(96, 96, 96);">  83:</span> 
<span id="lnum84" style="color: rgb(96, 96, 96);">  84:</span> <span style="color: rgb(0, 128, 0);">##  Send back the pre-formatted response, set in RULE_INIT, combined with the map zoom, list of areas, and request count</span>
<span id="lnum85" style="color: rgb(96, 96, 96);">  85:</span>       <span style="color: rgb(0, 0, 255);">set</span> chd [<span style="color: rgb(0, 0, 255);">string</span> trimright $chd <span style="color: rgb(0, 96, 128);">","</span>]
<span id="lnum86" style="color: rgb(96, 96, 96);">  86:</span>   <span style="color: rgb(0, 128, 0);">##  First loop through the trackingurls class to get a list of all URLs to be tracked and format HTML around them for links</span>
<span id="lnum87" style="color: rgb(96, 96, 96);">  87:</span>       <span style="color: rgb(0, 0, 255);">set</span> filters <span style="color: rgb(0, 96, 128);">""</span>
<span id="lnum88" style="color: rgb(96, 96, 96);">  88:</span>       <span style="color: rgb(0, 0, 255);">foreach</span> mytrackingurl [<span style="color: rgb(0, 0, 255);">class</span> names trackingurls] {
<span id="lnum89" style="color: rgb(96, 96, 96);">  89:</span>         <span style="color: rgb(0, 0, 255);">append</span> filters <span style="color: rgb(0, 96, 128);">"<a href='${zoom}?${mytrackingurl}'>${mytrackingurl}</a> | "</span>
<span id="lnum90" style="color: rgb(96, 96, 96);">  90:</span>       }
<span id="lnum91" style="color: rgb(96, 96, 96);">  91:</span>       <span style="color: rgb(0, 0, 255);">set</span> filters [<span style="color: rgb(0, 0, 255);">string</span> trimright $filters <span style="color: rgb(0, 96, 128);">" | "</span>]
<span id="lnum92" style="color: rgb(96, 96, 96);">  92:</span> 
<span id="lnum93" style="color: rgb(96, 96, 96);">  93:</span>   <span style="color: rgb(0, 128, 0);">##  Combine the above generated HTML with the static HTML in RULE INIT and respond to the client</span>
<span id="lnum94" style="color: rgb(96, 96, 96);">  94:</span>      <span style="color: rgb(0, 0, 255);">HTTP::respond</span> 200 content <span style="color: rgb(0, 96, 128);">"${static::resp1}${regions}${static::resp2}${zoom}&chd=t:${chd}&chld=${chld}${static::resp3} \</span>
<span id="lnum95" style="color: rgb(96, 96, 96);">  95:</span>      Filter by URL: <a href='/$zoom'>All URLs</a> | $filters\
<span id="lnum96" style="color: rgb(96, 96, 96);">  96:</span>      $static::resp4"
<span id="lnum97" style="color: rgb(96, 96, 96);">  97:</span>     }
<span id="lnum98" style="color: rgb(96, 96, 96);">  98:</span>
<span id="lnum99" style="color: rgb(96, 96, 96);">  99:</span>     <span style="color: rgb(0, 96, 128);">"/resetmap"</span> {
<span id="lnum100" style="color: rgb(96, 96, 96);"> 100:</span>       <span style="color: rgb(0, 0, 255);">foreach</span> pointertable [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable mytables] {
<span id="lnum101" style="color: rgb(96, 96, 96);"> 101:</span>         <span style="color: rgb(0, 0, 255);">foreach</span> entry [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable $pointertable] {
<span id="lnum102" style="color: rgb(96, 96, 96);"> 102:</span>           <span style="color: rgb(0, 0, 255);">table</span> delete -subtable $pointertable $entry
<span id="lnum103" style="color: rgb(96, 96, 96);"> 103:</span>         }
<span id="lnum104" style="color: rgb(96, 96, 96);"> 104:</span>       }
<span id="lnum105" style="color: rgb(96, 96, 96);"> 105:</span>       <span style="color: rgb(0, 0, 255);">foreach</span> pointerentry [<span style="color: rgb(0, 0, 255);">table</span> keys -subtable mytables] {
<span id="lnum106" style="color: rgb(96, 96, 96);"> 106:</span>         <span style="color: rgb(0, 0, 255);">table</span> delete -subtable mytables $pointerentry
<span id="lnum107" style="color: rgb(96, 96, 96);"> 107:</span>       }
<span id="lnum108" style="color: rgb(96, 96, 96);"> 108:</span>       <span style="color: rgb(0, 0, 255);">HTTP::respond</span> 200 Content <span style="color: rgb(0, 96, 128);">"<HTML><center><br><br><br><br><br><br>Table Cleared.<br><br><br> <a href='/heatmap'>Return to Map</a></HTML>"</span>
<span id="lnum109" style="color: rgb(96, 96, 96);"> 109:</span>     }
<span id="lnum110" style="color: rgb(96, 96, 96);"> 110:</span> 
<span id="lnum111" style="color: rgb(96, 96, 96);"> 111:</span>     <span style="color: rgb(0, 0, 255);">default</span> {
<span id="lnum112" style="color: rgb(96, 96, 96);"> 112:</span> <span style="color: rgb(0, 128, 0);">##  Look up country & state locations </span>
<span id="lnum113" style="color: rgb(96, 96, 96);"> 113:</span>       <span style="color: rgb(0, 0, 255);">set</span> cloc [<span style="color: rgb(0, 0, 255);">whereis</span> [<span style="color: rgb(0, 0, 255);">IP::client_addr</span>] country]
<span id="lnum114" style="color: rgb(96, 96, 96);"> 114:</span>       <span style="color: rgb(0, 0, 255);">set</span> sloc [<span style="color: rgb(0, 0, 255);">whereis</span> [<span style="color: rgb(0, 0, 255);">IP::client_addr</span>] abbrev]
<span id="lnum115" style="color: rgb(96, 96, 96);"> 115:</span>
<span id="lnum116" style="color: rgb(96, 96, 96);"> 116:</span> <span style="color: rgb(0, 128, 0);">##  If the IP doesn't resolve to anything, pick a random IP (useful for testing on private networks)</span>
<span id="lnum117" style="color: rgb(96, 96, 96);"> 117:</span>       <span style="color: rgb(0, 0, 255);">if</span> {($cloc eq <span style="color: rgb(0, 96, 128);">""</span>) <span style="color: rgb(0, 0, 255);">and</span> ($sloc eq <span style="color: rgb(0, 96, 128);">""</span>)} {
<span id="lnum118" style="color: rgb(96, 96, 96);"> 118:</span>         <span style="color: rgb(0, 0, 255);">set</span> ip [<span style="color: rgb(0, 0, 255);">expr</span> { int(rand()*255) }].[<span style="color: rgb(0, 0, 255);">expr</span> { int(rand()*255) }].[<span style="color: rgb(0, 0, 255);">expr</span> { int(rand()*255) }].[<span style="color: rgb(0, 0, 255);">expr</span> { int(rand()*255) }]
<span id="lnum119" style="color: rgb(96, 96, 96);"> 119:</span>         <span style="color: rgb(0, 0, 255);">set</span> cloc [<span style="color: rgb(0, 0, 255);">whereis</span> $ip country]
<span id="lnum120" style="color: rgb(96, 96, 96);"> 120:</span>         <span style="color: rgb(0, 0, 255);">set</span> sloc [<span style="color: rgb(0, 0, 255);">whereis</span> $ip abbrev]
<span id="lnum121" style="color: rgb(96, 96, 96);"> 121:</span>         <span style="color: rgb(0, 0, 255);">if</span> {($cloc eq <span style="color: rgb(0, 96, 128);">""</span>) <span style="color: rgb(0, 0, 255);">or</span> ($sloc eq <span style="color: rgb(0, 96, 128);">""</span>)} {
<span id="lnum122" style="color: rgb(96, 96, 96);"> 122:</span>             <span style="color: rgb(0, 0, 255);">set</span> cloc <span style="color: rgb(0, 96, 128);">"US"</span>
<span id="lnum123" style="color: rgb(96, 96, 96);"> 123:</span>           <span style="color: rgb(0, 0, 255);">set</span> sloc <span style="color: rgb(0, 96, 128);">"WA"</span>
<span id="lnum124" style="color: rgb(96, 96, 96);"> 124:</span>         }
<span id="lnum125" style="color: rgb(96, 96, 96);"> 125:</span>       }
<span id="lnum126" style="color: rgb(96, 96, 96);"> 126:</span> 
<span id="lnum127" style="color: rgb(96, 96, 96);"> 127:</span> <span style="color: rgb(0, 128, 0);">##  Strip slashes from URI to allow easy queries</span>
<span id="lnum128" style="color: rgb(96, 96, 96);"> 128:</span>       <span style="color: rgb(0, 0, 255);">set</span> friendlyURL [<span style="color: rgb(0, 0, 255);">string</span> map {/ <span style="color: rgb(0, 96, 128);">""</span>} [<span style="color: rgb(0, 0, 255);">HTTP::uri</span>]]
<span id="lnum129" style="color: rgb(96, 96, 96);"> 129:</span> <span style="color: rgb(0, 128, 0);">##  Create a new table named country:location or state:location</span>
<span id="lnum130" style="color: rgb(96, 96, 96);"> 130:</span>       <span style="color: rgb(0, 0, 255);">if</span> {[<span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">incr</span> -subtable country:$cloc -mustexist $friendlyURL] eq <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum131" style="color: rgb(96, 96, 96);"> 131:</span>         <span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">set</span> -subtable country:$cloc $friendlyURL 1 indefinite indefinite
<span id="lnum132" style="color: rgb(96, 96, 96);"> 132:</span>       }
<span id="lnum133" style="color: rgb(96, 96, 96);"> 133:</span> <span style="color: rgb(0, 128, 0);">##  Update the mytables pointer table with the new country or state table name  </span>
<span id="lnum134" style="color: rgb(96, 96, 96);"> 134:</span>       <span style="color: rgb(0, 0, 255);">if</span> {[<span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">incr</span> -subtable mytables -mustexist country:$cloc] eq <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum135" style="color: rgb(96, 96, 96);"> 135:</span>         <span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">set</span> -subtable mytables country:$cloc 1 indefinite indefinite
<span id="lnum136" style="color: rgb(96, 96, 96);"> 136:</span>       }
<span id="lnum137" style="color: rgb(96, 96, 96);"> 137:</span> <span style="color: rgb(0, 128, 0);">##  Same as above for states, not countries.</span>
<span id="lnum138" style="color: rgb(96, 96, 96);"> 138:</span>       <span style="color: rgb(0, 0, 255);">if</span> {$cloc eq <span style="color: rgb(0, 96, 128);">"US"</span>} {
<span id="lnum139" style="color: rgb(96, 96, 96);"> 139:</span>         <span style="color: rgb(0, 0, 255);">if</span> {[<span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">incr</span> -subtable state:$sloc -mustexist $friendlyURL] eq <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum140" style="color: rgb(96, 96, 96);"> 140:</span>             <span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">set</span> -subtable state:$sloc $friendlyURL 1 indefinite indefinite
<span id="lnum141" style="color: rgb(96, 96, 96);"> 141:</span>         }
<span id="lnum142" style="color: rgb(96, 96, 96);"> 142:</span>         <span style="color: rgb(0, 0, 255);">if</span> {[<span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">incr</span> -subtable mytables -mustexist state:$sloc] eq <span style="color: rgb(0, 96, 128);">""</span>} {
<span id="lnum143" style="color: rgb(96, 96, 96);"> 143:</span>             <span style="color: rgb(0, 0, 255);">table</span> <span style="color: rgb(0, 0, 255);">set</span> -subtable mytables state:$sloc 1 indefinite indefinite
<span id="lnum144" style="color: rgb(96, 96, 96);"> 144:</span>         }
<span id="lnum145" style="color: rgb(96, 96, 96);"> 145:</span>       }
<span id="lnum146" style="color: rgb(96, 96, 96);"> 146:</span>       <span style="color: rgb(0, 0, 255);">HTTP::respond</span> 200 Content <span style="color: rgb(0, 96, 128);">"Added - Country: $cloc State: $sloc"</span>
<span id="lnum147" style="color: rgb(96, 96, 96);"> 147:</span>     }
<span id="lnum148" style="color: rgb(96, 96, 96);"> 148:</span>   }
<span id="lnum149" style="color: rgb(96, 96, 96);"> 149:</span> }

Related Articles

This is really cool. Thanks :slightly_smiling_face:

Can you think of a way we can do this on the GTM.

That would be a fantastic add for this.

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/52/afv/topic/aft/1173024/aff/31/showtab/groupforums/Default.aspx

lot of people using f5 gtm are trying to come up with something on the irule where we can tag not just the ldns locations ( we can do that through icontrol by pulling stats), but something which can show where the requests went too.

Cant seem to do tables or even a catch on the irule side.

This is really cool. Thanks :slightly_smiling_face:

Can you think of a way we can do this on the GTM.

That would be a fantastic add for this.

lot of people using f5 gtm are trying to come up with something on the irule where we can tag not just the ldns locations ( we can do that through icontrol by pulling stats), but something which can show where the requests went too.

Cant seem to do tables or even a catch on the irule side.

when adding the rule, then adding it to a pool, I get the following:

Rule [/Common/heatmap] error: Unable to find value_list (trackingurls) referenced at line 85: [class names trackingurls]

The code is intact from the above article…

you need to add a datagroup called trackingurls

Well, now I’m in over my head. Back to the books.

Thanks!

A datagroup can be added in same location as iRules in the gui, Colin discusses the need/reason for the class in part 3: https://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/1086368/Heatmaps-iRules-Style-Part-3-ampndash-URL-Filtering.aspx

Thanks for the help.

Not sure how to ask or what the appropriate next step is. I have the iRule built in the F5. I used the code from it’s entirety posted on part4. I have also created the datagroup. From the level of knowledge of I had, I creating thi, and this is what the results are:

"ltm data-group internal /Common/trackingurls {

type string

}"

I applied this to a less than heavy traffic VIP and let it run for awhile, I’m not sure of two things at this point:

If it is working - stats didn’t indicate if it was, I did get counter increments in stats but I have no idea if that was a result of adding that iRule to the VIP.

Second, where do I use the data, does the rule produce a url that I use with the maps api…? If anyone can help, that will be awesome, I’ll be over here wondering aimlessly in the weeds.

Thanks again,

Randy