Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(config, tags) {
const dbConfig = {
username: config.username,
password: config.password,
database: config.database,
port: config.port,
host: config.host,
protocol: config.protocol,
precision: 'm',
};
// So uh. This library doesn't support path-prefixes.
// So let's just monkey patch that in.
const sender = new DefaultSender(dbConfig);
const oldDiscard = sender.db.pool.discard;
const oldText = sender.db.pool.text;
sender.db.pool.text = function internal(props) {
// eslint-disable-next-line no-param-reassign
props.path = config.pathPrefix + props.path;
// eslint-disable-next-line prefer-rest-params
return oldText.apply(this, arguments);
};
sender.db.pool.discard = function internal(props) {
// eslint-disable-next-line no-param-reassign
props.path = config.pathPrefix + props.path;
// eslint-disable-next-line prefer-rest-params
return oldDiscard.apply(this, arguments);
sender.db.pool.text = function internal(props) {
// eslint-disable-next-line no-param-reassign
props.path = config.pathPrefix + props.path;
// eslint-disable-next-line prefer-rest-params
return oldText.apply(this, arguments);
};
sender.db.pool.discard = function internal(props) {
// eslint-disable-next-line no-param-reassign
props.path = config.pathPrefix + props.path;
// eslint-disable-next-line prefer-rest-params
return oldDiscard.apply(this, arguments);
};
this.reporter = new InfluxMetricReporter({
sender,
tags,
unit: MILLISECOND,
reportInterval: 30000,
});
this.reporter.setLog({
info: () => {},
trace: () => {},
debug: () => {},
warn: () => {},
error: () => {},
});
this.metrics = {};
this.registry = new MetricRegistry();
async function influxReporter (registry, tags) {
const {
DefaultSender,
InfluxMetricReporter
} = require('inspector-influx')
const sender = new DefaultSender({
database: 'express4',
hosts: [{
host: '127.0.0.1',
port: 8086
}]
})
const reporter = new InfluxMetricReporter({
log: null,
minReportingTimeout: 30,
reportInterval: 5000,
sender
})
reporter.setTags(tags)
reporter.addMetricRegistry(registry)
async function influxReporter (registry, tags) {
const {
DefaultSender,
InfluxMetricReporter
} = require('inspector-influx')
const sender = new DefaultSender({
database: 'express4',
hosts: [{
host: '127.0.0.1',
port: 8086
}]
})
const reporter = new InfluxMetricReporter({
log: null,
minReportingTimeout: 30,
reportInterval: 5000,
sender
})
reporter.setTags(tags)
reporter.addMetricRegistry(registry)
await reporter.start()
return reporter
}