# Heroku

**Contents**:

* [Installing the Hosted Graphite Heroku Add-On](#installing-the-hosted-graphite-heroku-add-on)
  * [Heroku Auto-Dashboard](#heroku-auto-dashboard)
  * [Heroku Add-On Metrics](#heroku-add-on-metrics)
    * [Local Development Configuration](#local-development-configuration)
    * [Accessing the API Key Within Your App](#accessing-the-api-key-within-your-app)
  * [Custom Metrics](#custom-metrics)
  * [Router Path Metrics](#router-path-metrics)
  * [Router Aggregates](#router-aggregates)
    * [Path Aggregates](#path-aggregates)
    * [Process Aggregates](#process-aggregates)
    * [Host Aggregates](#host-aggregates)
  * [Heroku Event Annotations](#heroku-event-annotations)
* [Monitoring Heroku Metrics on an Existing HG Account](#monitoring-heroku-metrics-on-an-existing-hg-account)

{% embed url="<https://www.youtube.com/watch?t=13s&v=6NlGJXaB8D4>" %}
Heroku Video Tutorial
{% endembed %}

### [Installing the Hosted Graphite Heroku Add-On](#installing-the-hosted-graphite-heroku-add-on)

Hosted Graphite has a [Heroku Add-On](https://elements.heroku.com/addons/hostedgraphite)! Installing the add-on can be done through the UI of your Heroku account in the ‘Resources’ section, or by issuing the following command in your Heroku CLI:

> ```
> heroku addons:create hostedgraphite -a <app-name>
> ```

Make sure to replace the variable **\<app-name>** with the name of your application, as it appears in your Heroku account. Once the add-on is installed, a new application configuration key will be created, called `HOSTEDGRAPHITE_APIKEY`. Confirm the key by issuing this command:

> ```
> heroku config:get HOSTEDGRAPHITE_APIKEY -a <app-name>
> ```

You can now navigate to your new account by clicking on the Hosted Graphite add-on link in the Heroku UI, and wait for the metrics to appear.

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2Fjob3P9cB0CNkCWDVLjjz%2Fheroku-addon.png?alt=media&#x26;token=9434cbe1-b551-4fa3-b655-3bfa2e4efe17" alt=""><figcaption><p>Access your new HG account</p></figcaption></figure>

If you create a Hosted Graphite account via the Heroku Add-On, you do not need to configure any log drains. For more documentation around our Heroku Marketplace Add-On, please visit the [Hosted Graphite on Heroku](https://devcenter.heroku.com/articles/hostedgraphite) page.

### [Heroku Auto-Dashboard](#heroku-auto-dashboard)

This dashboard will be automatically created when you enable the Heroku Add-On, or configure Log-Drain metrics to your [existing Hosted Graphite account](#monitoring-heroku-metrics-on-an-existing-hg-account).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2F2QM4rvprYWaKb4RmuDSm%2Fheroku-dashboard-v4.png?alt=media&#x26;token=593a6913-f748-4487-a6b9-92821d38401a" alt=""><figcaption></figcaption></figure>

Using Heroku’s [Log Drain](https://devcenter.heroku.com/articles/log-drains) and [Log-Runtime](https://devcenter.heroku.com/articles/log-runtime-metrics) metrics we retrieve and process Heroku’s syslog information for your Dynos including:

* **CPU Load averages** - 1/5/15-minute averages
* **Memory and Swap** - Resident memory, disk cache, swap, total memory, and cumulative totals for pages written to/read from disk.
* **HTTP metrics** - The number of requests broken down by HTTP method and status codes, data transferred, and connect/service times.
* **Process metrics** - Memory stats from your [One-off process](https://devcenter.heroku.com/articles/process-model) as defined in your Procfile (scheduler, release, run, worker, etc).

**Troubleshooting**: If you are not receiving the web (dyno) metrics, you need to **enable log-runtime metrics** for your Heroku app. Log into your Heroku CLI and run the following commands:

```
heroku labs:enable log-runtime-metrics -a <app-name>
```

```
heroku restart -a <app-name>
```

### [Heroku Add-On Metrics](#heroku-add-on-metrics)

If you use the Heroku [Postgres add-on](https://elements.heroku.com/addons/heroku-postgresql) at the **standard** or **premium** tier, these metrics will automatically be forwarded to your Hosted Graphite account. They are prefixed with: **heroku.\<app-name>.heroku-postgres.\<instance-name>.\<type>** and report dyno statistics for cpu load, memory, db\_size, tables, active/waiting-connections, tmp-disk-available/used, read/write operations, and more!

We also have a handy Heroku Postgres dashboard that is available in our [Dashboard Library](https://docs.hostedgraphite.com/dashboard-and-graphs/dashboard-library).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2Fjv8CINBZ4WNCLrSoNz6o%2Fheroku-postgres-dashboard.png?alt=media&#x26;token=e0947022-fe5e-4865-af7c-399be073bd51" alt="" width="563"><figcaption><p>Heroku Postgres Dashboard</p></figcaption></figure>

If you use the Heroku [Redis add-on](https://devcenter.heroku.com/articles/heroku-redis) at **any** tier, these metrics will be automatically forwarded to your Hosted Graphite account. They are prefixed with: **heroku.\<app-name>.heroku-redis.\<instance-name>.\<type>** and report dyno statistics for load, memory, reads/writes, connections, and more!

We also have a Heroku Redis dashboard that is available in our [Dashboard Library](https://docs.hostedgraphite.com/dashboard-and-graphs/dashboard-library).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2F7U9o3y1o90Qju4J3jS2G%2Fheroku-redis-dash.png?alt=media&#x26;token=e0e7fe4e-7a0d-4919-bc79-e9770da2b4f6" alt="" width="563"><figcaption><p>Heroku Redis Dashboard</p></figcaption></figure>

If you use the Heroku [Kafka add-on](https://devcenter.heroku.com/articles/kafka-on-heroku) at the **Standard** tier or above, these metrics will automatically forward to your Hosted Graphite account. They are prefixed with: **heroku.\<app-name>.heroku-kafka.\<node>.\<instance-name>.\<type>** and report per-node statistics for load, memory, reads/writes, operations, and more!

We also have a Heroku Kafka dashboard that is available in our [Dashboard Library](https://docs.hostedgraphite.com/dashboard-and-graphs/dashboard-library).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2F9B37w7Sh0SyN4LmY02Rp%2Fheroku-kafka-dash.png?alt=media&#x26;token=e4562678-48a3-4490-b142-b845cee629f2" alt="" width="563"><figcaption><p>Heroku Kafka Dashboard</p></figcaption></figure>

#### [**Local Development Configuration**](#local-development-configuration)

In your local development environment, it will be necessary to replicate the above configuration. Since the [Foreman tool](https://devcenter.heroku.com/articles/procfile#developing-locally-with-foreman) will look in the `.env` file for development environment variables, use the following command to copy the `HOSTEDGRAPHITE_APIKEY` from the Heroku config (Do not check the file `.env` into source control).

> ```
> heroku config -s | grep HOSTEDGRAPHITE_APIKEY >> .env -a <app-name>
> ```
>
> ```
> more .env
> ```

More information on accessing your API key is detailed in the below section.

#### [Accessing the API Key Within Your App](#accessing-the-api-key-within-your-app)

Now that the add-on has been set up, the Hosted Graphite [*API Key*](https://docs.hostedgraphite.com/welcome-to-hosted-graphite#api-key) will be available via the environment variable **HOSTEDGRAPHITE\_APIKEY**. See the appropriate language snippet below for an example of how to access this variable in your app.

**Ruby** See also: [*Sending Metrics with Ruby*](https://docs.hostedgraphite.com/language-guide/ruby)

```
apikey = ENV['HOSTEDGRAPHITE_APIKEY']
```

**Python** See also: [*Sending Metrics with Python*](https://docs.hostedgraphite.com/language-guide/python-2.x)

```
apikey = os.environ['HOSTEDGRAPHITE_APIKEY']
```

**Java** See also: [*Sending Metrics with Java*](https://docs.hostedgraphite.com/language-guide/java)

```
String apikey = System.getenv("HOSTEDGRAPHITE_APIKEY");
```

**PHP** See also: [*Sending Metrics with PHP*](https://docs.hostedgraphite.com/language-guide/php)

```
$apikey = getenv('HOSTEDGRAPHITE_APIKEY');
```

**Node.js** See also: [*Sending Metrics with Node.js*](https://docs.hostedgraphite.com/language-guide/node.js)

```
var apikey = process.env.HOSTEDGRAPHITE_APIKEY;
```

### [Custom Metrics](#custom-metrics)

You can also send custom application metrics to your Hosted Graphite account. We provide code snippets in our [language guide](https://docs.hostedgraphite.com/language-guide) that can be configured throughout the codebase of your Heroku app to send Graphite metrics through a socket connection. Custom metrics can be tailored to track anything you want in your app like logins, sign ups, or cancellations.&#x20;

If you migrated your Heroku app monitoring from Librato, please note that Hosted Graphite does not support custom metrics via your app's log-drains.

See this helpful [video tutorial](https://www.youtube.com/watch?v=Xzr6pFwhDGM) on how to configure a custom StatsD metric to report an event from your Heroku app to your Hosted Graphite account.

### [Router Path Metrics](#router-path-metrics)

If you enable the Path Metrics feature in the Heroku **Config**, we will collect and forward router statistics (connection times, request methods/statuses) **per path** in your Heroku application. This will increase the total number of metrics being stored in the Hosted Graphite backend, but will give you **increased visibility** into activity within your app, and a higher level of alerting functionality.&#x20;

We offer these metrics in a dot.notation.format, or an underscore\_format giving you the option to choose the metric cardinality that works best for you:

**heroku.\<appname>.\<host>.router.\<path(url.com.sub-path)>.\<rest\_of\_metric>**

or

**heroku.\<appname>.\<host>.router.\<path(url\_com\_sub-path)>.\<rest\_of\_metric>**

If left on the 'default' metric format, you will receive the standard router metrics giving you a good overview of the activity within your Heroku app. The default router metrics are what can be seen on your [Heroku Auto Dashboard](#heroku-auto-dashboard).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2FKZHE5DHwjSlzKRt6GqFl%2Fheroku-config-card2.png?alt=media&#x26;token=ce77b927-3822-48cc-a090-c88e31505880" alt=""><figcaption></figcaption></figure>

### [Router Aggregates](#router-aggregates)

Our Heroku Router Aggregates features offer several ways to reduce metric cardinality by grouping router metrics that vary by dynamic elements such as paths, process identifiers, and hostnames. These options help simplify your router metric output while preserving the most useful statistical information.

#### [Path Aggregates](#path-aggregates)

If you have Path Metrics enabled, but experience a high cardinality of metrics due to unique identifiers being created in your app's URLs, our Router Aggregates feature will combine these values to reduce your metric overhead. For example, lets say your app generates endpoints with ID placeholders for a customer each time a route is accessed: "GET /api/path/\<placeholder-id>"

This could create a lot of unique heroku router metrics in your account and you might be better of receiving only 1 metric with a combined value. Simply define a path with the variable in curly brackets {placeholder-id} to combine multiple metrics into one! **NOTE**: Path metrics must first be enabled in your HG account, and you can define as many Router Aggregate paths as you like.

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2FJkVfN4cVEQoUOo4E0D7O%2Fpath-aggregates.png?alt=media&#x26;token=55aa832f-d529-4ad5-8128-11379923b08d" alt=""><figcaption></figcaption></figure>

#### [Process Aggregates](#process-aggregates)

Heroku runs your app code in Dynos defined by [One-Off](https://devcenter.heroku.com/articles/process-model) and [Worker](https://devcenter.heroku.com/articles/background-jobs-queueing) process types in your Procfile (you must have [Log-Runtime Metrics](https://devcenter.heroku.com/articles/log-runtime-metrics) enabled on your Heroku app to receive process metrics).

This feature rolls up multiple process instance IDs into a single metric stream, which is good for reducing cardinality and giving you a good performance overview. By default, you will receive individual process metrics, but we recommend enabling aggregation per process to significantly decrease your total metric count.

**Contact us** to enable Process Aggregation for any specific Heroku process metrics not listed in our Heroku UI (advanced\_scheduler, clock, celeryworker, worker\_pipeline, beat, mail\_syncer, notifications, orchestrator, priority, etc).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2FfJ1yy9yzWUdH8IN3QLZ0%2Fprocess-aggregates.png?alt=media&#x26;token=ac482412-0d87-458c-81b2-32f2a6ff2116" alt=""><figcaption></figcaption></figure>

#### [Host Aggregates](#host-aggregates)

Some Heroku apps report router metrics under multiple hostnames, such as a mix of your Heroku default domain (myapp.herokuapp.com), a custom domain ([www.herokuapp.com](http://www.herokuapp.com)), or internal service domains (UID-123.herokuapp.com). These hostname variations will produce multiple metric series even though they represent the same application.

If you don't require data for each host/subdomain of your app, enable the Host Aggregation feature to combine all individual hostname data sets into a single 'overview' series of: **heroku.router.\***

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2F5RsHnXXTahTMdBhGJL6A%2Fhost-aggregates.png?alt=media&#x26;token=6f3f8498-06ee-47e6-8b21-44091327509f" alt=""><figcaption></figcaption></figure>

### [Heroku Event Annotations](#heroku-event-annotations)

We also provide a convenient webhook that you can upload to your Heroku account and import real-time Heroku events to your Hosted Graphite account:

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2Fgtha7c2dqQWE7sPIhyrW%2Fheroku-annotation-config.png?alt=media&#x26;token=395feb83-7b5e-427c-b5c8-409e9fc6579f" alt=""><figcaption><p>Heroku Webhook</p></figcaption></figure>

Just add our HG webhook into your Heroku account, you can configure [annotations](https://docs.hostedgraphite.com/api-guides/annotations-and-events-api#dashboard-annotations) on your dashboards to display events from your Heroku environment around deployments, builds, domains, collaborators, add-ons, and more. The latest version of our Heroku Auto-Dashboard has the Heroku annotation built in, and you can generate the newest version of this dashboard from our [Dashboard Library](https://docs.hostedgraphite.com/dashboard-and-graphs/dashboard-library).

### [Monitoring Heroku Metrics on an Existing HG Account](#monitoring-heroku-metrics-on-an-existing-hg-account)

Its easy to forward your log drain metrics to an existing Hosted Graphite account. This is actually a better value because a dedicated HG account allows you to configure multiple heroku apps, get the full 2 year data retention, and premium level support for the same price as the Heroku add-on (depending on how many metrics your app produces).

<figure><img src="https://495119770-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZtHmoGZNsmARIViZEdbz%2Fuploads%2FMXWiiBHmIqn8AKrTBles%2Flog-drain-v2.png?alt=media&#x26;token=6274488c-02f6-4fb0-99ba-f20bb23de6c5" alt=""><figcaption></figcaption></figure>

**First**, make sure the Heroku ‘appname format’ is enabled in the Heroku Confg if you wish to include your appname in the metric naming scheme (recommended). Navigate to Add-Ons => Heroku, and confirm that the checkbox is checked.

**Next**, enable [Log-Runtime metrics](https://devcenter.heroku.com/articles/log-runtime-metrics) by running the following command in your Heroku CLI:

> ```
> heroku labs:enable log-runtime-metrics -a <app-name>
> ```

**Then**, after enabling runtime metrics, you need to restart your Heroku application:

> ```
> heroku restart -a <app-name>
> ```

**Finally**, you can just point the Heroku app logs to your existing Hosted Graphite account by running the following command:

> ```
> heroku drains:add https://webhooks.hostedgraphite.com/heroku/<app-name>/logs/\?apikey=<your-api-key> -a <app-name>
> ```

**NOTE: t**o avoid duplicate metric sets, make sure to enable both the 'appname format' checkbox in the Add-Ons UI, **and** include the appname in the above `drains:add` command. You are able to ship metrics from as many Heroku apps as you like, and metrics will appear as events happen within your app (status.\*, method.\*, etc).
