StatisticsCollector ポリシー

概要

プロダクト ID、料金、REST アクション、クライアントとターゲットの URL、メッセージ長など、メッセージに含まれているデータの統計情報を収集できます。データは、Apigee で定義されているフロー変数や、ユーザーが定義したカスタム変数から取得できます。

統計情報のデータは分析サーバーに渡され、分析とレポートの生成が行われます。生成されたレポートは、Edge 管理 UI または Edge API で表示できます。

サンプル

基本的な例

<StatisticsCollector name="publishPurchaseDetails">
  <Statistics>
    <Statistic name="productID" ref="product.id" type="string">999999</Statistic>
    <Statistic name="price" ref="product.price" type="string">0</Statistic>
  </Statistics>
</StatisticsCollector>

この例では、product.idproduct.price という 2 つのカスタム変数に関する統計情報を収集します。リクエストごとに、Statistics Collector ポリシーがこの 2 つの変数の値を分析サーバーに書き込みます。

この例では、各変数のオプションのデフォルト値も設定します。ここで、product.id のデフォルト値は 999999、デフォルトの product.price は 0 です。変数が未定義で、デフォルト値を指定していない場合、データは変数に記録されません。変数が未定義で、デフォルト値を指定した場合、デフォルト値が記録されます。

統計情報データを収集したら、Edge 管理 UI または API を使用して統計を取得できます。統計情報を取得するときは、これらの変数について収集されたデータをそれぞれ productIDprice として参照します。

統計にアクセスする

この例では、Edge Management API を使用して、productID というコレクションの統計情報データを表示します。このリクエストでは、各日の各プロダクト ID に対する送信メッセージ件数の合計に基づくプロダクト ID のカスタム レポートを作成します。変数 {org_name} を組織名に置き換え、Apigee Edge のアカウントのメールアドレスとパスワードを email:password に置き換えます。

timeRange パラメータを設定して、データが収集される時間間隔を含めます。デフォルトでは、現在の日付から 6 か月以上経過しているデータはアクセスできません。6 か月以上前のデータにアクセスするには、Apigee のサポートにお問い合わせください。

$ curl https://api.enterprise.apigee.com/v1/o/{org_name}/environments/test/stats/productID?"select=sum(message_count)&timeRange=1/19/2015%2000:00~6/21/2015%2000:00&timeUnit=day"
-u email:password

レスポンスの name フィールドにはプロダクト ID が含まれ、値は各日のリクエスト数を示します。

