Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
pm2-prom-module
Advanced tools
PM2 module to help collect applications statistic and send it to Prometheus server
PM2 module to help collect applications statistic and send it to Prometheus server
NEW: Starting from version 2.0.0, the plugin now supports the collection of all your Prometheus metrics from the running applications across multiple instances.
Most of applications use Prometheus monitoring server to collect statistic and then show it on Grafana dashboard. PM2 gives you a way to monitor the resource usage of your application but unfortunately most of information is available from your terminal or with PM2 Plus dashboard. To solve this isses you should use additional module to export statistic data.
Also if you use PM2-AutoScale module you want to see how many active instances of the app is currently active and how many resources it using.
This module pm2-prom-module
allows you to collect all PM2 monitoring data such as CPU Usage
, Memory Usage
and etc for your every applications and run HTTP server inside module to collect all metrics.
Also collect all PM2 default metrics for every instance:
pm2 install pm2-prom-module
After installation module creates HTTPS server on address http://localhost:9988/
and servers responds with Prometheus metrics
pm2 uninstall pm2-prom-module
Default settings:
port
Connection port for Prometheus agent. (default to 9988
)hostname
Listen address. (default to 0.0.0.0
)unix_socket_path
Set if you want to listen on unix socket (default to `` - empty string)service_name
Default label for registry (default to `` - empty string)debug
Enable debug mode to show logs from the module (default to false
)aggregate_app_metrics
Enable to aggregate metrics from app instances (default to true
)app_check_interval
Interval to check available apps and collect statistic (default to 1000
)To modify the module config values you can use the following commands:
pm2 set pm2-prom-module:debug true
pm2 set pm2-prom-module:port 10801
pm2 set pm2-prom-module:hostname 127.0.0.1
pm2 set pm2-prom-module:service_name MyApp
pm2 set pm2-prom-module:aggregate_app_metrics true
pm2 set pm2-prom-module:app_check_interval 5000
As of plugin version 2.0.0
, it enables the collection of metrics from all currently running applications in PM2, presenting them in a unified output alongside other PM2 metrics.
To communicate between PM2 nodejs application and pm2-prom-module
you can use pm2-prom-module-client which is using process messaging bus between module and an app.
Here an example how to use it:
import client from 'prom-client';
import { initMetrics } from 'pm2-prom-module-client';
const registry = new client.Registry();
const PREFIX = `nodejs_app_`;
const metricRequestCounter = new client.Counter({
name: `${PREFIX}request_counter`,
help: 'Show total request count',
registers: [registry],
});
// Register your prom-client Registry
initMetrics(registry);
// ...
app.get('/*', async (req: AppFastifyRequest, res) => {
// ...
metricRequestCounter?.inc();
// ...
});
Plugin automatically collect metrics from all running instances of apps and all metrics will be available on the same endpoint with pm2-prom-module
. Have a look on an example below.
Also you can add any of your own labels for any of prom-client
counters, but app
, and instance
are reserved for plugin and will be overwritten.
Since version 2.1.0
module support aggregation data for all instances by default.
But you can disable it with module configuration.
pm2 set pm2-prom-module:aggregate_app_metrics false
Aggregated data from all running apps:
# HELP nodejs_app_requests_total Show total request count
# TYPE nodejs_app_requests_total counter
nodejs_app_requests_total{app="app",serviceName="MyApp"} 8
nodejs_app_requests_total{app="app2",serviceName="MyApp"} 3
# HELP pm2_free_memory Show available host free memory
# TYPE pm2_free_memory gauge
pm2_free_memory{serviceName="my-app"} 377147392
# HELP pm2_cpu_count Show available CPUs count
# TYPE pm2_cpu_count gauge
pm2_cpu_count{serviceName="my-app"} 4
# HELP pm2_available_apps Show available apps to monitor
# TYPE pm2_available_apps gauge
pm2_available_apps{serviceName="my-app"} 1
# HELP pm2_app_instances Show app instances count
# TYPE pm2_app_instances gauge
pm2_app_instances{app="app",serviceName="my-app"} 2
# HELP pm2_app_average_memory Show average using memory of an app
# TYPE pm2_app_average_memory gauge
pm2_app_average_memory{app="app",serviceName="my-app"} 60813927
# HELP pm2_app_total_memory Show total using memory of an app
# TYPE pm2_app_total_memory gauge
pm2_app_total_memory{app="app",serviceName="my-app"} 121626624
# HELP pm2_event_loop_latency_p95 Event Loop Latency p95. Unit "ms"
# TYPE pm2_event_loop_latency_p95 gauge
pm2_event_loop_latency_p95{app="app",instance="13",serviceName="my-app"} 2.55
pm2_event_loop_latency_p95{app="app",instance="14",serviceName="my-app"} 2.48
# HELP nodejs_app_requests_total Show total request count
# TYPE nodejs_app_requests_total counter
nodejs_app_requests_total{app="app",instance="13",serviceName="my-app"} 10
nodejs_app_requests_total{app="app",instance="14",serviceName="my-app"} 17
max-memory-restart
?You can install plugin and restart it with the command:
pm2 restart pm2-prom-module --max-memory-restart=3000M
pm2_app_status
describes status of an app. (0-unknown,1-running,2-pending,3-stopped,4-errored)
All other metrics related to the app (not for pids) will be displayed. For example, pm2_available_apps
will show app until
it will be deleted from the PM2 or pm2_app_instances
will show 0 for stopped
or errored
status apps.hostname
. Listen address. If you want to specify, for example, localhost
, 127.0.0.1
unix_socket_path
. Run server on unix socket path.app_check_interval
. Interval to check available apps and collect statisticFAQs
PM2 module to help collect applications statistic and send it to Prometheus server
The npm package pm2-prom-module receives a total of 966 weekly downloads. As such, pm2-prom-module popularity was classified as not popular.
We found that pm2-prom-module demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.