The following Virtual Service functions are available in DataScripts:

Function

Description

avi.vs.analytics.counter(metric_name, [operation], [value])

Creates and manipulates a counter-type metric. For more information, see the NSX Advanced Load Balancer Monitoring Components topic in theVMware NSX Advanced Load Balancer Monitoring and Operability Guide.

avi.vs.analytics.gauge (metric_name, [operation], [value])

Creates and manipulates a gauge-type metric.

avi.vs.analytics.get_metric (metric_name, metric_type)

Return the user-defined metric value if one with the given name and given type exists.

avi.vs.analytics.get_counter()

Returns the value of the metric, be it of type absolute, counter, or gauge.

avi.vs.client_ip()

Returns the client IP address

avi.vs.client_port()

Returns the client source port

avi.vs.close.conn([reset])

Close the current TCP/UDP connection

avi.vs.ip()

Returns IP address of the VS

avi.vs.log()

Write a custom log to VS > client logs.

avi.vs.name()

Returns the name of the virtual service.

avi.vs.port()

Returns the VS port of the connection.

avi.vs.persist(key, [lifetime], [pool])

Creates peristence entry using the key used after load balancing traffic.

avi.vs.rate_limit( type, string_to_limit, [defer_action=False] )

Rate limits entities of various kinds.

avi.vs.reqvar.*

Set a global variable usable across events.

avi.vs.table_insert( [table_name,] key, value [, lifetime] )

Store custom data in a time-based table.

avi.vs.table_lookup( [table_name,] key [, lifetime_exten] )

Lookup data in a table.

avi.vs.table_refresh( [table_name,] key [, lifetime_exten] )

Update the expire time for a table entry.

avi.vs.rate.limit.exceed()

Rate limits entities of various kinds.

avi.vs.table_remove( [table_name,] key )

Remove data from a table.

avi.vs.get_open_conns()

Returns the total number of open connections per Service Engine attached to the current virtual service.

avi.vs.se_count()

Returns the total number of Service Engines attached to the current virtual service.

avi.vs.analytics.counter

Function

avi.vs.analytics.counter ( metric_name, [operation], [value] )

Description

Increments or clears the named counter metric.

For more information, see NSX Advanced Load Balancer Monitoring Components topic in theVMware NSX Advanced Load Balancer Monitoring and Operability Guide

.E.vents

  • HTTP_REQ

  • HTTP_RESP

  • RESP_FAILED

Parameter

  1. metric_name is a string value chosen by the user to identify the counter metric.

  2. operation is 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.

  3. value is the amount to increment the counter metric. If the value is not specified, it defaults to 1.

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

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

    • If metric_name has never been defined, the function will define it and set the metric_type to avi.vs.analytics.METRICTYPE_COUNTER. After that, the function will perform the indicated operation as modified by value.

    • 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 canceled.

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)

avi.vs.analytics.gauge

Function

avi.vs.analytics.gauge ( metric_name, [operation], [value] )

Description

Increments, decrements, sets or clears the named gauge metric.

For more information, see NSX Advanced Load Balancer Monitoring Components topic in theVMware NSX Advanced Load Balancer Monitoring and Operability Guide.

Events

  • HTTP_REQ

  • HTTP_RESP

  • RESP_FAILED

Parameter

  1. metric_name is a string value chosen by the user to identify the gauge metric.

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

    1. avi.vs.analytics.INCR — Increments the counter metric by value.

    2. avi.vs.analytics.DECR — Decrements the gauge metric by value. If the current value of the gauge metric is less than value, this operation resets the gauge metric to 0.

    3. avi.vs.analytics.SET — Sets the gauge metric to value.

    4. avi.vs.analytics.CLEAR — Clears the counter metric to 0. The value parameter is ignored.

  3. value is the amount to increment the counter metric. If the value is not specified, it defaults to 1.

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

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

    • If metric_name has never been defined, the function will define it and set the metric_type to avi.vs.analytics.METRICTYPE_GAUGE. After that, the function will perform the indicated operation as modified by value.

    • If metric_name has been defined before but has a metric_type other than avi.vs.analytics.METRICTYPE_GAUGE, the function will log an error, and the request/response causing this function call will be canceled.

Returns

No value returned

Related

avi.vs.analytics.get_metric()