{
  "environments" : [ {
    "dimensions" : [ {
      "metrics" : [ {
        "name" : "sum(message_count)",
        "values" : [ {
          "timestamp" : 1353369600000,
          "value" : "4.0"
        } ]
      } ],
      "name" : "52"
    }, {
      "metrics" : [ {
        "name" : "sum(message_count)",
        "values" : [ {
          "timestamp" : 1353369600000,
          "value" : "19.0"
        } ]
      } ],
      "name" : "14"
    }, ...
  } ],
  "metaData" : {
    "samplingRate" : "100"
  }
}

収集するデータを抽出する

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="GetWeatherData">
    <VariablePrefix>weather</VariablePrefix>
    <XMLPayload>
       <Namespaces>
          <Namespace prefix="yweather">http://xml.weather.yahoo.com/ns/rss/1.0</Namespace>
       </Namespaces>
       <Variable name="location" type="string">
          <XPath>/rss/channel/yweather:location/@city</XPath>
       </Variable>
       <Variable name="condition" type="string">
          <XPath>/rss/channel/item/yweather:condition/@text</XPath>
       </Variable>
    </XMLPayload>
</ExtractVariables>

Statistics Collector ポリシーでは、収集したデータを変数に保存する必要があります。 データは、Apigee が事前に定義したフロー変数か、ユーザーのカスタム変数に保存されます。

この例では、Extract Variables ポリシーを使用して、気象情報を含む XML ペイロードからデータを抽出します。このポリシーでは次のことを行います。

  • 都市の名前を抽出し、weather.location という名前の変数に書き込みます。
  • 現在の条件を抽出し、weather.condition という名前の変数に書き込みます。

次のように Statistics Collector ポリシーを使用して、変数に関する情報を収集します。

<StatisticsCollector name="publishPurchaseDetails">
  <Statistics>
    <Statistic name="weatherLocation" ref="weather.location" type="string"></Statistic>
    <Statistic name="weatherCondition" ref="weather.condition" type="string"></Statistic>
  </Statistics>
</StatisticsCollector>

統計コレクション ポリシーの XML ペイロードからデータを抽出する完全なチュートリアルについては、カスタム分析を使用して API メッセージ コンテンツを分析するをご覧ください。


Statistics Collector ポリシーについて

Statistics Collector ポリシーを実行すると、1 つ以上の変数の現在値が記録されます。Apigee が事前に定義したフロー変数またはユーザーのカスタム変数のデータが記録されます。このデータは、Edge 分析サーバーに書き込まれます。

ポリシーで収集された統計情報にアクセスするには、Edge API または Edge 管理 UI を使用します。たとえば、Edge 管理 UI を使用すると、カスタム レポートを作成し、収集されたデータをさまざまな形式で表示できます。

Statistics Collector ポリシーの使用方法のについての詳しいチュートリアルは、カスタム分析を使用して API メッセージ コンテンツを分析するをご覧ください。

ポリシーの配置場所

Statistics Collector ポリシーは、API プロキシのリクエスト フローまたはレスポンス フローで使用できます。ただし、複数の Statistics Collector ポリシーをプロキシに組み込むと、最後に実行された Statistics Collector ポリシーによって、Analytics サーバーに書き込まれるデータが決定され、それより前の Statistics Collector ポリシーによって書き込まれたデータは失われます。

1 つの API プロキシで複数の Statistics Collector ポリシーを使用するシナリオの 1 つとして、リクエスト フローまたはレスポンス フローに 1 つのポリシーを適用し、障害ハンドラに別のポリシーを適用する場合があります。API プロキシで障害が発生した場合は、障害ハンドラの Statistics Collector によって、収集されるデータが決定されます。この Statistics Collector は障害に関する情報の記録に使用します。あるいは、他に必要と思われる情報の記録に使用します。リクエスト / レスポンスの Statistics Collector が実行済みかどうかに関係なく、障害ハンドラの Statistics Collector により、収集されるデータが決まります。

詳細については、障害の処理をご覧ください。

要素リファレンス

この要素リファレンスでは、Statistics Collector ポリシーの要素と属性について説明します。

<?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="statName" ref="varName" type="refDataType">defaultStatValue</Statistic>
    </Statistics>
</StatisticsCollector>

<StatisticsCollector> 属性

<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Stats-1">

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

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

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

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
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

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

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<Statistics>/<Statistic> 要素

<Statistics>
    <Statistic name="statName" ref="varName" type="refDataType">defaultStatValue</Statistic>
</Statistics>
属性 説明 デフォルト 要否
name

特定の変数に収集されたデータの参照に使用する名前。分析データを表示するときは、この名前を使用して、ref 属性で指定された変数について収集されたデータを参照します。

ref で指定された変数がリクエストまたはレスポンスで定義されていない場合、defaultStatValue は変数に対して収集された値を指定します。デフォルト値を省略し、変数が未定義の場合、この変数にデータは収集されません。

命名規則

カスタム分析の変数には次の命名規則が適用されます。

なし 必須
ref

統計情報を収集するフロー変数。この変数は、Apigee が事前に定義したフロー変数か、ユーザーが API プロキシに定義したカスタム変数になります。

通常、ref 属性は、Extract Variables ポリシーで定義されたカスタム変数を参照します。詳細については、Extract Variables ポリシーをご覧ください。

なし 必須
type

ref 属性で指定された変数のデータ型を指定します。有効な値は、string / integer / float / long / double / boolean です。

string データ型の場合は、カスタム レポートで統計データをディメンションとして参照します。データ型が数値(integer / float / long / double)の場合、カスタム レポートの統計データはディメンションまたは指標として参照されます。詳細については、カスタム レポートの管理をご覧ください。

ref が事前定義の Apigee フロー変数を参照しているか、Extract Variables ポリシーの XML ペイロードで宣言されたデータ型を参照している場合、type の値は省略できます。

文字列 省略可

エラー リファレンス

This section describes the error messages and flow variables that are set when this policy triggers an error. This information is important to know if you are developing fault rules for a proxy. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

None.

Deployment errors

Error name Cause Fix
UnsupportedDatatype If the type of the variable specified by the ref attribute in the <Statistic> element of the Statistics Collector policy is unsupported, then the deployment of the API proxy fails. The supported data types are string, integer, float, long, double, and boolean.
InvalidName If the name used to reference the data collected for the specified variable defined within the <Statistic> element of the Statistics Collector policy conflicts with a system-defined variable, then the deployment of the API proxy fails. Some of the known system-defined variables are organization and environment.
DatatypeMissing If the type of the variable specified by the ref attribute in the <Statistic> element of the Statistics Collector policy is missing, then the deployment of the API proxy fails.

Fault variables

None.

スキーマ

各ポリシータイプは XML スキーマ(.xsd)によって定義されます。参照用のポリシー スキーマは GitHub から入手できます。

関連トピック

関連ページ