STATS::incr¶
Description¶
Increments the value of the specified setting (field), in the
specified Statistics profile, by the specified value. If you do not
specify a value, the system increments by 1. It is possible to set
a negative value in order to decrement the counter. Returns the
current value of the field which was incremented.
Syntax¶
STATS::incr <profile> <field> [<value>]
STATS::incr <profile> <field> [<value>]¶
Increments the value of a Statistics profile setting.
- the name of the profile. Even though you provide the name, you must
have the profile applied to the Virtual Server.
- The NAME of the field to increment. Fields are numbered from 1 to
32, but you must provide the NAME of the field for it to work.
- Amount to increment. If not provided, LTM will increment by 1.
Using negative numbers will decrement the counter.
- Returns the current value of the field which was incremented.===Examples===
#Check initial page of website to see if connection is from IE6, IE7, or other browser. #Easy to add more. #Andre Padua #a.padua@f5.com # #ADD a STATS Profile to LTM and apply it to the Virtual Server. # #profile stats browser_version { # defaults from stats # field1 IE6 # field2 IE7 # field3 Other #} # when HTTP_REQUEST { if { [HTTP::uri] ends_with "Default.aspx" } { #log local0. "Requested URL was Default.aspx" switch -glob [string tolower [HTTP::header User-Agent]] { "*msie 6.0*" { #log local0. "Browser is IE6" STATS::incr browser_version IE6 } "*msie 7.0*" { #log local0. "Browser is IE7" STATS::incr browser_version IE7 } "*" { #log local0. "Browser is not IE6 or IE7" STATS::incr browser_version Other } } } }
# Note: this won't work as it is posted in 9.4.x/10.0.x as STATS::set cannot be used in the RULE_INIT event.
# See the STATS::set page for a workaround:
# http://devcentral.f5.com/wiki/default.aspx/iRules/STATS__set.html
#
# Simple rule showing how to intialize, increment and decrement a stats profile field
#
when RULE_INIT {
# Initialise the number of unanswered HTTP requests at 0
log local0. "Initialize the count of unanswered requests: [STATS::set my_stats_profile_name "current_count" 0]"
}
when HTTP_REQUEST {
# Increment the number of unanswered HTTP requests
log local0. "Incremented the current count to: [STATS::incr my_stats_profile_name "current_count"]"
}
when HTTP_RESPONSE {
# Increment the number of unanswered HTTP requests
log local0. "Decremented the current count to: [STATS::incr my_stats_profile_name "current_count" -1]"
}
Sample log output:
Rule: Initialize the count of unanswered requests: 0
Rule stats_rule <HTTP_REQUEST>: Incremented the current count to: 100
Rule stats_rule <HTTP_RESPONSE>: Decremented the current count to: 99