Examples

  1. Create a gauge-type metric with name “speedo” and add 42 to it. If the gauge-type metric is not present, then create it and initialize it with default value, 0.

    avi.vs.analytics.gauge(“speedo”, avi.vs.analytics.INCR, 42)
  2. Increment the gauge-type metric named "speedo." by 1.

    avi.vs.analytics.gauge(“speedo”, avi.vs.analytics.INCR)

avi.vs.analytics.get_metric

Function

avi.vs.analytics.get_metric ( metric_name, metric_type ) )

Description

Returns the value of the metric, be it of type counter or gauge. Before doing so, the function first checks if metric_name has been defined. If it has, it then compares the value of metric_type to the type previously stored. If metric_name has never been defined, or the type is not correct, the function will report an error on the log and the request/response causing this function call will be cancelled.

For more information, see the User-defined Metrics section in the NSX Advanced Load Balancer Monitoring Components topic in the VMware NSX Advanced Load Balancer Monitoring and Operability Guide.

Events

  • HTTP_REQ

  • HTTP_RESP

  • RESP_FAILED

Parameter

  1. metric_name is a string value chosen by the user to identify the metric.

  2. metric_type is a numeric parameter to be set by making a symbolic reference to avi.vs.analytics.METRICTYPE_GAUGE or avi.vs.analytics.METRICTYPE_COUNTER.

Returns

The value of the metric

Related

avi.vs.analytics.counter(), avi.vs.analytics.gauge()

Example

Set goo-current-val to the current value of a counter-type metric named goo, if it exists.

goo-current-val = avi.vs.analytics.get_metric ("goo", avi.vs.analytics.METRICTYPE_COUNTER)

avi.vs.analytics.get_counter

Function

avi.vs.analytics.get_counter ( metric_name, metric_type )

Description

Returns the metric's value, be it of type absolute, counter, or gauge. Before doing so, the function first checks if metric_name has been defined. If it has, it then compares the value of metric_type to the type previously stored. If metric_name has never been defined, or the type is not correct, the function will report an error on the log.

Events

  • HTTP_REQ

  • HTTP_RESP

  • RESP_FAILED

Parameter

metric_name is a string value chosen by the user to identify the metric.

metric_type is a numeric parameter to be set by making a symbolic reference to:

  • avi.vs.analytics.USERDEFINED_METRICTYPE_ABSOLUTE

  • avi.vs.analytics.USERDEFINED_METRICTYPE_GAUGE or

  • avi.vs.analytics.USERDEFINED_METRICTYPE_COUNTER

Returns

The value of the metric

Related

  • avi.vs.analytics.absolute()

  • avi.vs.analytics.counter()

  • avi.vs.analytics.gauge()

Example

TBD

avi.vs.client_ip

Function

avi.vs.client_ip()

Description

Returns the client's IPv4 or IPv6 address.

Events

All

Parameter

None

Returns

String containing the client’s source IP address.

Example

Insert the source IP address of a client into an HTTP header.

avi.http.add_header("XFF", avi.vs.client_ip())

avi.vs.client_port

Function

avi.vs.client_port()

Description

Returns the client's source port.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

None

Returns

String containing client’s source port.

Example

Simple way to provide A/B testing by distributing 1/10th of connections to pool1.

if string.endswith(avi.vs.client_port(), "0") then
   avi.pool.select("Pool1")
else avi.pool.select("Pool2")
end

avi.vs.close.connection

Function

avi.vs.close_conn ( [reset] )

Description

Closes the current TCP/UDP connection. The reset flag is of no consequence in case of a UDP connection.

Events

  • VS_DATASCRIPT_EVT_L4_REQUEST

  • VS_DATASCRIPT_EVT_L4_RESPONSE

Parameter

The reset flag will reset the connection, rather than use the default FIN.

Returns

No return value

Example

if avi.vs.client_ip() == "10.1.1.1" then
avi.vs.close_conn()
end
avi.vs.close_conn(1) 

avi.vs.ip

Function

avi.vs.ip()

Description

Returns the virtual service IPv6 address which accepted the request or connection.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

The reset flag will reset the connection, rather than use the default FIN.

Returns

IPv6 address in hexadecimal string format (separated by colons), for instance, 2001:db8::1122:ab12IPv4 address in octets format (separated by decimals), for instance, 10.1.1.1

Example

Insert a header informing the server which VS traffic originated from.

