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.

Integrating 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. To do this:

    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": "192.168.222.59", <--
         "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:

    statsd_prefix: statsd_prefix is described in the previous step.

    app_name: For information about the app’s name, see this documentation.

    app_index: For information about the app’s index, see this documentation.

    For an example, see this GitHub repository.

  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’s 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...
    OK
    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 standard is available—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.

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