heatmaps
2 TopicsHeatmaps Part1
Problem this snippet solves: I’ve been tinkering with a way to allow iRules to make that easier, and to allow those interested parties to see some usage statistics in a visually interesting, real-time manner, without adding much heavy lifting for you or your application. The idea is simple, create a heat map view of your HTTP requests, mapped to the locations around the United States (to start with). This will give you an idea which areas are most highly utilizing your application in a very easy on the eyes fashion. Best of all, of course, is that we’re going to generate this 100% with iRules. For the full write-up check out the article. (Note: There is an update to this iRule using the newer GeoCharts.) Code: (as gist) when HTTP_REQUEST { if {[HTTP::uri] starts_with "/heatmap"} { set chld "" set chd "" foreach state [table keys -subtable states] { append chld $state append chd "[table lookup -subtable states $state]," } set chd [string trimright $chd ","] HTTP::respond 200 content "<HTML><center><font size=5>Here is your site's usage by state:</font><img src='http://chart.apis.google.com/chart?cht=t&chd=&chs=440x220&chtm=usa&chd=t:$chd&chld=$chld&chco=f5f5f5,edf0d4,6c9642,365e24,13390a' border='0'><a href='/resetmap'>Reset Map</a></center></HTML>" } elseif {[HTTP::uri] starts_with "/resetmap"} { foreach state [table keys -subtable states] { table delete -subtable states $state } HTTP::respond 200 Content "<HTML><center>Table Cleared. <a href='/heatmap'>Return to Map</a></HTML>" } else { set loc [whereis [IP::client_addr] abbrev] if {$loc eq ""} { set ip [expr { int(rand()*255) }].[expr { int(rand()*255) }].[expr { int(rand()*255) }].[expr { int(rand()*255) }] set loc [whereis $ip abbrev] } if {[table incr -subtable states -mustexist $loc] eq ""} { table set -subtable states $loc 1 indefinite indefinite } } }783Views0likes0CommentsiRules Heat Map - US Only
Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’. Short Description This iRule is an update to the original by Colin Walker. It takes source IPs and does a geolocation lookup on them and if within a US State, adds that as a counter against that state in the session table memory. A request to /heatmap on the applicable virtual server will display a US map with request counts from each state utilizing Google's GeoCharts. Problem solved by this Code Snippet This is not solving a problem, but is providing enhanced view of data traversing the BIG-IP. How to use this Code Snippet Apply the iRule to your application's virtual server To view the map, use the URI /heatmap To clear the data from memory, use the URI /resetmap Code Snippet Meta Information Version: Tested on TMOS version 16.1.3, but should work as is on any version 12.1.x forward. Coding Language: iRules, HTML, and Javascript. Full Code Snippet Code is accessible in this gist on GitHub.881Views0likes0Comments