A Tool for Monitoring Your Functions

2 min readJun 18, 2018

It’s important to keep tabs on your running Functions, monitoring their state and health. PubNub provides structural integrity for applications of any scale, but there could be times where the code within the Function does something you didn’t intend, so we’ve developed a tool that allows you to monitor those irregularities.

The Function monitoring tool is a Python script that monitors all of your event handlers and displays alerts/notifications in the terminal. This is beneficial because you can easily add all of your logs of this system to Elasticsearch via the remote server running the monitor. This will enable services like Kibana, Grafana, and PagerDuty – which in turn covers logging, metrics, and alerts for the on-call engineering team.

NOTE: If you used SSO (Google) to sign in, you will need to go into the admin portal and change your password. The new password you set will be the one you enter into the tool down below.

Set Up and Running the Tool

First, we’ll start off by cloning the project.

git pull https://github.com/bigoper/pubnub-monitoring-functions.git master

Once we have that, go into the pfunc-monitor folder.

cd pfunc-monitor

Now install all the dependencies.

sudo pip install -r requirements.txt

Great! Now let’s add our credentials for PubNub.

python app.py --user=YourEmailAddress --password='yourPassword'

If your login is correct, the terminal should print out Success.(1). Once you receive that, you can run the script and let it listen for any notifications that come in from your Functions.

python app.py

Now if anything comes up, you’ll see it in your terminal!

How does it work?

It’s important to understand the different layers of a Function, which in turn gives us a better understanding of the different channels it makes on startup.

Looking at the diagram below, you can see the different apps we’ve created in our PubNub account. Inside those apps, we have keysets that are linked to those apps. Each keyset then has their own modules, and finally, within those modules, we have our Functions.

This is really important for understanding our code, since from a debugging perspective, we are subscribing to channels related to each piece in the hierarchy.

Functions Monitoring

Let’s see how this would look in our Admin Dashboard.

Functions monitoring

You can see in the console that we have three different channels that we connect to.

The first on is “*”, which is the same channel that the Function is listening on. The next two are a bit more unique. They are related to the hierarchy and are channels that are publishing events that are taking place and allow for the debugging. The monitoring tool subscribes to these three channels and prints out the different messages being published.

More from PubNub

How to Create a Dating App: 7 Steps to Fit Any Design
Insights6 minMar 15, 2023

How to Create a Dating App: 7 Steps to Fit Any Design

There are common underlying technologies for a dating app, and in this post, we’ll talk about the major technologies and designs...

Michael Carroll

Michael Carroll

How to Create a Real-time Public Transportation Schedule App
Build6 minMar 14, 2023

How to Create a Real-time Public Transportation Schedule App

How to use geohashing, JavaScript, Google Maps API, and BART API to build a real-time public transit schedule app.

Michael Carroll

Michael Carroll

How to Create Real-Time Vehicle Location Tracking App
Build2 minMar 9, 2023

How to Create Real-Time Vehicle Location Tracking App

How to track and stream real-time vehicle location on a live-updating map using EON, JavaScript, and the Mapbox API.

Michael Carroll

Michael Carroll

Talk to an expert