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
NOTE: If you are an existing HostedGraphite user or you want to use Hostedgraphite for collecting and visualizing metrics other than Heroku, please go here.
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/<app-name>/logs/\?apikey=<api_key> -a <app-name>
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
- I don’t see any metrics coming into my Hosted Graphite account.It can take some time for metrics to appear. Upon provisioning the HG add-on, log-runtime and application metrics should be created automatically. If this is not the case, you can run the ‘enable log-runtime’ and ‘log drain’ commands from within your Heroku CLI, steps can be found here. If you’re still having trouble and can’t find help in these docs, or our FAQ, then just get in touch. We’re happy to help.