UNPKG

elastic-apm-node

Version:

The official Elastic APM agent for Node.js

48 lines (39 loc) 979 B
'use strict' const MetricsRegistry = require('./registry') const registrySymbol = Symbol('metrics-registry') const agentSymbol = Symbol('metrics-agent') class NoopLogger { debug () { } error () { } fatal () { } info () { } trace () { } warn () { } } class Metrics { constructor (agent) { this[agentSymbol] = agent this[registrySymbol] = null } start () { const metricsInterval = this[agentSymbol]._conf.metricsInterval this[registrySymbol] = new MetricsRegistry(this[agentSymbol], { reporterOptions: { defaultReportingIntervalInSeconds: metricsInterval, enabled: metricsInterval !== 0, unrefTimers: true, logger: new NoopLogger() } }) } stop () { if (this[registrySymbol]) { this[registrySymbol].shutdown() this[registrySymbol] = null } } getOrCreateCounter (...args) { return this[registrySymbol].getOrCreateCounter(...args) } } module.exports = Metrics