Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// let config = require('../../config/config');
const client = require('prom-client');
const collectDefaultMetrics = client.collectDefaultMetrics;
const register = new client.Registry();
/**
* COLLECT DEFAULT METRICS FOR THE PROCESS
* https://prometheus.io/docs/instrumenting/writing_clientlibs/#standard-and-runtime-collectors
*/
collectDefaultMetrics({
timeout: 5000,
register: register
});
/**
* METRIC DEFINITIONS
*/
const testCounter = new client.Counter({
const client = require('prom-client');
// Stores
const itunes = require('app-store-scraper');
const gplay = require('google-play-scraper');
// Config files
const config = require('../../config/config.json');
const apps = require('../../config/apps.json');
const metrics = require('../config/metrics.json');
const register = new client.Registry();
// Collect Scrape Metrics (duration, memory/CPU used, etc.)
// https://prometheus.io/docs/instrumenting/writing_exporters/#metrics-about-the-scrape-itself
client.collectDefaultMetrics({ register });
const gauges = {};
/**
* Get enabled metrics from the config file
* and compatible based on the store
*
* @param {String} store
* @returns
*/
function getEnabledMetrics(store) {
const enabledMetrics = [];
constructor ({ ignoreTags = {} } = {}) {
this._registry = new Prometheus.Registry()
this._options = {
ignoreTags
}
// Initialize metrics
this._metricsOperationDurationSeconds()
}
constructor() {
this.register = new prometheus.Registry()
this.counters = {
numRequests: new prometheus.Counter({
name: 'service_requests_total',
help: 'Total service requests',
labelNames: ['category', 'family', 'service'],
registers: [this.register],
}),
responseTime: new prometheus.Histogram({
name: 'service_response_millis',
help: 'Service response time in milliseconds',
// 250 ms increments up to 2 seconds, then 500 ms increments up to 8
// seconds, then 1 second increments up to 15 seconds.
buckets: [
250,
500,
750,
/* globals require, process, __dirname, module */
const express = require('express');
const yaml = require('node-yaml');
const path = require('path');
const expressStaticGzip = require('express-static-gzip');
const bunyan = require('bunyan');
const finalhandler = require('finalhandler');
const promClient = require('prom-client');
const fakePbf = require('./middlewares/fake_pbf/index');
const compression = require('compression');
const mapStyle = require('./middlewares/map_style');
const getReqSerializer = require('./serializers/request');
const app = express();
const promRegistry = new promClient.Registry();
function App(config) {
const openSearch = require('./middlewares/opensearch/index')(config);
const constants = yaml.readSync('../config/constants.yml');
const languages = constants.languages;
const router = express.Router();
this.logger = bunyan.createLogger({
name: 'erdapfel',
stream: process.stdout,
level: process.env.NODE_ENV === 'test' ? 'warn' : 'info',
serializers: {
req: getReqSerializer(config),
err: bunyan.stdSerializers.err,
},
});
function Prometheus (config, runtime) {
if (!(this instanceof Prometheus)) {
return new Prometheus(config, runtime)
}
const { prometheus } = config
if (!prometheus) return
const { label: dyno } = prometheus
this.config = prometheus
this.register = new client.Registry()
this.client = client
this.runtime = runtime
this.metrics = {}
this.shared = {}
this.listenerId = `${listenerPrefix}${dyno}`
this.register.setDefaultLabels({ dyno })
const timeout = 10000
this.timeout = timeout
setInterval(() => this.maintenance(), timeout)
process.on('exit', () => {
try {
this.quit()
} catch (e) {
this.runtime.captureException(e)
constructor () {
this.registry = new (Prometheus.Registry)()
this.incomingDataPackets = new PeerCounter({
name: 'ilp_connector_incoming_ilp_packets',
help: 'Total number of incoming ILP packets',
labelNames: [ 'result', 'code'],
registers: [this.registry]
})
this.incomingDataPacketValue = new PeerCounter({
name: 'ilp_connector_incoming_ilp_packet_value',
help: 'Total value of incoming ILP packets',
labelNames: [ 'result', 'code'],
registers: [this.registry]
})
this.outgoingDataPackets = new PeerCounter({
public constructor(opts: IMetricsOptions) {
this.opts = opts;
this.registry = new Registry();
}
export const prometheusLoggerMiddleware = () => {
const register = new Registry()
const gauge = new Gauge({ name: 'io_http_requests_current', help: 'The current number of requests in course.' })
register.registerMetric(gauge)
collectDefaultMetrics({ register })
const startGcStats = gcStats(register)
startGcStats()
return async (ctx: ServiceContext, next: () => Promise) => {
if (ctx.request.path !== '/metrics') {
gauge.inc(1)
await next()
gauge.dec(1)
return
}
ctx.set('Content-Type', register.contentType)
ctx.body = register.metrics()
ctx.status = 200
}