It would be useful to have a way to determine the name of the stats profile from an iRule. If this isn't possible, you could open a case with F5 Support and ask them to consider adding this functionality in a future release.
For now, do you want to use one stats profile per VIP? If so, you could use a naming convention based on the VIP name that would allow you to write a generic rule:
when HTTP_REQUEST {
log local0. "\[virtual name\]: [virtual name]"
log local0. "vip stats profile name: [virtual name]_stats"
log local0. "vip stats profile field1 value: [STATS::get [virtual name]_stats field1]"
log local0. "vip stats profile field1 value incr: [STATS::incr [virtual name]_stats field1]"
log local0. "vip stats profile field1 value: [STATS::get [virtual name]_stats field1]"
}
And the log output:
: [virtual name]: example.com_http_vs
: vip stats profile name: example.com_http_vs_stats
: vip stats profile field1 value: 0
: vip stats profile field1 value incr: 1
: vip stats profile field1 value: 1
If you're trying to use one stats profile on multiple VIPs, you could create a datagroup which maps the VIP name to the stats profile name. You could then use class or findclass in RULE_INIT to set the stats profile name for the particular VIP the iRule is running on.
Neither option is perfect, but they would get you around the need to hardcode the stats profile name in the iRule.
Aaron