Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setupOptions.excludeRoutes = excludeRoutes || [];
setupOptions.includeQueryParams = includeQueryParams;
setupOptions.defaultMetricsInterval = defaultMetricsInterval;
let metricNames = {
http_request_duration_seconds: 'http_request_duration_seconds',
app_version: 'app_version',
http_request_size_bytes: 'http_request_size_bytes',
http_response_size_bytes: 'http_response_size_bytes',
defaultMetricsPrefix: ''
};
metricNames = utils.getMetricNames(metricNames, useUniqueHistogramName, metricsPrefix, projectName);
Prometheus.collectDefaultMetrics({ timeout: defaultMetricsInterval, prefix: `${metricNames.defaultMetricsPrefix}` });
if (!Prometheus.register.getSingleMetric(metricNames.app_version)) {
const version = new Prometheus.Gauge({
name: metricNames.app_version,
help: 'The service version by package.json',
labelNames: ['version', 'major', 'minor', 'patch']
});
const versionSegments = appVersion.split('.').map(Number);
version.labels(appVersion, versionSegments[0], versionSegments[1], versionSegments[2]).set(1);
}
setupOptions.responseTimeHistogram = Prometheus.register.getSingleMetric(metricNames.http_request_duration_seconds) || new Prometheus.Histogram({
name: metricNames.http_request_duration_seconds,
help: 'Duration of HTTP requests in seconds',
labelNames: ['method', 'route', 'code'],
// buckets for response time from 1ms to 500ms
buckets: durationBuckets || [0.001, 0.005, 0.015, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5]
server.get('/metrics', (req, res) => {
res.set('Content-Type', Prom.register.contentType)
res.end(Prom.register.metrics())
})
}
processAuth(req,res).then(function (authResult){
if(!authResult){
return;
}
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(promClient.register.metrics());
});
}
middleware(ctx, next) {
if (!this.setupOptions.server && ctx.req.socket) {
this.setupOptions.server = ctx.req.socket.server;
this._collectDefaultServerMetrics(this.setupOptions.defaultMetricsInterval);
}
if (ctx.req.url === this.setupOptions.metricsRoute) {
debug('Request to /metrics endpoint');
ctx.set('Content-Type', Prometheus.register.contentType);
ctx.body = Prometheus.register.metrics();
return next();
}
if (ctx.req.url === `${this.setupOptions.metricsRoute}.json`) {
debug('Request to /metrics endpoint');
ctx.body = Prometheus.register.getMetricsAsJSON();
return next();
}
ctx.req.metrics = {
timer: this.setupOptions.responseTimeHistogram.startTimer({
method: ctx.req.method
}),
contentLength: parseInt(ctx.request.get('content-length')) || 0
};
app.get('/metrics', (_req, res) => {
res.send(PromClient.register.metrics())
})
rates.getZecRate((err,zecRate)=> {
zecPrice.set(Number(zecRate.rate));
res.end(promclient.register.metrics());
});
});
function routeHandler(req, res, log, cb) {
if (req.method !== 'GET') {
return cb(errors.BadRequest, []);
}
const promMetrics = client.register.metrics();
const contentLen = Buffer.byteLength(promMetrics, 'utf8');
res.setHeader('content-length', contentLen);
res.setHeader('content-type', client.register.contentType);
res.end(promMetrics);
return undefined;
}
processAuth(req,res).then(function (authResult){
if(!authResult){
return;
}
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(promClient.register.metrics());
});
}
app.get('/metrics', async (req, res) => {
const [nodeResults,
neighborResults] = await Promise.all([
nodeInfo.getNodeInfo(),
neighborInfo.getNeighborInfo()
])
res.end(promclient.register.metrics())
})
this.router.get('/metrics', observable => observable.mapTo(prometheus.register.metrics()));