64 lines
1.1 KiB
JavaScript
64 lines
1.1 KiB
JavaScript
/*
|
|
* 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;
|