pm2 microservices monitoring with Grafana + InfluxDB

Nikunj Prajapati
Aug 14, 2018 · 3 min read

Is it possible to monitor pm2 microservices through Grafana?

Yes, It’s possible. Let’s say, you have an nth number of microservices and all those are running on the production server and you want to monitor those via an eminent tool like kibana, grafana, Databox with not any cost.

Of course, It’s completely free. You can create unlimited dashboard in grafana and easily manage it.

What you have to do?

You need to install Grafana and influxDB into your server. Whatever server it can be, no worries about that.

  1. What is Grafana?

Grafana is an open-source visualization tool that can be used on top of a variety of different data stores but is most commonly used together with Graphite, InfluxDB, and also Elasticsearch and If you are completely new to grafana, please refer this link for installation and configuration.

Next, you need one database which can store large amounts of time series data like InfluxDB, Graphite, Elasticsearch, etc. For instance, we use InfluxDB.

2. What is InfluxDB?

InfluxDB is used as a data store for any use case involving large amounts of time-stamped data, including DevOps monitoring, log data, application metrics, IoT sensor data, and real-time analytics.

please refer this link for installation guide.

I hope your grafana and influxDB services are running.

Now, PM2 comes with a web interface, in the form of a JSON API. We can start that by running the following command:

This listens on all networks on port 9615. The web interface is actually a monitored process. We can inspect any monitored process. Thus, make sure you have opened this port number into the security group(for cloud). If you want to test, enter http://your_ip:9615 in your browser, you will get JSON response of your all pm2 microservices.

Step 1. Its time to connect influxDB with Grafana..

Open grafana on the browser via http://your_ip:3000 and login with the correct credentials. You might see the screen like this

Now, Its time to configure data source i.e. influxDB. Click on add data source and select InfluxDB as a data source. Fill up all the required details and click on save and test button. For more clarity, please see the below image.

Thus, You have successfully integrated grafana with influxDB. Now, you need to make one cron which fetch those microservices data to influxdb.

Step 2. Prepare the node scheduler..

I have already coded node scheduler and uploaded on GitHub. You just need to clone it and configure it with your DB name, server IP and field name.

Step 3. Configure the grafana dashboard..

Now, Let’s create a graph into grafana dashboard. Please select ‘PM2’ as a database source and set a query like display maximum cpu consumption of “microservice_1” (`Base64` in my case). It would look like this

Congratulation! You did it. You can monitor all your microservices through grafana. Grafana also support notification, alert and data render time series. Even, you can share this dashboard with other user as a guest role.

If you enjoyed this post, let me know, and please tell others about it.

Be brave. Add a comment or ask a question.

Thank you and Good Bye… Follow me on Facebook, Twitter

Nikunj Prajapati

Written by

Software Engineer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade