monitoring-manager
v1.0.0
Published
A monitoring package for Node.js and NestJS applications using Prometheus
Downloads
2
Readme
npm install
const monitoringOptions: MonitoringOptions = { port: 3001, enableHttpMetrics: true, enableProcessMetrics: true, customMetrics: true, };
const monitoringService = new MonitoringService(monitoringOptions); monitoringService.attachHttpMetrics(app);
// usage in app.js or app.ts file -->
import MonitoringService, { MonitoringOptions } from 'node-monitoring-package'; import express from 'express';
const app = express();
const monitoringOptions: MonitoringOptions = { port: 3001, enableHttpMetrics: true, enableProcessMetrics: true, customMetrics: [ { type: 'counter', name: 'custom_request_total', help: 'Total number of custom requests', labelNames: ['method', 'endpoint'] }, { type: 'gauge', name: 'custom_memory_usage_bytes', help: 'Custom memory usage gauge', labelNames: ['type'] } ] };
const monitoringService = new MonitoringService(monitoringOptions); monitoringService.attachHttpMetrics(app);
app.get('/custom', (req, res) => { // Example usage of custom metric const customCounter = client.getSingleMetric('custom_request_total') as client.Counter; customCounter.inc({ method: req.method, endpoint: '/custom' });
res.send('Custom metrics route');
});
app.listen(3000, () => { console.log('App running on port 3000'); });