Registering Custom App Metrics

This topic describes how to install the Metric Registrar CLI plugin and emit custom app metrics to the Metric Registrar by registering your app as a metric source.

Registering your app as a metric source allows you to see your custom metrics in PCF Metrics and configure autoscaling rules with PCF Autoscaler. For more information about these products, see the PCF Metrics and PCF Autoscaler documentation.

Install the Plugin

Install the Metric Registrar CLI plugin by running the following command:

cf install-plugin -r CF-Community "metric-registrar"

Register Your App

To register your app as a metric source, do one of the following:

  • Register a public endpoint for custom metrics to be parsed and emitted to the Loggregator.
  • Register a structured log format that can be emitted to Loggregator.

Register a Public Metrics Endpoint

The Metric Registrar supports custom metrics created with the open-source tool Prometheus. Prometheus uses a response format common in many open-source libraries. It also provides several out-of-the-box metrics. For more information about Prometheus, see prometheus.io.

For examples of apps that use Prometheus to publish metrics to an endpoint, see the metric-registrar-examples repository.

Note: These endpoints must be public for the Metric Registrar to retrieve the data. If you do not want to expose public endpoints for your app, see Register a Structured Log Format below.

For each Prometheus endpoint in your app, run the following command to register the endpoint as a metric source:

 cf register-metrics-endpoint APP-NAME PATH

Register a Structured Log Format

The Metric Registrar supports metrics emitted in JSON or DogStatsD formats. For more information about these formats, see the JSON and DogStatsD sections below.

Run the following command to register your app as a metric source:

cf register-log-format APPNAME FORMAT

Where FORMAT is either json or DogStatsD.

JSON

The table below shows the supported JSON format for event, gauge, and counter log types.

Type Format
Events
{
  "type": "event",
  "title": "title",
  "body": "body",
  "tags": {
    "tag1": "tag value"
  }
}
Gauges
{
  "type": "gauge",
  "name": "some-counter",
  "value": ,
  "tags": {
    "tag1": "tag value"
  }
}
Counters
{
  "type": "counter",
  "name": "some-counter",
  "delta": ,
  "tags": {
    "tag1": "tag value"
  }
}

DogStatsD

The table below shows the supported DogStatsD format for event, gauge, and counter log types. It also lists the supported fields. For more information about DogStatsD, see the DogStatsD topic in the Datadog documentation.

Type Format Supported Fields
Events
_e{title.length,text.length}:title|text|d:timestamp|
h:hostname|p:priority|t:alert_type|#tag1,tag2
title
text
Gauges
gauge.name:value|g|@sample_rate|#tag1:value,tag2
gauge.name
value
Counters
counter.name:value|c|@sample_rate|#tag1:value,tag2
counter.name
value
Create a pull request or raise an issue on the source for this page in GitHub