Forum Discussion
iRule hitcount logging
Hello DevCentral,
I have an iRule for redirection based on host headers. I want to make a hit count on each host header. Is this possible?
when HTTP_REQUEST {
if { [HTTP::host] contains "example.com," } {
HTTP::redirect "https://www,.secureexample.com[HTTP::uri]"
}
if { [HTTP::host] contains "example.no" } {
HTTP::redirect "https://www.secureexample.no[HTTP::uri]"
}
if { [HTTP::host] contains "example.dk" } {
HTTP::redirect "https://www.secureexample.dk[HTTP::uri]"
}
}
I was thinking that I could use something like:
log local0. "Number of hits on [HTTP::host]:[HTTP::request_num]".
Any ideas on how I could implement it? All I want to know is how many hits each host header gets.
Regards,
Martin Karlsen
- nitass
Employee
statistics profileroot@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.19.252:80 ip-protocol tcp mask 255.255.255.255 profiles { http { } mystats { } tcp { } } rules { myrule } snat automap vlans-disabled } root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm profile statistics mystats ltm profile statistics mystats { app-service none field1 example.com field2 example.no field3 example.dk } root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { if { [HTTP::host] contains "example.com" } { STATS::incr mystats example.com 1 HTTP::redirect "https://www.secureexample.com[HTTP::uri]" } if { [HTTP::host] contains "example.no" } { STATS::incr mystats example.no 1 HTTP::redirect "https://www.secureexample.no[HTTP::uri]" } if { [HTTP::host] contains "example.dk" } { STATS::incr mystats example.dk 1 HTTP::redirect "https://www.secureexample.dk[HTTP::uri]" } } } root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) show ltm profile statistics mystats -------------------------------- Ltm::Profile Statistics: mystats -------------------------------- example.com 7 example.dk 1 example.no 4
- nitass
Employee
istatsroot@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.19.252:80 ip-protocol tcp mask 255.255.255.255 profiles { http { } tcp { } } rules { myrule } snat automap vlans-disabled } root@(ve11a)(cfg-sync Changes Pending)(Active)(/Common)(tmos) list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { ISTATS::incr "ltm.virtual /Common/bar counter [HTTP::host]" 1 if { [HTTP::host] contains "example.com" } { HTTP::redirect "https://www.secureexample.com[HTTP::uri]" } if { [HTTP::host] contains "example.no" } { HTTP::redirect "https://www.secureexample.no[HTTP::uri]" } if { [HTTP::host] contains "example.dk" } { HTTP::redirect "https://www.secureexample.dk[HTTP::uri]" } } } [root@ve11a:Active:Changes Pending] config tmsh show ltm virtual bar --------------------------------------------------------- Ltm::Virtual Server: bar --------------------------------------------------------- Status Availability : unknown State : enabled Reason : The children pool member(s) either don't have service checking enabled, or service check results are not available yet CMP : enabled CMP Mode : all-cpus Destination : 172.28.19.252:80 Traffic ClientSide Ephemeral General Bits In 30.4K 0 - Bits Out 21.8K 0 - Packets In 48 0 - Packets Out 32 0 - Current Connections 0 0 - Maximum Connections 1 0 - Total Connections 8 0 - Min Conn Duration/msec - - 3 Max Conn Duration/msec - - 5 Mean Conn Duration/msec - - 4 Total Requests - - 0 CPU Usage Ratio (%) Last 5 Seconds 0 Last 1 Minute 0 Last 5 Minutes 0 User-defined Value example.com 1 example.dk 2 example.no 1 test.example.com 1 www.example.com 1 www.example.dk 1 www.example.no 1
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com