1
0
Fork 0
auth.rxbn.de/bin/prometheus/module.js

64 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-09-26 20:23:52 +00:00
/*
* This file is part of the authRXBN single sign-on package.
*
* (c) Ruben Meyer <contact@rxbn.de>
*/
// init
var methods = {};
let client = require('prom-client');
client.collectDefaultMetrics(); // collect system info
let register = client.register;
let metrics = {};
var cfg = require(global['__dirname']+'/bin/config');
/**
* get a metric
* @author Ruben Meyer
* @param {String} name metric name
* @return {Metric}
*/
methods.getMetric = (name) => {
return metrics[name];
}
/**
* add a metric
* @author Ruben Meyer
* @param {String} name metric name
* @param {Metric} metric metric object
* @param {Boolean} overwrite overwrite parameter to overwrite metric if it already exists
* @return {Boolean}
*/
methods.addMetric = (name, metric, overwrite = false) => {
if(name in metrics && !overwrite)
return false;
metrics[name] = metric;
return true;
};
/**
* get the metrics register
* @author Ruben Meyer
* @return {Object}
*/
methods.getRegister = () => {
return register;
};
/**
* get the metrics client
* @author Ruben Meyer
* @return {Object}
*/
methods.getClient = () => {
return client;
};
module.exports = methods;