avi.http.add_header("VS_IP", avi.vs.ip())

avi.vs.log

Function

avi.vs.log()

Description

Generate a log associated with the connection or request and viewed within the Virtual Service > Client Log page. A log field is created called datascript_log, containing the DataScript’s name and the output of the avi.vs.log command. If avi.vs.log is called multiple times, the output of each invocation goes in the same datascript_log field in the client log.

Events

  • HTTP_REQ

  • HTTP_RESP

  • HTTP_RESP_DATA

  • HTTP_REQ_DATA

  • HTTP_RESP_FAILED

  • LB_DONE

  • LB_FAILED

  • AUTH

  • POST_AUTH

  • SSL_HANDSHAKE_DONE

  • SSL_CLIENT_HELLO

  • SSL_PRE_CONNECT

Parameter

  • Logs may contain any arbitrary combination of string, number, Boolean and nil values.

  • If the last argument avi.SIG_ENABLE passed, the connection log is converted to a significant log.

Returns

None

Example

From DataScript "Log1" HTTP_REQ event:

avi.vs.log("Hello World!")

From DataScript "Log2" HTTP_RESP event:

num = 2
avi.vs.log("Hello " .. num .. " You!")

Output from the client log:

DataScript Log: [string "Log1"]:1: Hello World!
DataScript Log: [string "Log2"]:1: Hello 2 You!
Note:

The logs are prefixed by meta information, which is generally the function name and line number calling avi.vs.log(). When the call is not made from a function, the name is the name of the script (in our example, the script is a string, not a file, named Log1).

Significant Logging Example:

From DataScript "Log1" HTTP_REQ event:

avi.vs.log("Hello World!", avi.SIG_ENABLE)

Output from the client log:

DataScript Log: [string "Log1"]:1: Hello World!
Significance: Datascript Significant Log.

avi.vs.name

Function

avi.vs.name()

Description

Returns the name of the virtual service which accepted the request or connection.

Events

HTTP_REQ

HTTP_RESP

Parameter

None

Returns

String containing the virtual service name.

Example

Insert a header in traffic sent to the server: X-Source: www.avi.com-10.1.1.1

avi.http.add_header("X-Source", avi.vs.name() .. "-" .. avi.vs.ip())

avi.vs.port()

Function

avi.vs.port()

Description

Returns the virtual service port that received the request or connection.

Events

HTTP_REQ

HTTP_RESP

Parameter

None

Returns

String containing the virtual service port number.

Example

Close the connection if the HTTP request did not arrive on port 443.

if avi.vs.port() ~= "443" then
   avi.http.close_conn()
end

avi.vs.persist

Function

avi.vs.persist()

Description

Load balances the request to the optional provided pool or the pool attached to the virtual service.

This function also creates a key-value persistence entry for the same. The key being the passed parameter, and the value being the load balanced IP, port (Eg: 10.10.10.10-80).

Optional lifetime ensures the persistence table entry is created with the passed lifetime.

The default is 300s.

Under the hood, this API performs traditional load balancing and automatically creates a persistence table entry with the value being the load-balanced backend server.

Repeatedly calling out this API will refresh the timeout.

Events

VS_DATASCRIPT_EVT_L4_REQUEST

Parameter

Key , [lifetime], [pool]

Returns

No return value

Example

if username == “my_user” then
avi.vs.persist(username, 3600, “POOL_80”)
Note:

This API yields from a DataScript and no further statements after this API will run. This is a terminal API.

avi.vs.rate.limit

Function

avi.vs.rate_limit( type, string_to_limit, [defer_action=False] )

Description

Rate limits entities of various kinds.

Events

HTTP_REQ

Parameter

  • type is a string specifying the type of rate limiter. Currently type must be set to avi.RL_CUSTOM_STRING.

  • string_to_limit is a unique identifier of the entity that should be rate limited. This is a string, such as a JsessionID, a username or an IP address.

  • defer_action is an optional True/False flag. If True, the given_action (described below) is not taken when the rate limit has exceeded the threshold. If the rate limit action is set to discard the connection, the rule is not processed any further. The defer_action parameter could be used to prevent the connection from being dropped by the profile, allowing further DataScript logic to process before an action could be manually enacted later by the DataScript.

Returns

