How to Monitor Your Node.js Application in Heroku

November 17, 2020


Heroku is a cloud-based platform to deploy, manage, and scale your node applications. It supports a wide range of languages including Node, Ruby, Python, Java, PHP, etc. along with providing a container-based load balancing approach. 

In this article, we will be covering how to monitor a Node.js application using Heroku CLI and visualize the metrics using the HG Heroku monitoring add-on.

The HG Heroku monitoring tool is an infrastructure and application monitoring tool that imports metrics from any data source, and visualizes the metrics on a single pane of glass. When you login to your HG Heroku Monitoring tool, dashboards for your Heroku app will be built automatically. Check it out here:

Preview of Hosted Graphite's auto generated Heroku dashboard

The service also provides full support, and you can easily access it in the intercom chat window in your app. If you’re starting your journey with Heroku, an introductory read on Heroku Monitoring with Hosted Graphite is recommended.

Setting up your environment

Heroku Command-Line Interface (CLI) installation requires a pre-installed git version. If you have not installed Git or Heroku CLI, visit here. This tutorial assumes your Node.js application running on Heroku. Refer to a step-by-step tutorial by the Dev centre to deploy your first Node.js application in Heroku.

Image of a demo Heroku application using Node.js

Below are the system configurations used for this tutorial:

Operating System: Ubuntu 18.04.4 LTS
Git version: 2.17.1
Node.js version: 8.10.0
Npm version: 3.5.2
Heroku CLI version: 7.46.2

Monitoring the metrics using the Hosted Graphite Add-on

1. Connect Heroku with HG Heroku add-on using Heroku CLI

Copy the following command to your terminal.

$ heroku addons:add hostedgraphite

Once this is installed, a new HOSTEDGRAPHITE_APIKEY configuration key will be available. To access your key, type the following:

$ heroku config:get HOSTEDGRAPHITE_APIKEY
--> abcdef-abcd-dcba-abcd-abcdefabcd

We will now add this configuration to our env file as well.

$ heroku config -s | grep HOSTEDGRAPHITE_APIKEY >> .env
$ more .env

One last step to connect our add-on with our Node.js application.

$ heroku drains:add<appname>/logs/?apikey=<your_api_key>

To check whether our add-on is working properly, let’s visit our Heroku Account. Under the apps listed, click on your Node.js application. You should see something like this on the upper left corner: 

Screenshot of Hosted Graphite add on in Heroku's 'Installed add-ons' list

You will be directed to your HG Heroku Monitoring account by clicking on this add-on in your Heroku account. Go to Metrics -> Metric Treemap. Your Treemap will now have Heroku written in one of the many fragments.

Image of Hosted Graphite's Metric Treemap

Your account will also list that it has created a new dashboard. However, if you’ve just deployed your application, it will not show anything because it is not sending any metrics. Therefore, we will enable some metrics in this tutorial to verify if our Grafana Dashboards are indeed working as intended.

2. Enabling Node.js Metrics

If your application is already sending custom metrics to the HG Heroku monitoring add-on, then you could skip this step. 

In our case, we will enable the Node.js runtime metrics available here using the following commands:

$ heroku labs:enable "runtime-heroku-metrics" -a "my-app-name"
$ heroku labs:enable "nodejs-language-metrics" -a "my-app-name"

It may take some time to reflect these metrics on the Grafana Dashboard. If it still doesn’t show up, try restarting Heroku using:

$heroku restart 

3. Metrics on Grafana Dashboards

To verify if the metrics are indeed sending their data to our dashboard, go to Metrics->Account Diagnostics. You should see a similar graph if you have just enabled your metrics following the above steps.

Image of Hosted Graphite's Account Diagnositcs in Metrics tab.

Note that the suddenly lifted bar is because the metrics were previously disabled by default. Now, let’s check our Grafana Dashboard.

Image of Hosted Graphite's Grafana dashboard receiving metrics

This Dashboard along with 5 other metrics was automatically created. Another Dashboard showing Data Points received per second is shown below:

Image of Hosted Graphite's Grafana dashboard showing Data Points received per second.


In this tutorial, we saw how to use the HG Heroku monitoring service to your Heroku Node.js Application using Heroku CLI. We also covered enabling traffic Metrics and visualizing the information using Grafana Dashboard.

The HG Heroku monitoring service is run by MetricFire, a hosted Prometheus, Graphite and Grafana service. Hosted Prometheus, Hosted Graphite and Hosted Grafana can do much more than Heroku Metrics Visualization. To find out more, book a free trial today! or check out our post on 10 reasons why you should choose MetricFire.

Related Posts

No items found.

See why thousands of engineers trust Hosted Graphite with their monitoring