Was this Helpful?

 Statistics Collector policy

About | Samples | Element reference | Error codes | Schema | Related topics

What

Enables you to collect statistical data for messages processed in a flow, such as product ID, price, REST action, client and target URL, and message length (predefined flow variables as well as custom variables). The data is then provided to the analytics server, which analyzes the statistics and generates reports. You can view the reports through Analytics Services.

Where

This policy can be attached in the following locations.

ProxyEndpoint TargetEndpoint
    PreFlow Flow PostFlow PreFlow Flow PostFlow    
Request                
    Response
    PostFlow Flow PreFlow PostFlow Flow PreFlow    

You attach the StatisticsCollector Policy to the response path in your API proxy, where you can capture and publish a range of statistics to the analytics server.

Samples

You can set the defaultval as shown in the following example to initialize a variable with a static, default value. If you provide a default value, then the default value you provide will be assigned to the variable the variable only when the variable does not get initialized during the message flow. If you do not provide a defaultval, then the variable is assigned normally during the message flow and calls fail if the variable is not resolved.

<StatisticsCollector name="publishPurchaseDetails">
<Statistics>
<Statistic name="productID" ref="product.id" type="string">{defaultval}</Statistic>
<Statistic name="price" ref="product.price" type="string">{defaultval}</Statistic>
</Statistics>
</StatisticsCollector>


Element reference

The element reference describes the elements and attributes of the StatisticsCollector policy.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Statistics-Collector-1">
    <DisplayName>Statistics Collector 1</DisplayName>
    <Statistics>
        <Statistic name="name" ref="" type="STRING">value</Statistic>
    </Statistics>
</StatisticsCollector>

<StatisticsCollector> attributes

<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Stats-1">
Attribute Description Default Presence
async

Set to true to specify that the policy should be run in a thread pool different from the pool servicing the request/response flow.

Note: This setting is only used for for internal optimization. Contact Apigee Support via the Support Portal for more information.

false Optional
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies. For example, when a quota is exceeded, an error will be raised.

Set to true to have flow execution continue even after a policy fails.

false Optional
enabled

Set to true to enforce the policy.

Set to false to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
name

The internal name of the policy. Characters you can use in the name are restricted to: A-Z0-9._\-$ %. However, the Edge management UI enforces additional restrictions, such as automatically removing characters that are not alphanumeric.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-lanaguage name.

N/A Required

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-lanaguage name.

<DisplayName>My Stats Collector</DisplayName>
Default: N/A
Presence: Optional
Type: String

<Statistics>/<Statistic> element

<Statistics>
    <Statistic name="name" ref="" type="STRING">value</Statistic>
</Statistics>
Attribute Description Default Presence
name

Custom name provided for the referenced variable. The name cannot contain spaces or dashes. In the example below, the referenced variable is product.id.

The following restrictions apply:

N/A Required
ref

Flow variable that can be a predefined variable or a variable defined in the XML payload of the Extract Variables policy. See Extract message content using ExtractVariables.

N/A Optional
type

Valid values: string/integer/float/long/boolean/double

If provided, overrides the existing datatype of ref. Note that the type can be left empty only if ref is a predefined variable or the type is declared in the XML payload of the Extract Variables policy.

N/A Optional

Error codes

The default format for error codes returned by Policies is:

{
  "code" : " {ErrorCode} ",
  "message" : " {Error message} ",
  "contexts" : [ ]
}

The StatisticsCollector Policy type defines the following error codes:

Error Code Message
DatatypeMissing StatisticsCollection {0}: Datatype of {1} is missing. Context {2}
UnsupportedDatatype StatisticsCollection {0}: Datatype {1} is unsupported . Context {2}

Schema

Each policy type is defined by an XML schema (.xsd). For reference, policy schemas are available on GitHub.

Related topics

For more information on how to analyze your data using Apigee analytics, see Analyze API message content using custom analytics.

 

Help or comments?

  • Something's not working: See Apigee Support
  • Something's wrong with the docs: Click Send Feedback in the lower right.
    (Incorrect? Unclear? Broken link? Typo?)