The function returns two optional, purely informational variables:

  1. count_exceeded is true when the count is exceeded.

  2. given_action is the action the rate limit profile is configured to execute as long as the defer_action parameter is not set. The given_action is configured within the rate limit profile through the CLI. This information may be used to manually recreate these actions within the DataScript.

The possible options are:

  • avi.RL_ACTION_CLOSE_CONN – Closes the TCP connection. No further rule processing will occur.

  • avi.RL_ACTION_LOCAL_RSP – Returns a statically configured HTTP response page. No further rule processing will occur.

  • avi.RL_ACTION_REDIRECT – Redirects the request to another URL. No further rule processing will occur.

  • avi.RL_ACTION_NONE – Do nothing. A significant log for the request will be generated, but the request will be forwarded on to the chosen pool server.

Additional Configuration

DataScript must be configured to reference a rate limit profile, which is nested within a HTTP application profile, which is attached to one or more virtual services. This rate limit profile association is made through the CLI or API. The following CLI syntax shows how to modify the profile:

configure applicationprofile <application_profile_name>
dos_rl_profile
rl_profile
custom_requests_rate_limit
count <max_number_of_requests_allowed>
period <time_period_during_which_those_requests_should_be_allowed>
-- Rate limiter allows requests as long as count is not exceeded within period seconds
action type <action_type>
-- Default for action_type is avi.RL_ACTION_CLOSE_CONN
save
-- Repeat until you exit the application profile 

To configure the rate limit profile on the UI:

  1. On the Controller, navigate to Templates.

  2. Under the Application tab, select and edit your application profile (or create a new one).

  3. Select the DDoS tab.

  4. Under Add Rate Limit, select Rate Limit all HTTP requests that map to any custom string to all URLs of the virtual service.

  5. Enter the values for Threshold and Time Period. For this particular use-case select Action as Send HTTP Local Response and Status Code as 429. You do not need to upload a file.

  6. Click Save.

Basic rate limiting

Example 1

  • Rate limit clients based upon a unique ID, in this case an HTTP header value

  • The number of requests per poeriod of time are defined within the rate limit profile

avi.vs.rate_limit(avi.RL_CUSTOM_STRING, avi.http.get_header("userID"))

Rate limiting with a penalty timer

  • Extend the logic of rate limiting by adding a penalty box

  • Normally rate limit only allows X number of connections within

  • Y period of time. With the penalty box, when a user exceeds the limit,

  • They may not send any requests until the penalty timer expires.

userID = avi.http.get_header("userID")
penalty_time = 900
-- Check if the userID has been added to the table of blocked users
-- The table is used to create a "penalty box" of 900 seconds
-- If user is not in the list then given_action variable is nil
given_action, remaining_time = avi.vs.table_lookup(userID, 0)
if given_action then
   avi.http.close_conn()
else
-- if userID is not in the penalty box table
  count_exceeded, given_action = avi.vs.rate_limit(avi.RL_CUSTOM_STRING, userID, true)
  if count_exceeded then
-- user just crossed the threshold and is now added to the penalty box table
     avi.vs.table_insert(userID, given_action, penalty_time)
-- Since the optional defer_action flag from avi.vs.rate_limit() is set to true
-- The rate limit profile is not enforcing the limit, so it is enforced below
     avi.http.close_conn()
   end
 end

avi.vs.rate.limit.exceed

Starting with Avi Load Balancer release 18.2.9, the existing rate limit DataScript API – avi.vs.rate_limit. is deprecated. The new DataScript API for the rate limit is avi.vs.ratelimit.exceed.

Deprecated DataScript API – avi.vs.rate_limit( type, string_to_limit, [defer_action=False] )

New DataScript API –avi.vs.ratelimit.exceed(rl_name, request_key, [consume])

The following are the parameters used in new DataScript rate limiter:

Function

avi.vs.ratelimit.exceed( (rl_name, request_key, [consume]) )

Description

Rate limits entities of various kinds.

Events

HTTP_REQ

Parameter

  • rl_name refers to the rate limit object. It should match the name of one of the Rate Limit Objects supplied in the meta-data.

  • request_key is an arbitrary string constructed by the DataScript code. For example, concatenation of header values or other properties. A separate bucket with the rate specified in the request rule meta-data will be set aside for all calls specifying the same request_key. This allows any property or combination of properties to be used to identify requests.

  • consume is the number that this API will consume the rate limiter bucket, default value is 1. The return value is a Boolean indicating whether the rate limit was hit. The function itself does not apply any action; it just indicates whether the user is above the threshold. It's up to the DataScript to take actions based on this information.

Returns

The function returns two variables:

  • rl_exceeds is true when the rate limiter exceeds the configured value.

  • rl_does_not_exceed is true when the rate limiter does not exceed the configured value.

The action can be configured as per the requirement. In the following configuration section, the action is chosen to log the event in the virtual service logs.

Note:

This API is not supported in the events SSL_PRECONNECT, SSL_CLIENTHELLO, and SSL_HANDSHAKE_DONE.

Additional Configuration

DataScript must be configured to reference a rate limit profile, which is nested within a HTTP application profile, which is attached to one or more virtual services. This rate limit profile association is made through the CLI or API. The following CLI syntax shows how to modify the profile:

Configuring DataScript Rate Limiter

Login to the CLI and use configure vsdatascriptset <policy name> command to configure rate limiters. Provide the policy name and assign the desired value of the rate limiters (count, period, and burst size) as shown below:

[admin]: > configure vsdatascriptset rate_limiter_test

[admin]: vsdatascriptset> rate_limiters

[admin]: vsdatascriptset:rate_limiters> count 1

[admin]: vsdatascriptset:rate_limiters> period 15

[admin]: vsdatascriptset:rate_limiters> burst_sz 0

[admin]: vsdatascriptset:rate_limiters> name rl1

[admin]: vsdatascriptset:rate_limiters> save

[admin]: vsdatascriptset> save

Use the avi.vs.ratelimit.exceed function in a DataScript with the desired action. For example:

 result = avi.vs.ratelimit.exceed("rl1", "key1")
 if result == true then
 avi.vs.log("rl exceeds")
 else
 avi.vs.log("rl does not exceed")
 end

avi.vs.reqvar

Function

avi.vs.reqvar.*

Description

Sets (write) or gets (read) a variable. These variables have scope across the HTTP_REQ and HTTP_RESP events. Their lifetime is limited to that of the HTTP request/response transaction, so it does not need to be manually unset. Any Lua value can be stored within this variable. For variable data that is only required during the current event, map the variable to the data.

var = 1
if var == 1 then ...

For variable data that needs to be saved across connections or mirrored to other Service Engines for the virtual service use avi.vs.table_insert()

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

None

Returns

Boolean true upon refresh success and false upon refresh failure.

HTTP Request Example

HTTP_REQ Event:

avi.vs.reqvar.foo = 10

HTTP_RESP Event:

if avi.vs.reqvar.foo == 10 then
   avi.vs.log("Foo=" .. avi.vs.reqvar.foo)
end

avi.vs.table_insert

Function

avi.vs.table_lookup( [table_name,] key [, lifetime_exten] )

Description

The table API is used to store and retrieve custom data. The avi.vs.table_lookup API looks up a key and return the corresponding value. This key-value store is unique per Virtual Service and is mirrored across all Service Engines hosting the VS.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

If the optional table_name is not specified, the key is looked up in the default table for the VS. When it is specified, a custom table will be searched.

The key is used to look up the value.

The optional lifetime_exten flag must be a positive integer, indicating the length of time, in seconds, that should be added to the current lifetime parameter for the key. When not specified, the default value of 300 seconds is used. This means that by default, looking up the value of a key will extend the lifetime of a key by an additional 300 seconds. To lookup the key without impacting the expiration, set the lifetime_exten flag to 0.

Returns

Returns the value field of the key. If no value exists or the key does not exist, returns nil.The remaining lifetime, a non-negative integer representing the remaining lifetime of the entry in seconds.

HTTP Request Example

This use case can also be performed through the native App-Cookie persistence mode:

if avi.http.get_cookie("OAM_JSESSIONID") then
    if avi.vs.table_lookup(avi.http.get_cookie("OAM_JSESSIONID")) then
        avi.pool.select(avi.vs.table_lookup(avi.http.get_cookie("JSESSIONID")))
     end                                                                        
 end

HTTP Response Example

if avi.http.get_cookie("JSESSIONID") ~= "" then
   avi.vs.table_insert(avi.http.get_cookie("JSESSIONID"), avi.pool.server_ip(), 3600)                                                                        
  end

