[misc] fix module importing

This commit is contained in:
Jakob Ackermann 2020-08-14 00:41:21 +02:00 committed by Jakob Ackermann
parent b2e661b408
commit 6f4829e817
9 changed files with 10 additions and 10 deletions

View file

@ -9,7 +9,7 @@ module.exports = (EventLoopMonitor = {
monitor(logger, interval, log_threshold) {
if (interval == null) { interval = 1000; }
if (log_threshold == null) { log_threshold = 100; }
const Metrics = require("./metrics");
const Metrics = require("./index");
// check for logger on startup to avoid exceptions later if undefined
if ((logger == null)) { throw new Error("logger is undefined"); }
// monitor delay in setInterval to detect event loop blocking

View file

@ -11,7 +11,7 @@ const yn = require("yn");
const STACKDRIVER_LOGGING = yn(process.env['STACKDRIVER_LOGGING']);
module.exports.monitor = logger => (function(req, res, next) {
const Metrics = require("./metrics");
const Metrics = require("./index");
const startTime = process.hrtime();
const {
end

View file

@ -73,13 +73,13 @@ module.exports = (MemoryMonitor = {
monitor(logger) {
const interval = setInterval(() => MemoryMonitor.Check(logger)
, oneMinute);
const Metrics = require("./metrics");
const Metrics = require("./index");
return Metrics.registerDestructor(() => clearInterval(interval));
},
Check(logger) {
let mem;
const Metrics = require("./metrics");
const Metrics = require("./index");
const memBeforeGc = (mem = inMegaBytes(process.memoryUsage()));
Metrics.gauge("memory.rss", mem.rss);
Metrics.gauge("memory.heaptotal", mem.heapTotal);

View file

@ -21,7 +21,7 @@ module.exports = {
mongodbCore = require(v2_path);
} catch (error1) {}
const Metrics = require("./metrics");
const Metrics = require("./index");
const monitorMethod = function(base, method, type) {
let _method;

View file

@ -19,13 +19,13 @@ module.exports = (OpenSocketsMonitor = {
monitor(logger) {
const interval = setInterval(() => OpenSocketsMonitor.gaugeOpenSockets()
, 5 * seconds);
const Metrics = require("./metrics");
const Metrics = require("./index");
return Metrics.registerDestructor(() => clearInterval(interval));
},
gaugeOpenSockets() {
let agents, hostname, url;
const Metrics = require("./metrics");
const Metrics = require("./index");
const object = require('http').globalAgent.sockets;
for (url in object) {
agents = object[url];

View file

@ -24,7 +24,7 @@ describe('event_loop', function() {
warn: sinon.stub()
};
return this.event_loop = SandboxedModule.require(modulePath, { requires: {
'./metrics': this.metrics
'./index': this.metrics
}
}
);

View file

@ -25,7 +25,7 @@ describe('timeAsyncMethod', function() {
inc: sinon.stub()
};
this.timeAsyncMethod = SandboxedModule.require(modulePath, { requires: {
'./metrics': this.metrics
'./index': this.metrics
}
}
);

View file

@ -9,7 +9,7 @@
module.exports = function(obj, methodName, prefix, logger) {
let modifedMethodName;
const metrics = require('./metrics');
const metrics = require('./index');
if (typeof obj[methodName] !== 'function') {
throw new Error(`[Metrics] expected object property '${methodName}' to be a function`);