Skip to content

Instantly share code, notes, and snippets.

@f5-rahm
Last active November 17, 2022 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f5-rahm/e32f2e93beaca2752bc4853ae1af5b24 to your computer and use it in GitHub Desktop.
Save f5-rahm/e32f2e93beaca2752bc4853ae1af5b24 to your computer and use it in GitHub Desktop.
Colin Walker's original heatmap iRule (for reference - use heatmap_2022 instead)
ltm rule /Common/heatmap {
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><br><br><br><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'><br><br><br><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><br><br><br>Table Cleared.<br><br><br> <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
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment