Anypoint Monitoring Metrics API

(0 reviews)

home

Metrics API

The Metrics API enables you to access metrics that Anypoint Monitoring exposes. Use the Anypoint Monitoring Query Language (AMQL) to construct flexible and secure queries to access metrics data.

Prerequisite

Generate a bearer token for Anypoint Platform. For guidance, see How to generate your Authorization Bearer token for Anypoint Platform.

Get the Shape of Data

To learn about available metrics, use the Describe endpoint to return a list of registered MetricDescriptors that provides the shape of data that's stored and available for queries.

The response will provide a JSON object containing:

  • metricName: The name of the metric.
  • dimensions: Attributes that can be used for filtering and grouping.
  • measurements: Numerical values that can be aggregated.

Access Your Data

After retrieving the shape of data stored in Anypoint Monitoring, construct a query for the Search endpoint.

Use AMQL in the Search endpoint to:

  • Define the data to query and the data structure of the response.
  • Define a set of aggregations for selection capabilities.
  • Define a set of filtering conditions to narrow your search scope.
  • Define grouping and sorting capabilities that allow you to either create a time series.
  • Define top N and pagination capabilities by setting limit and offset values.

Anypoint Monitoring Query Language (AMQL) Grammar for Search Endpoint

        SELECT aggregatedMeasure,[attributeList...]
            FROM MetricNameT
            WHERE timestamp between {startTimestamp} AND {endTimestamp}
            [AND conditionExpression]
            [GROUP BY {fieldGroupByList}]
            [ORDER BY timestamp {ASC|DESC}]
            [TIMESERIES [TimeDurationT]]
            [LIMIT numberOfRowsToReturn]
            [OFFSET numberOfRowsToSkip]


MetricNameT = "mulesoft.app.request|mulesoft.app.outbound.request|mulesoft.entity|.."
TimeDurationT = P1M|P{integer}D|PT{integer}H|PT{integer}M
[] = optional clauses
Supported Clauses

SELECT: Specifies the list of attributes to get with at least one aggregated measurement. Use the Describe endpoint to discover available attributes and measurements for a metric type. SELECT supports these aggregation functions:

Aggregation FunctionArguments
avg{measurementName}
sum{measurementName}
percentile{measurementName, percentage value in range (0;100)}
max{measurementName}
min{measurementName}
count{measurementName} or {attributeName}

FROM: Specifies the metric (namespace) to use for the query. Use the metric type list endpoint to get a list of all available metrics.

WHERE: Adds filter conditions to the query. Time-range and business group filters are required. Additional filters can be applied to attributes. These operators are allowed in the filter condition"

Filter FunctionOperator
equals=
notEqual!=
greater>
greaterOrEquals>=
less<
lessOrEquals<=
inin

GROUP BY: Groups the result-set by one or more attributes. All non-aggregated attributes in the SELECT clause must be included in GROUP BY clause.

ORDER BY: Allows time-based sorting on a result set in ascending or descending order.

TIMESERIES: Groups data in a supported times series:

  • PT1M - minutely
  • PT1H - hourly
  • P1D - daily

Example

Assume that a user wants to know error counts for their API for the last day.

To get that number, you first need to know what metrics are available in Anypoint Monitoring.

Make a call to a List Metric Types endpoint:

curl -X GET https://anypoint.mulesoft.com/observability/api/v1/metric_types
     -H "Content-Type: application/json"
     -H "Authentication: ${token}"

After you get the name of metric you want, get the shape of metric using the Describe endpoint:

curl -X GET https://anypoint.mulesoft.com/observability/api/v1/metric_types/mulesoft.api:describe
     -H "Content-Type: application/json"
     -H "Authentication: ${token}"

After getting all dimensions and measurements for the metric mulesoft.api,summary, you can make a query to fetch the total request count grouped by status codes for a specific api instance (See Obtain an API Instance ID) using Search endpoint:

curl -X POST https://anypoint.mulesoft.com/observability/api/v1/metrics:search?offset=0&limit=20
     -H "Content-Type: application/json"
     -H "Authentication: ${token}"
     -d '{"query":"SELECT COUNT(requests),  \"api.instance.id\", \"http.status_code_group\"
                   FROM \"mulesoft.api\"
                   WHERE \"sub_org.id\" = 'your-business-group-id' AND \"env.id\" = 'your-environment-id'
                   AND \"api.instance.id\" = 'your-api-instance-id'
                   AND timestamp BETWEEN 1740510840000 AND 1740514440000
                   GROUP BY \"http.status_code_group\""
         }'

The response will provide a JSON object containing requestVolume over selected time-range.

{
  "data": [
    {
      "COUNT(requests)": 1668,
      "api.instance.id": "your-api-instance-id",
      "status_code_group": "2xx"
    },
    {
      "COUNT(requests)": 24,
      "api.instance.id": "your-api-instance-id",
      "status_code_group": "4xx"
    }
  ]
}

Reviews