Heroku Redis Monitoring

November 10, 2020

Introduction

Redis is an open-source data structure store used as a database, cache and message broker. It supports several Data Structures including lists, sets, strings, hashes, etc. In this article, we will cover how to add a Redis instance to your existing Heroku application. Later, in the article, we will also see how Grafana Dashboards can be created using Hosted Graphite’s addon, HG Heroku Monitoring, for monitoring your application’s metrics. 

HG Heroku Monitoring is a Hosted Graphite service, offered as a stand-alone app, or as a Heroku add-on. HG Heroku monitoring offers Hosted Grafana, Hosted Graphite, and Hosted Prometheus services, which wraps all your metrics into one single pane of glass. It’s easy to do redis monitoring in Heroku when you can pull in any kind of time-series metrics, and visualize them on Grafana dashboards.

Install the Heroku add-on and start Heroku redis monitoring in just a few clicks. 

Prerequisites & Environment Settings

We will be using the Heroku CLI throughout this tutorial. If you have not installed the Heroku CLI, visit here. The CLI also requires you to have Git installed in your system. This tutorial is done using the following configurations:

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

Alternatively, visit the Heroku User Interface

Since Heroku supports all the major Operating Systems, this tutorial will be applicable to the Windows and MAC users as well. 

Provisioning a Redis instance

We will provision a Redis instance on a running Node.js test application for the sake of simplicity. Once we have the Redis instance we’ll check out how to do Heroku redis monitoring. Deploy your first Node.js application using this thorough guide available on the Heroku dev center. 



If you already have an application running with Redis provisioned, you can verify with this command if the Redis is indeed provisioned.


$ heroku addons | grep heroku-redis


The above command will return a null value if you have not provisioned a Redis instance for your application which moves us to the next step.

$ heroku addons:create heroku-redis:hobby-dev -a your-app-name


Keep a note of the instance name as it will be required in the following commands. To check the status of your instance, type the following:


$ heroku addons:info <your-redis-instance-name>
===>
Attachments:  floating-sea-52624::HEROKU_REDIS_PURPLE
Installed at: Mon Nov XX 20XX 19:XX:XX GMT+0530 (India Standard Time)
Owning app:   floating-sea-XXXXX
Plan:         heroku-redis:hobby-dev
Price:        free
State:        created


It may take a minute for the status to be updated from “creating” to “created”. After this step, a Redis URL will be available which can be viewed using:

$ heroku config | grep REDIS
HEROKU_REDIS_URL: redis://h:asdfqwer1234asdf@xxxxxxxxxxxxxxxxxxxx
HEROKU_REDIS_PURPLE_URL: redis://h:asdfqwer1234asdf@xxxxxxxxxxxxxx


In our case, multiple URLs are generated because more than one instance is provisioned.


Now, on to Heroku Redis monitoring with HG Heroku Monitoring!

   

Monitor the application using Hosted Graphite

Provision the HG Heroku Monitoring add-on

Now that our application is up and running, we will configure the HG Heroku Monitoring add-on using the following command:


$ heroku addons:add hostedgraphite


Follow these steps on how to add these configurations to your env file as well and link it to your application.


HOSTEDGRAPHITE_APIKEY can be accessed using:

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


Our Heroku Dashboard will now look something like this

If you just created your application, then the dashboard will not display any metrics because we have not enabled them yet. 

In case you already had an application running, feel free to explore the automatically created dashboards.

Enable Node.js Metrics

To enable the convention Node.js metrics, type:

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


It may take a while for our Dashboards to reflect this data. The output should look something like this:


Here you can see your Heroku redis monitoring, with metrics sent in to HG Heroku Monitoring directly from your app to automatically generated heroku monitoring dashboards. 

   

Sending Custom Metrics

We will need to access the above mentioned HOSTEDGRAPHITE_APIKEY in our application. Below is a code snippet for accessing HOSTEDGRAPHITE_APIKEY in a Node.js application


var apikey = process.env.HOSTEDGRAPHITE_APIKEY;


Below are the code snippets for sending out custom-metrics for a Node.js application running on Heroku.


TCP Connection

var net    = require('net');
var apikey = process.env.HOSTEDGRAPHITE_APIKEY;

var socket = net.createConnection(2003, "carbon.hostedgraphite.com", function() {
  socket.write(apikey + ".request.time 1444\n');
  socket.end();
});

UDP Connection

var dgram  = require('dgram');
var apikey = process.env.HOSTEDGRAPHITE_APIKEY;

var message = new Buffer(apikey + ".request.time 1444\n");
var client = dgram.createSocket("udp4");
client.send(message, 0, message.length, 2003, "carbon.hostedgraphite.com", function(err, bytes) {
    client.close();
});


Other language specific codes are available here

Conclusion

In this tutorial, we saw how to provision a Redis instance for your Heroku application. We also created sample Grafana Dashboards by enabling Node.js metrics. This tutorial can be extended to other programming languages as well, for instance, Monitoring a Python application in Heroku


Look no further for the best way to do Heroku Redis monitoring! HG Heroku Monitoring has got your back. 


Check out our top picks for API Monitoring tools or register for a free trial today!



Related Posts

No items found.

See why thousands of engineers trust Hosted Graphite with their monitoring

START A FREE TRIAL