Links

Heroku

Here is how to add Heroku Addon to Hosted Graphite.
Contents
Hosted Graphite has a Heroku Add-On! Installing the add-on can be done through your Heroku account in the ‘Resources’ section, or by issuing the following command in your Heroku CLI:
heroku addons:add 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>
Now, you just need to run one more command from the Heroku CLI to send the application’s dyno metrics to your new HG account:
heroku drains:add https://webhooks.hostedgraphite.com/heroku/<app-name>/logs/\?apikey=<api-key> -a <app-name>
Note: Including the app-name in the Log-Drain command prevents individual dyno metric duplication and stores them in the following format:
heroku.<appname>.<dyno>.<dyno_number>.<rest_of_metric>
You can now navigate to your new Hosted Graphite account through the Heroku UI and wait for the metrics to appear.
For full documentation on our Heroku Add-On, please visit the Hosted Graphite on Heroku page.
This dashboard will be automatically created when you enable the Heroku Add-On, or configure Log-Drain metrics to your existing Hosted Graphite account:
Automatic Heroku Dashboard
Using Heroku’s Log-Runtime metrics we retrieve and process Heroku’s syslog information for your Dynos including:
  • Load average - 1 / 5 / 15-minute averages
  • Memory and Swap - Resident memory, disk cache, swap, total memory, and cumulative totals for pages written to and read from disk.
  • HTTP metrics - The number of requests broken down by HTTP method and status codes, data transferred, and connect and service times.
In your local development environment, it will be necessary to replicate the above configuration. Since the Foreman tool 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.
Now that the add-on has been set up, the 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
apikey = ENV['HOSTEDGRAPHITE_APIKEY']
Python See also: Sending Metrics with Python
apikey = os.environ['HOSTEDGRAPHITE_APIKEY']
Java See also: Sending Metrics with Java
String apikey = System.getenv("HOSTEDGRAPHITE_APIKEY");
PHP See also: Sending Metrics with PHP
$apikey = getenv('HOSTEDGRAPHITE_APIKEY');
Node.js See also: Sending Metrics with Node.js
var apikey = process.env.HOSTEDGRAPHITE_APIKEY;
You can send metric messages to Hosted Graphite from your Heroku app. See our Language Guide for more information on sending custom metrics through your application code using a socket connection.
If you already have a Hosted Graphite account and you want to send dyno metrics from your Heroku application, you will need to enable the Heroku ‘appname format’ if you wish to include your appname in the metric naming scheme (recommended). Simply navigate to Add-Ons => Heroku, then click the checkbox and Save:
Next, you will need to enable Log-Runtime metrics by running the following command in your Heroku CLI:
heroku labs:enable log-runtime-metrics -a <app-name>
After enabling runtime metrics, you will 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=<api-key> -a <app-name>
NOTE: Make sure to replace the variables <app-name> and <api-key> with their respective details and you can generate the Heroku Autodash in Add-Ons => Dashboard Library. You are able to ship metrics from as many Heroku apps as you like, but it can take up to an hour for all of the application metrics to appear for the first time.
Last modified 1mo ago