pandora-component-reporter-manager
Advanced tools
Comparing version 2.0.0-9 to 2.0.0-beta.0
@@ -13,7 +13,11 @@ import { MetricsOscillator } from './oscillator/MetricsOscillator'; | ||
bindOscillators(): void; | ||
startAtAllProcesses(): void; | ||
stopAtAllProcesses(): void; | ||
start(): Promise<void>; | ||
startAtSupervisor(): Promise<void>; | ||
stop(): Promise<void>; | ||
stopAtSupervisor(): Promise<void>; | ||
} | ||
export * from './doamin'; | ||
export * from './domain'; | ||
export * from './ReporterManager'; | ||
export * from './oscillator/MetricsOscillator'; |
@@ -17,2 +17,3 @@ "use strict"; | ||
const ErrorLogOscillator_1 = require("./oscillator/ErrorLogOscillator"); | ||
const pandora_dollar_1 = require("pandora-dollar"); | ||
let ComponentReporterManager = class ComponentReporterManager { | ||
@@ -26,3 +27,3 @@ constructor(ctx) { | ||
this.metricsOscillator = new MetricsOscillator_1.MetricsOscillator(metricsManager, { | ||
interval: metricsConfig.interval / 1000 | ||
interval: metricsConfig.interval | ||
}); | ||
@@ -35,21 +36,33 @@ this.traceOscillator = new TraceOscillator_1.TraceOscillator(traceManager); | ||
this.metricsOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('metrics', data).catch(console.error); | ||
this.reporterManager.dispatch('metrics', data).catch(pandora_dollar_1.consoleLogger.error); | ||
}); | ||
this.traceOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('trace', data).catch(console.error); | ||
this.reporterManager.dispatch('trace', data).catch(pandora_dollar_1.consoleLogger.error); | ||
}); | ||
this.errorLogOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('errorLog', data).catch(console.error); | ||
this.reporterManager.dispatch('errorLog', data).catch(pandora_dollar_1.consoleLogger.error); | ||
}); | ||
} | ||
startAtAllProcesses() { | ||
this.metricsOscillator.start(); | ||
this.traceOscillator.start(); | ||
this.errorLogOscillator.start(); | ||
} | ||
stopAtAllProcesses() { | ||
this.metricsOscillator.stop(); | ||
this.traceOscillator.stop(); | ||
this.errorLogOscillator.stop(); | ||
} | ||
async start() { | ||
await this.metricsOscillator.start(); | ||
await this.traceOscillator.start(); | ||
await this.errorLogOscillator.start(); | ||
this.startAtAllProcesses(); | ||
} | ||
async startAtSupervisor() { | ||
await this.metricsOscillator.start(); | ||
await this.traceOscillator.start(); | ||
await this.errorLogOscillator.start(); | ||
this.startAtAllProcesses(); | ||
} | ||
async stop() { | ||
this.stopAtAllProcesses(); | ||
} | ||
async stopAtSupervisor() { | ||
this.stopAtAllProcesses(); | ||
} | ||
}; | ||
@@ -56,0 +69,0 @@ ComponentReporterManager = __decorate([ |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("events"); | ||
const debug = require('debug')('pandora:reporter-manager:ErrorLogOscillator'); | ||
class ErrorLogOscillator extends events_1.EventEmitter { | ||
@@ -12,3 +13,8 @@ constructor(errorLogManager, options) { | ||
this.handler = (list) => { | ||
this.emit('oscillate', list); | ||
try { | ||
this.emit('oscillate', list); | ||
} | ||
catch (err) { | ||
debug(err); | ||
} | ||
}; | ||
@@ -15,0 +21,0 @@ this.errorLogManager.on('dump', this.handler); |
@@ -15,2 +15,3 @@ /// <reference types="node" /> | ||
start(): void; | ||
collect(): Promise<void>; | ||
report(metricsData: { | ||
@@ -17,0 +18,0 @@ gauges: Map<string, BaseGauge<any>>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const debug = require('debug')('pandora:reporter-manager:MetricsOscillatorOption'); | ||
const metrics_common_1 = require("metrics-common"); | ||
const events_1 = require("events"); | ||
const pandora_component_metrics_1 = require("pandora-component-metrics"); | ||
const pandora_metrics_util_1 = require("pandora-metrics-util"); | ||
const debug = require('debug')('pandora:reporter-manager:MetricsOscillator'); | ||
class MetricsOscillator extends events_1.EventEmitter { | ||
constructor(metricsManager, options) { | ||
super(); | ||
this.intervalHandler = null; | ||
this.options = options; | ||
@@ -18,25 +19,25 @@ this.interval = options.interval; | ||
this.intervalHandler = setInterval(async () => { | ||
try { | ||
debug('exec report once'); | ||
const categoryMetrics = this.metricsManager.getAllCategoryMetrics(); | ||
await this.report({ | ||
gauges: categoryMetrics.get(metrics_common_1.MetricType.GAUGE), | ||
counters: categoryMetrics.get(metrics_common_1.MetricType.COUNTER), | ||
histograms: categoryMetrics.get(metrics_common_1.MetricType.HISTOGRAM), | ||
meters: categoryMetrics.get(metrics_common_1.MetricType.METER), | ||
timers: categoryMetrics.get(metrics_common_1.MetricType.TIMER), | ||
fastCompasses: categoryMetrics.get(metrics_common_1.MetricType.FASTCOMPASS) | ||
}); | ||
} | ||
catch (err) { | ||
console.error(err); | ||
} | ||
}, interval * 1000); | ||
this.collect().catch((err) => { | ||
debug('collect error', err); | ||
}); | ||
}, interval); | ||
} | ||
} | ||
async collect() { | ||
debug('exec report once'); | ||
const categoryMetrics = this.metricsManager.getAllCategoryMetrics(); | ||
await this.report({ | ||
gauges: categoryMetrics.get(metrics_common_1.MetricType.GAUGE), | ||
counters: categoryMetrics.get(metrics_common_1.MetricType.COUNTER), | ||
histograms: categoryMetrics.get(metrics_common_1.MetricType.HISTOGRAM), | ||
meters: categoryMetrics.get(metrics_common_1.MetricType.METER), | ||
timers: categoryMetrics.get(metrics_common_1.MetricType.TIMER), | ||
fastCompasses: categoryMetrics.get(metrics_common_1.MetricType.FASTCOMPASS) | ||
}); | ||
} | ||
async report(metricsData) { | ||
const { gauges, counters, histograms, meters, timers, fastCompasses } = metricsData; | ||
const timestamp = Date.now(); | ||
const collector = new pandora_component_metrics_1.CompactMetricsCollector({ | ||
reportInterval: this.interval, | ||
const collector = new pandora_metrics_util_1.CompactMetricsCollector({ | ||
reportInterval: this.interval / 1000, | ||
}); | ||
@@ -68,2 +69,3 @@ const gaugesArr = Array.from(gauges.values()); | ||
for (const metricObject of collector.build()) { | ||
/* istanbul ignore else */ | ||
if (metricObject && metricObject.toJSON) { | ||
@@ -78,3 +80,3 @@ list.push(metricObject.toJSON()); | ||
catch (err) { | ||
console.error('report metrics data error!', err); | ||
debug('report metrics data error!', err); | ||
} | ||
@@ -84,2 +86,3 @@ } | ||
this.intervalHandler && clearInterval(this.intervalHandler); | ||
this.intervalHandler = null; | ||
} | ||
@@ -86,0 +89,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("events"); | ||
const pandora_component_trace_1 = require("pandora-component-trace"); | ||
const debug = require('debug')('pandora:reporter-manager:TraceOscillator'); | ||
const TRACE_DATA_DUMP = 'Trace:Data_Dump'; | ||
class TraceOscillator extends events_1.EventEmitter { | ||
@@ -13,8 +14,13 @@ constructor(traceManager, options) { | ||
this.handler = (list) => { | ||
this.emit('oscillate', list); | ||
try { | ||
this.emit('oscillate', list); | ||
} | ||
catch (err) { | ||
debug(err); | ||
} | ||
}; | ||
this.traceManager.on(pandora_component_trace_1.TRACE_DATA_DUMP, this.handler); | ||
this.traceManager.on(TRACE_DATA_DUMP, this.handler); | ||
} | ||
stop() { | ||
this.traceManager.removeListener(pandora_component_trace_1.TRACE_DATA_DUMP, this.handler); | ||
this.traceManager.removeListener(TRACE_DATA_DUMP, this.handler); | ||
} | ||
@@ -21,0 +27,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { IReporter } from './doamin'; | ||
import { IReporter } from './domain'; | ||
export declare class ReporterManager { | ||
@@ -3,0 +3,0 @@ registration: Map<string, IReporter>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const debug = require('debug')('pandora:reporter-manager:ReporterManager'); | ||
class ReporterManager { | ||
@@ -10,3 +11,8 @@ constructor() { | ||
if (reporter.type === type) { | ||
await reporter.report(data); | ||
try { | ||
await reporter.report(data); | ||
} | ||
catch (err) { | ||
debug(err); | ||
} | ||
} | ||
@@ -13,0 +19,0 @@ } |
{ | ||
"name": "pandora-component-reporter-manager", | ||
"version": "2.0.0-9", | ||
"description": "Pandora 2 Component Node.js Metrics", | ||
"version": "2.0.0-beta.0", | ||
"description": "Pandora 2 Component Reporter Manager", | ||
"main": "dist/ComponentReporterManager", | ||
@@ -11,3 +11,3 @@ "typings": "dist/ComponentReporterManager.d.ts", | ||
"lint": "../../node_modules/.bin/tslint --format prose -c ../../tslint.json src/**/*.ts test/**/*.ts", | ||
"test": "npm run lint && true", | ||
"test": "npm run lint && NODE_ENV=unittest mocha --trace-warnings", | ||
"cov": "nyc mocha", | ||
@@ -22,13 +22,13 @@ "ci": "npm run test", | ||
"devDependencies": { | ||
"@types/chai": "^3.5.2", | ||
"@types/chai": "^4.1.7", | ||
"@types/extend": "^3.0.0", | ||
"@types/mocha": "^2.2.41", | ||
"@types/node": "^8.5.2", | ||
"chai": "^3.5.0", | ||
"chai": "^4.2.0", | ||
"mm": "^2.1.0", | ||
"mocha": "^3.5.0", | ||
"nyc": "^8.4.0", | ||
"pandora-component-error-log": "^2.0.0-9", | ||
"pandora-component-metrics": "^2.0.0-9", | ||
"pandora-component-trace": "^2.0.0-9" | ||
"nyc": "^13.1.0", | ||
"pandora-component-error-log": "^2.0.0-beta.0", | ||
"pandora-component-metrics": "^2.0.0-beta.0", | ||
"pandora-component-trace": "^2.0.0-beta.0" | ||
}, | ||
@@ -41,3 +41,5 @@ "nyc": { | ||
"exclude": [ | ||
"typings" | ||
"typings", | ||
"dist", | ||
"src/domain.ts" | ||
], | ||
@@ -61,6 +63,8 @@ "extension": [ | ||
"dependencies": { | ||
"debug": "^4.1.1", | ||
"metrics-common": "^1.1.6", | ||
"pandora-component-decorator": "^2.0.0-9", | ||
"pandora-dollar": "^2.0.0-9" | ||
"pandora-component-decorator": "^2.0.0-beta.0", | ||
"pandora-dollar": "^2.0.0-beta.0", | ||
"pandora-metrics-util": "^2.0.0-beta.0" | ||
} | ||
} |
@@ -6,2 +6,3 @@ import {componentName, dependencies, componentConfig} from 'pandora-component-decorator'; | ||
import {ErrorLogOscillator} from './oscillator/ErrorLogOscillator'; | ||
import {consoleLogger} from 'pandora-dollar'; | ||
@@ -32,3 +33,3 @@ @componentName('reporterManager') | ||
this.metricsOscillator = new MetricsOscillator(metricsManager, { | ||
interval: metricsConfig.interval / 1000 | ||
interval: metricsConfig.interval | ||
}); | ||
@@ -44,29 +45,44 @@ this.traceOscillator = new TraceOscillator(traceManager); | ||
this.metricsOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('metrics', data).catch(console.error); | ||
this.reporterManager.dispatch('metrics', data).catch(consoleLogger.error); | ||
}); | ||
this.traceOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('trace', data).catch(console.error); | ||
this.reporterManager.dispatch('trace', data).catch(consoleLogger.error); | ||
}); | ||
this.errorLogOscillator.on('oscillate', (data) => { | ||
this.reporterManager.dispatch('errorLog', data).catch(console.error); | ||
this.reporterManager.dispatch('errorLog', data).catch(consoleLogger.error); | ||
}); | ||
} | ||
startAtAllProcesses() { | ||
this.metricsOscillator.start(); | ||
this.traceOscillator.start(); | ||
this.errorLogOscillator.start(); | ||
} | ||
stopAtAllProcesses() { | ||
this.metricsOscillator.stop(); | ||
this.traceOscillator.stop(); | ||
this.errorLogOscillator.stop(); | ||
} | ||
async start() { | ||
await this.metricsOscillator.start(); | ||
await this.traceOscillator.start(); | ||
await this.errorLogOscillator.start(); | ||
this.startAtAllProcesses(); | ||
} | ||
async startAtSupervisor() { | ||
await this.metricsOscillator.start(); | ||
await this.traceOscillator.start(); | ||
await this.errorLogOscillator.start(); | ||
this.startAtAllProcesses(); | ||
} | ||
async stop() { | ||
this.stopAtAllProcesses(); | ||
} | ||
async stopAtSupervisor() { | ||
this.stopAtAllProcesses(); | ||
} | ||
} | ||
export * from './doamin'; | ||
export * from './domain'; | ||
export * from './ReporterManager'; | ||
export * from './oscillator/MetricsOscillator'; |
import {EventEmitter} from 'events'; | ||
import {ErrorLogManager} from 'pandora-component-error-log'; | ||
const debug = require('debug')('pandora:reporter-manager:ErrorLogOscillator'); | ||
@@ -21,3 +22,7 @@ export interface ErrorLogOscillatorOption { | ||
this.handler = (list) => { | ||
try { | ||
this.emit('oscillate', list); | ||
} catch(err) { | ||
debug(err); | ||
} | ||
}; | ||
@@ -32,2 +37,1 @@ this.errorLogManager.on('dump', this.handler); | ||
} | ||
import {MetricsManager} from 'pandora-component-metrics'; | ||
const debug = require('debug')('pandora:reporter-manager:MetricsOscillatorOption'); | ||
import { | ||
@@ -13,6 +12,7 @@ BaseGauge, | ||
import {EventEmitter} from 'events'; | ||
import {CompactMetricsCollector} from 'pandora-component-metrics'; | ||
import {CompactMetricsCollector} from 'pandora-metrics-util'; | ||
const debug = require('debug')('pandora:reporter-manager:MetricsOscillator'); | ||
export interface MetricsOscillatorOption { | ||
interval: number; | ||
interval: number; // ms | ||
} | ||
@@ -24,3 +24,3 @@ | ||
interval: number; | ||
intervalHandler; | ||
intervalHandler = null; | ||
metricsManager: MetricsManager; | ||
@@ -39,22 +39,24 @@ | ||
this.intervalHandler = setInterval(async () => { | ||
try { | ||
debug('exec report once'); | ||
const categoryMetrics = this.metricsManager.getAllCategoryMetrics(); | ||
await this.report( | ||
{ | ||
gauges: <Map<string, BaseGauge<any>>> categoryMetrics.get(MetricType.GAUGE), | ||
counters: <Map<string, BaseCounter>> categoryMetrics.get(MetricType.COUNTER), | ||
histograms: <Map<string, BaseHistogram>> categoryMetrics.get(MetricType.HISTOGRAM), | ||
meters: <Map<string, BaseMeter>> categoryMetrics.get(MetricType.METER), | ||
timers: <Map<string, BaseTimer>> categoryMetrics.get(MetricType.TIMER), | ||
fastCompasses: <Map<string, BaseFastCompass>> categoryMetrics.get(MetricType.FASTCOMPASS) | ||
} | ||
); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}, interval * 1000); | ||
this.collect().catch((err) => { | ||
debug('collect error', err); | ||
}); | ||
}, interval); | ||
} | ||
} | ||
async collect() { | ||
debug('exec report once'); | ||
const categoryMetrics = this.metricsManager.getAllCategoryMetrics(); | ||
await this.report( | ||
{ | ||
gauges: <Map<string, BaseGauge<any>>> categoryMetrics.get(MetricType.GAUGE), | ||
counters: <Map<string, BaseCounter>> categoryMetrics.get(MetricType.COUNTER), | ||
histograms: <Map<string, BaseHistogram>> categoryMetrics.get(MetricType.HISTOGRAM), | ||
meters: <Map<string, BaseMeter>> categoryMetrics.get(MetricType.METER), | ||
timers: <Map<string, BaseTimer>> categoryMetrics.get(MetricType.TIMER), | ||
fastCompasses: <Map<string, BaseFastCompass>> categoryMetrics.get(MetricType.FASTCOMPASS) | ||
} | ||
); | ||
} | ||
async report(metricsData: { | ||
@@ -73,3 +75,3 @@ gauges: Map<string, BaseGauge<any>>, | ||
const collector = new CompactMetricsCollector({ | ||
reportInterval: this.interval, | ||
reportInterval: this.interval / 1000, | ||
}); | ||
@@ -108,2 +110,3 @@ | ||
for (const metricObject of collector.build()) { | ||
/* istanbul ignore else */ | ||
if (metricObject && metricObject.toJSON) { | ||
@@ -117,3 +120,3 @@ list.push(metricObject.toJSON()); | ||
} catch (err) { | ||
console.error('report metrics data error!', err); | ||
debug('report metrics data error!', err); | ||
} | ||
@@ -125,2 +128,3 @@ | ||
this.intervalHandler && clearInterval(this.intervalHandler); | ||
this.intervalHandler = null; | ||
} | ||
@@ -127,0 +131,0 @@ |
import {EventEmitter} from 'events'; | ||
import {TraceManager, TRACE_DATA_DUMP} from 'pandora-component-trace'; | ||
import {TraceManager} from 'pandora-component-trace'; | ||
const debug = require('debug')('pandora:reporter-manager:TraceOscillator'); | ||
const TRACE_DATA_DUMP = 'Trace:Data_Dump'; | ||
export interface TraceOscillatorOption { | ||
@@ -21,3 +24,7 @@ } | ||
this.handler = (list) => { | ||
this.emit('oscillate', list); | ||
try { | ||
this.emit('oscillate', list); | ||
} catch(err) { | ||
debug(err); | ||
} | ||
}; | ||
@@ -24,0 +31,0 @@ this.traceManager.on(TRACE_DATA_DUMP, this.handler); |
@@ -1,2 +0,3 @@ | ||
import {IReporter} from './doamin'; | ||
import {IReporter} from './domain'; | ||
const debug = require('debug')('pandora:reporter-manager:ReporterManager'); | ||
@@ -8,3 +9,7 @@ export class ReporterManager { | ||
if(reporter.type === type) { | ||
await reporter.report(data); | ||
try { | ||
await reporter.report(data); | ||
} catch(err) { | ||
debug(err); | ||
} | ||
} | ||
@@ -11,0 +16,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30892
578
5
+ Addeddebug@^4.1.1
+ Addedpandora-metrics-util@2.1.2(transitive)
Updatedpandora-dollar@^2.0.0-beta.0