bigbluebutton-Github/bigbluebutton-html5/imports/startup/server/prom-metrics/metrics.js
germanocaumo 6f1e1d4f4a refactor(prom-html5): serve endpoint via meteor instead of http server +
- separate backend/frontend metrics, only add metrics related to the role
- add role and instance labels
2021-11-05 16:31:23 +00:00

43 lines
1000 B
JavaScript

const {
Counter,
} = require('prom-client');
const METRICS_PREFIX = 'html5_'
const METRIC_NAMES = {
METEOR_METHODS: 'meteorMethods',
}
const buildFrontendMetrics = () => {
return {
[METRIC_NAMES.METEOR_METHODS]: new Counter({
name: `${METRICS_PREFIX}meteor_methods`,
help: 'Total number of meteor methods processed in html5',
labelNames: ['methodName', 'role', 'instanceId'],
}),
}
}
const buildBackendMetrics = () => {
// TODO add relevant backend metrics
return {}
}
let METRICS;
const buildMetrics = () => {
if (METRICS == null) {
const isFrontend = (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'frontend');
const isBackend = (!process.env.BBB_HTML5_ROLE || process.env.BBB_HTML5_ROLE === 'backend');
if (isFrontend) METRICS = buildFrontendMetrics();
if (isBackend) METRICS = { ...METRICS, ...buildBackendMetrics()}
}
return METRICS;
};
export {
METRICS_PREFIX,
METRIC_NAMES,
METRICS,
buildMetrics,
};