Publishing Custom Metrics Using the API

Publish custom metrics to the Monitoring service.

Tip

Agent configurations are another way to publish custom metrics to Monitoring. With agent configurations, the API isn't necessarily required to publish custom metrics. You can now use agent configurations to ingest metric data into custom metrics. For example, expose metrics from a virtual machine (VM) using an HTTP endpoint in Prometheus format.

A custom metric is a metric that you design to collect and analyze data.

For example, create a productOrder metric (in a metric namespace, mymetricsnamespace) to track product orders by country and division, with additional metadata for product categories and notes.

Before You Begin

IAM policies: To publish custom metrics, you must be given the required type of access in a policy  written by an administrator. This requirement applies whether you're using the REST API with an SDK, CLI, or other tool. If you get a message that you don't have permission or are unauthorized, check with the administrator. You might not have the required type of access in the current compartment .

Administrators: For an example policy, see Publish Custom Metrics (Securing Monitoring).

Considerations

When defining custom metrics, note the following:

  • For the metric namespace, don't use a reserved prefix (oci_ or oracle_).
  • Ensure that custom metrics don't exceed limits. For example, note the valid range of dimensions and maximum number of streams for custom metrics. See PostMetricData.
  • Define metrics with aggregation in mind. While custom metrics can be posted as frequently as every second (minimum frequency of one second), the minimum aggregation interval is one minute.
  • Define metrics with return limits in mind. Limits information for returned data includes the 100,000 data point maximum and time range maximums (determined by resolution, which relates to interval). See MetricData. See also Limits on Monitoring.
  • Ensure that timestamp values are near current time. For a data point to be posted, its timestamp must be near current time (less than two hours in the past and less than 10 minutes in the future). See PostMetricData.
  • After publishing custom metrics, you can access them the same way you access any other metrics stored by the Monitoring service: View charts in the Console, query metrics using the CLI or API, and create alarms.
  • When retrieving custom metrics, you can match to a resource group. Blank (null) for resource group returns metric data that doesn't have a resource group.