Hosted Graphite provides a Heroku add-on! Installing the add-on is as simple as issuing the command:
$ heroku addons:add hostedgraphite -----> Adding hostedgraphite to sharp-mountain-4005... done, v1
Once installed, this add-on will make a new application configuration key available, called HOSTEDGRAPHITE_APIKEY. Confirm the key by issuing the command:
$ heroku config:get HOSTEDGRAPHITE_APIKEY abcdef-abcd-dcba-abcd-abcdefabcd
In your local development environment, it will be necessary to replicate this configuration. Since the Foreman tool will look in the .env file for development environment variables, use the following command to copy HOSTEDGRAPHITE_APIKEY from the heroku config (Do not check the file .env into source control).
$ heroku config -s | grep HOSTEDGRAPHITE_APIKEY >> .env $ more .env
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.
To have your heroku application name stored as part of your metric names, include it in the log drain url as follows:
heroku drains:add https://webhooks.hostedgraphite.com/heroku/<appname>/logs/?apikey=<api_key>
This prevents individual dyno metric duplication and stores them in the format:
Sending Custom Metrics¶
That’s it! You can now begin to send metric messages to Hosted Graphite from your Heroku app. For full documentation on our Heroku plugin, please visit the Hosted Graphite on Heroku documentation page.
Accessing the API Key within your app¶
Now that the add-on has been setup, the Hosted Graphite API Key will be available via the environment variable HOSTEDGRAPHITE_APIKEY. See the appropriate language snippet below for an example on how to access this variable in your app.
apikey = ENV['HOSTEDGRAPHITE_APIKEY']
See also: Sending Metrics with Ruby
apikey = os.environ['HOSTEDGRAPHITE_APIKEY']
See also: Sending Metrics with Python
String apikey = System.getenv("HOSTEDGRAPHITE_APIKEY");
See also: Sending Metrics with Java
$apikey = getenv('HOSTEDGRAPHITE_APIKEY');
See also: Sending Metrics with PHP
var apikey = process.env.HOSTEDGRAPHITE_APIKEY;
See also: Sending Metrics with Node.js
- If I have trouble with my metrics, should I remove and re-add the Hosted Graphite plugin?