replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
@@ -2,7 +2,7 @@ import apps from './apps.js';
|
||||
import assert from 'node:assert';
|
||||
import BoxError from './boxerror.js';
|
||||
import constants from './constants.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import docker from './docker.js';
|
||||
import fs from 'node:fs';
|
||||
import net from 'node:net';
|
||||
@@ -15,7 +15,7 @@ import shellModule from './shell.js';
|
||||
import superagent from '@cloudron/superagent';
|
||||
import _ from './underscore.js';
|
||||
|
||||
const debug = debugModule('box:metrics');
|
||||
const { log, trace } = logger('metrics');
|
||||
const shell = shellModule('metrics');
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ async function readSystemMetrics() {
|
||||
}
|
||||
|
||||
async function sendToGraphite() {
|
||||
// debug('sendStatsToGraphite: collecting stats');
|
||||
// log('sendStatsToGraphite: collecting stats');
|
||||
|
||||
const result = await readSystemMetrics();
|
||||
|
||||
@@ -203,7 +203,7 @@ async function sendToGraphite() {
|
||||
});
|
||||
|
||||
client.on('error', (error) => {
|
||||
debug(`Error sending data to graphite: ${error.message}`);
|
||||
log(`Error sending data to graphite: ${error.message}`);
|
||||
resolve();
|
||||
});
|
||||
|
||||
@@ -381,7 +381,7 @@ async function pipeContainerToMap(name, statsMap) {
|
||||
// we used to poll before instead of a stream. but docker caches metrics internally and rate logic has to handle dups
|
||||
const statsStream = await docker.getStats(name, { stream: true });
|
||||
|
||||
statsStream.on('error', (error) => debug(error));
|
||||
statsStream.on('error', (error) => log(error));
|
||||
statsStream.on('data', (data) => {
|
||||
const stats = JSON.parse(data.toString('utf8'));
|
||||
const metrics = translateContainerStatsSync(stats);
|
||||
@@ -478,7 +478,7 @@ async function getStream(options) {
|
||||
|
||||
const INTERVAL_MSECS = 1000;
|
||||
intervalId = setInterval(async () => {
|
||||
if (options.system) await safe(pipeSystemToMap(statsMap), { debug });
|
||||
if (options.system) await safe(pipeSystemToMap(statsMap), { debug: log });
|
||||
|
||||
const result = {};
|
||||
const nowSecs = Date.now() / 1000; // to match graphite return value
|
||||
|
||||
Reference in New Issue
Block a user