LATEST VERSION: 1.11 - CHANGELOG
Metrics Forwarder for PCF v1.11

Emitting Metrics to Metrics Forwarder for PCF

This topic describes how to emit custom app metrics to Metrics Forwarder for Pivotal Cloud Foundry (PCF).

Accessing the Endpoint and Credentials

To use Metrics Forwarder for PCF, you must know its endpoint and credentials. You can find this information in the environment variables of a bound app.

Apps running on Cloud Foundry access their bound service instances using the VCAP_SERVICES environment variable. See the following example:

$ cf env my-app 
Getting env variables for app my-app in org my-org / space my-space as user@example.com... OK System-Provided: { "VCAP_SERVICES": { "metrics-forwarder": [ { "credentials": { "access_key": "YOUR-ACCESS-KEY", "endpoint": "https://METRICS-FORWARDER-DOMAIN/v1/metrics" }, "label": "metrics-forwarder", "name": "test-metrics-forwarder", "plan": "unlimited", "provider": null, "syslog_drain_url": null, "tags": [], "volume_mounts": [] } ] } }

In the example above, note the following properties:

  • access_key is the authentication token used in the Authorization header of the POST request to the Metrics Forwarder API.
  • endpoint is the URI for POST requests to the Metrics Forwarder API.

You can search for your service by its name, which is the name you provided when creating the service instance, or dynamically through the tags or label properties. Similar to other PCF services, the VCAP_SERVICES environment variable for an app is modified only when the app is bound to a service instance.

Emitting Metrics

Metrics Forwarder accepts metrics emitted to its HTTP API using the POST method. See the following example:

{
    "applications": [
    {
        "id": "YOUR-APP-ID",
        "instances": [
        {
            "id": "YOUR-INSTANCE-ID",
            "index": "0",
            "metrics": [
            {
                "name": "a-metric",
                "type": "counter",
                "value": 0,
                "timestamp": 1094817600000,
                "unit": "number",
                "tags": { "a-tag": "a", "b-tag": "b" }
            }]
        }]
    }]
}

For each request to the Metrics Forwarder API, you receive information about your rate limits in the response of the request.

Frameworks and Libraries

Frameworks and libraries help to control the frequency of metric emission, error handling, aggregation, and general API use.

Spring Boot Actuators

You can use Spring Boot Actuators to emit metrics to the Metrics Forwarder API. To do this, perform the following steps:

  1. Configure your app to use Spring Boot Actuators.
  2. Create the Metrics Forwarder for PCF service.
  3. Bind your app to the Metrics Forwarder for PCF service.
  4. Push or restage your app using the Java buildpack v4.2 or later.

Go

You can use a Go library to export metrics to Metrics Forwarder for PCF. To do this, perform the following steps:

  1. Configure your app to use the go-metrics exporter.
  2. Create the Metrics Forwarder for PCF service.
  3. Bind your app to the Metrics Forwarder for PCF service.
  4. Push or restage your app using the Go buildpack.

SSL Certificates

The Metrics Forwarder API endpoint uses the SSL certificate configured on the Gorouter. If this certificate is a self-signed certificate, you must configure all apps and tools emitting metrics to the Metrics Forwarder API to trust the self-signed certificates.

Create a pull request or raise an issue on the source for this page in GitHub