ltm rule command STATS incr
iRule(1) BIG-IP TMSH Manual iRule(1)
STATS::incr
Increments the value of a Statistics profile setting.
SYNOPSIS
STATS::incr PROFILE_NAME FIELD_NAME (VALUE)?
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 []
* Increments or decrements (negative value) 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/decrement. If not provided, LTM will increment by 1.
RETURN VALUE
Returns the current value of the field which was incremented.
VALID DURING
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 reused in the RULE_INIT event.
# See the STATS::set page for a workaround:
#
# Simple rule showing how to intialize, increment and decrement a stats profilefield
#
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 : Incremented the current count to: 100
Rule stats_rule : Decremented the current count to: 99
HINTS
SEE ALSO
CHANGE LOG
@BIGIP-9.2.0 --First introduced the command.
BIG-IP 2022-04-12 iRule(1)