@epictnr/metrics
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Epictnr Metrics 🪣

Collect metrics (OpenMetrics\Prometheus) from many NodeJS instances

(the part of micro-starter framework)

How to use

Init example:
const acmeMetrics = require('@epictnr/metrics')
const logger = require('../logger')

const metricsConfig = {
  serviceName: 'testService',
  port: 8080,
  aggregateHosts: [
    'acme-service-sync-spending-worker',
    'acme-service-webhooks'
  ],
  aggregateTimeout: 2000, //ms
  collectDefaultMetricsInterval: 5000 // ms
}

const metrics = acmeMetrics(metricsConfig, logger)
Api worker:
const metrics = require('../app/metrics')

app.use('/', metrics.getMasterRouter())

metrics.startMaster('api')

process.on('SIGINT', () => {
  metrics.stop()
})
Other workers:
const metrics = require('../app/metrics')

metrics.start('webhooks')

process.on('SIGINT', () => {
  metrics.stop()
})
OpenApi schema:
paths:
  /metrics:
    get:
      summary: Get application metrics
      responses:
        '200':
          description: Application metrics OpenMetrics\Prometheus format
          content:
            text/plain:
              example:
                # HELP api_process_cpu_user_seconds_total Total user CPU time spent in seconds.
                # TYPE api_process_cpu_user_seconds_total counter
                api_process_cpu_user_seconds_total 0.6500000000000001 1551965298565

How to publish:

$ npm pub

Package Sidebar

Install

npm i @epictnr/metrics

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

22.8 kB

Total Files

14

Last publish

Collaborators

  • olegator8800