Creating Custom Metrics
The Anypoint Custom Metrics connector enables you to send operational and business metric values that you define from an app to Anypoint Monitoring. You can then use the built-in Custom metrics dashboard and a custom dashboard in Advanced mode to visualize the custom metrics in real time.
Define metrics in the Anypoint Custom Metrics connector to select which metrics to display in the dashboard. You can filter and group the metrics along the dimensions you define to include multiple custom and built-in metrics in a single dashboard visualization.
The Custom Metrics connector is available for both Mule 3 and Mule 4 in the Monitoring > Custom Metrics page.
This connector is available only if your organization has the Anypoint Integration Advanced package or a Titanium subscription to Anypoint Platform. For more information, see the Pricing and Packaging documentation.
Prerequisites
Run your Mule app on a supported Mule runtime version. For supported versions, see Mule Runtime Release Notes.
You must also install the Anypoint Monitoring Agent.
Custom Metrics Best Practices
Best practices include using time period and frequency effectively as well as using data with low cardinality dimensions.
Use Time Period and Frequency Effectively
Each chart in the Custom Metrics dashboard represents the output of a query. Two parameters in the dashboard, time range and refresh frequency, affect the response time for the query that generates a chart.
- Time range
-
Determines how much data is fetched or processed to generate the chart. For example, more data is fetched and processed when displaying a monthly chart compared to displaying a daily chart.
- Refresh frequency
-
Determines how often a chart refreshes. High refresh frequencies put more stress on a system and can affect performance. For example, a refresh rate of one hour sends a query every hour, and a refresh rate of one minute sends the same query every minute.
Increasing time range (such as daily to monthly) or increasing refresh frequency (from one hour to one minute) affects the system response time. Reduce time range or reduce the refresh frequency to improve the chart response time.
Use Low Cardinality Dimensions
Most custom metric dimensions have less than 100 possible unique values, but some may have a thousand unique values, such as country_code
, state_code
, city_code
, and zip
. Do not add high cardinality data, or data with many unique values, to custom metrics. Some examples of high cardinality dimensions include customer_id
, user_id
, session_id
, order_id
, transaction_id
, email_address
, token_id
, product_id
, location_id
(latitude/longitude), ip_address
, and phone_number
. Charts configured for custom metrics with high cardinality dimensions can adversely affect the response time of dashboards. For best results, restrict dimensions to have only a few unique values.
If a particular custom metrics chart slows down and affects other charts in the system, you can:
-
Create a new custom metric without the offending high cardinality dimension
-
Replace a high cardinality dimension with a low cardinality dimension, such as:
-
category_id
instead ofproduct_id
-
country_code
instead oflocation_id
-
order_count
instead oforder_id
-
-
Avoid using UUIDs and timestamps when creating new custom metrics
-
Reduce the time range of the custom metric chart, for example, create a daily or weekly chart instead of a monthly or yearly chart
-
Reduce the refresh frequency, for example, refresh hourly instead of every minute.
Restricted Keywords
Due to internal database restrictions, you cannot use the following keywords to define dimensionName
or factName
while using the Anypoint Custom Metrics connector:
-
ALL
-
ALTER
-
ANALYZE
-
ANY
-
AS
-
ASC
-
BEGIN
-
BY
-
CREATE
-
CONTINUOUS
-
DATABASE
-
DATABASES
-
DEFAULT
-
DELETE
-
DESC
-
DESTINATIONS
-
DIAGNOSTICS
-
DISTINCT
-
DROP
-
DURATION
-
END
-
EVERY
-
EXPLAIN
-
FIELD
-
FOR
-
FROM
-
GRANT
-
GRANTS
-
GROUP
-
GROUPS
-
IN
-
INF
-
INSERT
-
INTO
-
KEY
-
KEYS
-
KILL
-
LIMIT
-
SHOW
-
MEASUREMENT
-
MEASUREMENTS
-
NAME
-
OFFSET
-
ON
-
ORDER
-
PASSWORD
-
POLICY
-
POLICIES
-
PRIVILEGES
-
QUERIES
-
QUERY
-
READ
-
REPLICATION
-
RESAMPLE
-
RETENTION
-
REVOKE
-
SELECT
-
SERIES
-
SET
-
SHARD
-
SHARDS
-
SLIMIT
-
SOFFSET
-
STATS
-
SUBSCRIPTION
-
SUBSCRIPTIONS
-
TAG
-
TO
-
USER
-
USERS
-
VALUES
-
WHERE
-
WITH
-
WRITE
-
TIME
Use Design Center to Configure the Custom Metrics Values
Create a Mule application project in Design Center and configure the Custom Metrics connector.
-
In Design Center, create a new Mule application project.
The project opens in Design Center. -
Select the trigger for your flow, and click Next.
-
For Target, select Anypoint Custom Metrics Connector, and click Done.
The connector has one operation called Send Custom Metric.
-
On the design canvas, open the Anypoint Custom Metrics Connector card to add your metrics.
-
In Metric Name, enter a meaningful value.
-
Next to Dimensions, click Add to enter the name and value for the metric’s dimension.
-
In the Add Item dialog box, enter the Dimension Name and Value for the dimension.
-
Leave the Collapsible option with the default of True.
-
Click OK.
You can repeat these steps to add multiple key values.
-
-
Next to Facts, click Add to add facts for the metric. Values for measurements are always numerical.
-
In the Add Item dialog box, enter a Fact Name and numerical Value for the fact.
For facts, the value must always be numerical. This is not validated at design time, but a non-numerical value will cause a runtime exception once deployed. -
Click OK.
You can repeat these steps to add multiple key values.
-
-
Select the Throw Runtime Exception on Validation Failure option if you want the flow to break if invalid values are entered for the metric. If this option is left unchecked, an error will be logged, but the flow won’t break.
Custom Metrics Connector requires all Facts to be sent from every operation, even if they contain empty or 0 value in them.
Configure Custom Metrics Values Using Anypoint Studio
-
Search Anypoint Exchange for the Anypoint Custom Metrics connector.
-
Drag the Send Custom Metric operation to the canvas.
-
Add the Send Custom Metric operation to your application flow.
This image shows an example flow for custom metrics in Anypoint Studio. -
Click the Send Custom Metric operation to add values for the operation.
-
Add the dimension for the metric:
-
In Metric name, enter a meaningful value, for example "sales."
-
In Enter contextual information select Edit inline to enter the name and value for the dimension.
-
Click the green plus on the left to enter the values.
-
In the Dimension dialog box, enter the Name and Value for the dimension.
-
Leave the Collapsible option with the default of True.
-
Click Finish.
You can repeat these steps to add multiple key values.
-
-
Enter the facts for the metric. Values for measurements are numerical.
-
In Enter measurements select Edit inline to enter the name and value for the metric.
-
In the Fact dialog box, enter a Name and numerical Value for the fact.
For facts, the value must always be numerical. This is not validated at design time, but a non-numerical value will cause a runtime exception once deployed. -
Leave the Collapsible option with the default of True.
-
Click Finish.
You can repeat these steps to add multiple key values.This image shows example values for a custom metric that tracks t-shirt sales.
-
-
Select the Throw runtime exception on validation failure option if you want the flow to break if invalid values are entered for the metric. If this option is left unchecked, an error is will be logged, but the flow won’t break.
Deploy the Application
-
Deploy the app.
-
In Anypoint Monitoring, add a new custom dashboard for the custom metric.
This image shows an example of the configuration for a graph to display t-shirt sales.You only see the custom metrics in the pre-populated metric selection drop-down lists once something is logged for the custom metric.
Use the Custom Metrics Dashboard
Custom metrics are not collected for the app until you configure the Custom Metrics Connector in your application flow and deploy the application to a server or server cluster.
-
In Anypoint Monitoring, select the application to view metrics for, and click View.
-
Click the Custom metrics tab.
If the Custom Metrics connector has collected one or more metrics in the specified time range, one chart per defined metric is displayed. -
Click Select a measurement for this chart to display the measurement for the chart.
-
Use the drop-down lists at the bottom of the chart to filter the data by:
-
Aggregation - Possible aggregations include:
-
None (default) - No data aggregation.
-
count - Displays the total number of items collected for the measurement.
-
distinct - Returns the unique values for the given measurement.
-
integral - Returns the area under the curve for subsequent values.
-
mean - Returns the arithmetic average of the specified measurement over a given interval of time.
-
median - Displays the middle value for the collected metrics.
-
mode - Displays the most frequent value in the metrics collected for the defined measurement.
-
sum - Displays the sum of all the values for the defined measurement.
-
-
Measurement - The choices in this list are determined by the measurement values you define in the Custom Metrics connector.
-
Group by - The choices in this list are determined by the values you define in the Custom Metrics connector.
-