StatsD Integration

About StatsD Integration

This section is intended for app developers who are going to use the Altoros Heartbeat service to collect custom metrics from their apps. The section describes how to enable an app to send metrics to the StatsD server. These metrics are subsequently pushed to Graphite’s Carbon component for caching and persistence.

Integrate Heartbeat’s StatsD Into the App

  1. Download a language-specific StatsD client library from this Github page and add it into your app code.

  2. Follow the steps in Binding a Service Instance to the App to bind the Heartbeat service to your app.

  3. Parse environment variables in the code to get a StatsD endpoint. a. Parse environment variables of your app. b. Find the service called Heartbeat and retrieve the variables highlighted below: System-Provided: { "VCAP_SERVICES": { "heartbeat": [ { "credentials": { "host": "", <-- "jmxtrans_prefix": "jmxtrans.admin.demo.", "port": 8125, <-- "statsd_prefix": "apps.admin.demo." <-- }, "label": "heartbeat", "name": "heartbeat",

  4. Prepare a metrics prefix in the following format statsd_prefix + app_name + . + app_index, where:

  5. Configure the StatsD client library (e.g. set host, port, prefix). For an example, see this GitHub repository.

  6. Define custom metrics inside the app code (using the StatsD library). For an example, see this GitHub repository.

  7. Push the app to Pivotal Cloud Foundry (PCF).

  8. Create a custom dashboard in Grafana. For a sample dashboard, see this GitHub repository.

For an example of an app written in golang that sends custom metrics to a Grafana dashboard, see this GitHub repository.

Example of an App with StatsD Integration

  1. Navigate to cf marketplace.

    cf marketplace
        Getting services from marketplace in org admin / space demo as admin...
    service              plans                               description
    app-autoscaler       standard                            Scales bound applications in response to load (beta)

  2. Find Heartbeat in the list of the available services and select the service plan. Currently, only the standard service plan is available, so it is selected by default.

  3. Create a service instance.

    cf create-service heartbeat standard heartbeat

  4. Bind the service to your app.

    cf bind-service app_name heartbeat

  5. Restage the app to start the metrics flow.

    cf restage app_name

Create a Custom Dashboard

For information about creating and editing Grafana graphs and panels, see Grafana documentation. For an example of an app’s dashboard, see this Github repository.