DataScript: avi.vs.analytics.counter

DataScript

Function avi.vs.analytics.counter ( metric_name, [operation], [value] )
Description Increments or clears the named counter metric.

Refer to the User-defined Metrics article for important details.
Events HTTP_REQ
HTTP_RESP
RESP_FAILED
Parameter metric_name is a string value chosen by the user to identify the counter metric.

operation is a numeric which may take on one of two values:

  1. avi.vs.analytics.INCR — Increments the counter metric by value.
  2. avi.vs.analytics.CLEAR — Clears the counter metric to 0. The value parameter is ignored.
value is the amount to increment the counter metric. If value is not specified, it defaults to 1.

Notes

  • If the operation is not specified, it defaults to avi.vs.analytics.INCR.

  • The following applies to all invocations of avi.vs.analytics.counter.

    1. If metric_name has never been defined, the function will define it and set the metric_type to avi.vs.analytics.METRICTYPE_COUNTER. Thereafter, the function will perform the indicated operation as modified by value.
    2. If metric_name has been defined before, but has a metric_type other than avi.vs.analytics.METRICTYPE_COUNTER, the function will log an error and the request/response causing this function call will be cancelled.
Returns No value returned
Related avi.vs.analytics.get_metric()
Examples 1. Create a counter-type metric with name “Foo” and add 42 to it. If the metric is not present, then create it and initialize it with default value, 0.

avi.vs.analytics.counter(“Foo”, avi.vs.analytics.INCR, 42)

2. Increment the counter-type metric named "Foo." by 1.

avi.vs.analytics.counter(“Foo”, avi.vs.analytics.INCR)

3. Increment the counter named "tls1_2" if the SSL protocol is "TLSv1.2."

if avi.ssl.protocol() == "TLSv1.2" then
     avi.vs.analytics.counter("tls1_2", avi.vs.analytics.INCR, 1)