NodeJS Monitoring Simplified: Get Real-Time Metrics Effortless with N|solid

Jefferson Rios
5 min readJan 12, 2024

--

nodesource logo

N|solid is a game-changer in the NodeJS world, offering a secure and scalable runtime environment for your applications. Built on top of NodeJS itself, N|solid offers full compatibility with your existing codebase, allowing you to leverage its advanced features without any code modifications.

Why would you want N|Solid over NodeJS:

N|Solid significantly outperforms NodeJS instrumented with traditional APM libraries, as evidenced by the N|Solid benchmark (https://benchmark.nodesource.com). This benchmark demonstrates N|Solid’s ability to handle more than twice the number of HTTP requests compared to its instrumented counterparts.

Validate how much costs you can cut using N|solid instead https://www.nodesource.com/infrastructure-cost

Nsolid Benchmark HTTP Requests per second

Exporting N|Solid(nodejs) Metrics to Prometheus and Visualizing in Real-time with Grafana

N|Solid metrics visualized in a Grafana dashboard.

Technical Overview

N|solid Runtime

Sends metrics to the statsd_exporter using StatsD protocol. https://docs.nodesource.com/nsolid/5.0/docs#statsd

statsd_exporter

Receives N|solid metrics and translates it into a Prometheus-compatible format.

Prometheus

Scrapes metrics from the statsd_exporter and stores them in its database.

Grafana

Connects to Prometheus and displays the collected metrics in customizable dashboards.

N|solid Metrics workflow

Let’s Start with the POC implementation

Must have installed Docker and Docker compose

Step 1: Clone the repo with all needed config

git clone https://github.com/riosje/nsolid-prometheus-poc
cd nsolid-prometheus-poc

Step 2: Run the Docker Compose file to set up a complete Proof of Concept environment for experimenting with N|solid metrics

docker-compose up

Step 3: Access Grafana

Go to http://localhost:3000/dashboards using the credentials admin:admin. Once logged in, you’ll have access to two default dashboards.

Step 4: Get N|solid Runtime

You can get N|solid via YUM or APT from https://downloads.nodesource.com/

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
apt-get install nsolid -y

Docker image -> https://hub.docker.com/r/nodesource/nsolid

Step 5: Configure your own N|solid process

To configure your N|solid process to export metrics via StatsD to statsd_exporter, you need to configure the runtime either through environment variables (ENV) or through package.json.

Here’s an example using ENV variables.

NSOLID_APPNAME=YOUR-APP-NAME
NSOLID_ENV=dev
NSOLID_STATSD_BUCKET=nsolid.statsd
NSOLID_STATSD_TAGS='shortId:${shortId},app:${app},env:${env},hostname:${hostname}'
NSOLID_STATSD=127.0.0.1:9125

In the docker-compose file, the environment variable NSOLID_STATSD does not use localhost or 127.0.0.1. This is because Docker internally resolves the service DNS.

Here’s an example using the package.json.

{
"name": "YOUR-APP-NAME",
"version": "1.0.0",
"main": "index.js",
"nsolid": {
"statsd": "127.0.0.1:9125",
"statsdBucket": "nsolid.statsd",
"env": "dev",
"statsdTags": "shortId:${shortId},app:${app},env:${env},hostname:${hostname}"
},
"scripts": {
"start": "nsolid index.js"
}
}

Step 6: View Application Metrics in Grafana

After successfully configuring your N|solid process to export metrics via StatsD to the statsd_exporter, you should be able to view your application’s metrics in Grafana. Here’s how:

1. Access Grafana

2. Explore the Dashboards

  • Two default dashboards are available:
  • N|solid Overview: Provides an overview of key metrics, including CPU, memory, and network usage.
  • N|solid Services: Offers detailed information about specific N|solid services, including their health, performance, and resource utilization.
  • Each dashboard displays various graphs and panels visualizing your application’s metrics in real-time.
  • You can explore the dashboards further and customize them to your specific needs.

3. Verify Metrics

  • Look for metrics specific to your application, identified by the configured NSOLID_APPNAME and other tags (e.g., app, env).
  • Ensure the metrics are updating accurately in real-time, reflecting the activity of your N|solid process.
  • If you encounter any issues, double-check your configuration and ensure all services are running properly.

Additional Notes

  • You can also access the Prometheus server directly at http://localhost:9090 to view and query the metrics in its native format.
  • Grafana allows you to create custom dashboards and alerts based on specific metrics, tailored to your monitoring needs.

With your application’s metrics exposed and visualized in Grafana, you can gain valuable insights into its performance and behavior, enabling you to identify potential bottlenecks and optimize your solution for optimal performance and stability.

But this not all… There is even more from NodeSource

What if tell you can get all of this features:

  1. AI Assistant:

2. Debugging features, Heap Snapshots and CPU profiles

3. Machine Learning to identify upcoming perf issues.

4. Vulnerability Scanning and 3rd party modules certification, SBOM

Visit the Nodesource site to get full list of features and services offered.

You can SignUp to the Nodesource SaaS and get easily a free license for up to 4 process

--

--