Monitor Node.js applications
Quickstart guide for monitoring Node.js applications using OpenAPM
To quickly get started with the OpenAPM in your Node.js application, follow the steps below:
Installation
OR
Usage
OpenAPM needs to be initialized in the application as early as possible so that it starts a metrics server and can monitor your application from the get-go.
To initialize OpenAPM, import the OpenAPM
class from the package
and create its instance. This will create a metrics server running by default on
http://localhost:9097
. The metrics will be available on
http://localhost:9097/metrics
.
Now, OpenAPM is ready to instrument the application packages using the
.instrument()
method.
Instrumentation
Currently, OpenAPM supports the following frameworks and databases.
Express
Call the instrument
method before initializing the Express application as
below.
This will instrument all HTTP requests from the Express application
and emit the Rate, Errors, Duration (RED) metrics.
These metrics will be available on http://localhost:9097/metrics
.
MySQL
OpenAPM supports instrumenting the mysql2
package. This means all the ORMs that use the mysql2
package internally will
get instrumented.
The database query metrics will be exposed on the /metrics
route on the
metrics server.
NestJS
OpenAPM supports instrumenting @nestjs/core v4 and above.
The Rate, Errors, Duration (RED) metrics for all the HTTP requests in the application will be emitted by default.
Configuration
You can customize the default behavior of OpenAPM by providing specific options described below.
-
path
: The path at which the metrics will be served. Defaults to/metrics
. -
metricsServerPort
: (Optional) The port at which the metricsServer will run. Defaults to9097
. -
environment
: (Optional) The application environment. Defaults toproduction
. -
defaultLabels
: (Optional) Any default labels to be included. -
requestsCounterConfig
: (Optional) Requests counter configuration, same as Counter inprom-client
. Defaults to -
requestDurationHistogramConfig
: (Optional) Requests Duration histogram configuration, the same as Histogram inprom-client
. Defaults to -
extractLabels
: (Optional) Extract labels from URL path params. -
excludeDefaultLabels
: (Optional) Provide labels to exclude from the default labels emitted by OpenAPM.
levitateConfig
: (Optional) Configuration for Last9. Adding this configuration will enable the Change Events such as application lifecycle events.
Storing Metrics
Metrics emitted by the OpenAPM library can be scraped by the Prometheus agent and sent to remote write storage like Last9. Follow the guide here to know more.
Visualization
OpenAPM collection ships with ready-to-import Grafana dashboards for applications to understand key performance indicators such as Apdex score, slow endpoints and slow database queries, among many others.
Steps to import default dashboards
- Import this dashboard into Grafana.
- Set up the data source to the one where metrics from OpenAPM are getting sent.
- Save the dashboard.