avi.vs.table_lookup

Function

avi.vs.table_lookup( [table_name,] key [, lifetime_exten] )

Description

The table API is used to store and retrieve custom data. The avi.vs.table_lookup API looks up a key and return the corresponding value. This key-value store is unique per Virtual Service and is mirrored across all Service Engines hosting the VS.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

If the optional table_name is not specified, the key is looked up in the default table for the VS. When it is specified, a custom table will be searched.

The key is used to look up the value.

The optional lifetime_exten flag must be a positive integer, indicating the length of time, in seconds, that should be added to the current lifetime parameter for the key. When not specified, the default value of 300 seconds is used. This means that by default, looking up the value of a key will extend the lifetime of a key by an additional 300 seconds. To lookup the key without impacting the expiration, set the lifetime_exten flag to 0.

Returns

Returns the value field of the key. If no value exists or the key does not exist, returns nil.The remaining lifetime, a non-negative integer representing the remaining lifetime of the entry in seconds.

HTTP Request Example

This use case can also be performed via the native App-Cookie persistence mode:

if avi.http.get_cookie("OAM_JSESSIONID") then
    if avi.vs.table_lookup(avi.http.get_cookie("OAM_JSESSIONID")) then
        avi.pool.select(avi.vs.table_lookup(avi.http.get_cookie("JSESSIONID")))
     end                                                                        
 end

HTTP Response Example

if avi.http.get_cookie("JSESSIONID") ~= "" then
   avi.vs.table_insert(avi.http.get_cookie("JSESSIONID"), avi.pool.server_ip(), 3600)                                                                        
  end

avi.vs.table_refresh

Function

avi.vs.table_refresh( [table_name,] key [, lifetime_exten] )

Description

Refreshes the lifetime of the entry for the key in the key/value store.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

Looks up the key in the default VS table, unless another table name is specified through the optional table_name.

  • The key is used to search for the desired table entry.

  • The optional lifetime_exten, a positive integer, is the value in seconds by which to extend the lifetime of the entry in the key/value store. When it is not specified, the default value of 300 seconds is used to extend the lifetime of the entry.

Returns

Boolean true upon refresh success and false upon refresh failure.

Note

The key/value entry will be removed from all Service Engines hosting the VS.

Example

TBD

avi.vs.table_remove

Function

avi.vs.table_remove( [table_name,] key )

Description

The table API is used to store and retrieve custom data. The avi.vs.table_remove API removes a specified key/value pair from the data store for the specified key.

Events

  • HTTP_REQ

  • HTTP_RESP

Parameter

If the optional table_name is not specified, the key is looked up in the default table for the VS. When it is specified, a custom table will be searched.

The key is used to search for the table entry to be deleted.

Returns

None

Note

The key/value entry will be removed from all Service Engines hosting the VS.

Example

TBD

avi.vs.get_open_conns

Function

avi.vs.get_open_conns()

Description

Returns the total number of open connections for the virtual service on the SE on which the request was received

Events

All events

Parameter

None

Returns

The total number of open connections

Example

The following data script example will provide the SE count and open connections:

local se_count = avi.vs.se_count() 
local open_conn = avi.vs.get_open_conns() 
avi.vs.log("Open conns: " .. open_conn .. " for Total SE: " .. se_count)

avi.vs.se_count

Function

avi.vs.get_se_count()

Description

Returns the total number of service engines attached to the current virtual service

Events

All events

Parameter

None

Returns

The total number of SEs for the respective virtual service

Example

The following data script example will print 1 , if there is only one SE present:

-- scale-out SE open connection limit
MAX_OPEN_CON=50
local se_count = avi.vs.se_count() 
local open_conn = avi.vs.get_open_conns() 
per_se_max = MAX_OPEN_CON/se_count --Dividing the MAX count per SE, assuming equal distribution.
if (open_conn > per_se_max) then
	avi.vs.log("Current open conns: " .. open_conn .. "> MAX_OPEN_CON=" .. MAX_OPEN_CON .. " for Total SE: " .. se_count)
	avi.http.response(404, {content_type="text/html"}, "<html> MAX_OPEN_CON=" .. MAX_OPEN_CON .. " exceeded, please try later! </html>\n")
else
	avi.vs.log("Open conns: " .. open_conn .. " for Total SE: " .. se_count)
end