Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main(logger: Logger): Promise {
// Collect process metrics
promClient.collectDefaultMetrics({ prefix: 'lsif_' })
// Read configuration from frontend
const fetchConfiguration = await waitForConfiguration(logger)
// Configure distributed tracing
const tracer = createTracer('lsif-server', fetchConfiguration())
// Update cache capacities on startup
metrics.connectionCacheCapacityGauge.set(settings.CONNECTION_CACHE_CAPACITY)
metrics.documentCacheCapacityGauge.set(settings.DOCUMENT_CACHE_CAPACITY)
metrics.resultChunkCacheCapacityGauge.set(settings.RESULT_CHUNK_CACHE_CAPACITY)
// Ensure storage roots exist
await ensureDirectory(settings.STORAGE_ROOT)
await ensureDirectory(path.join(settings.STORAGE_ROOT, constants.DBS_DIR))
await ensureDirectory(path.join(settings.STORAGE_ROOT, constants.TEMP_DIR))
constructor(options: MetricsOptions) {
this.options = options
const metricsOptions: DefaultMetricsCollectorConfiguration = {
prefix: options.prefix,
labels: options.labels,
}
this.client = prometheus
this.registry = prometheus.register
// Collect default metrics (event loop lag, memory, file descriptors etc.)
collectDefaultMetrics(metricsOptions)
}
}
async function main(logger: Logger): Promise {
// Collect process metrics
promClient.collectDefaultMetrics({ prefix: 'lsif_' })
// Read configuration from frontend
const fetchConfiguration = await waitForConfiguration(logger)
// Configure distributed tracing
const tracer = createTracer('lsif-worker', fetchConfiguration())
// Ensure storage roots exist
await ensureDirectory(settings.STORAGE_ROOT)
await ensureDirectory(path.join(settings.STORAGE_ROOT, constants.DBS_DIR))
await ensureDirectory(path.join(settings.STORAGE_ROOT, constants.TEMP_DIR))
await ensureDirectory(path.join(settings.STORAGE_ROOT, constants.UPLOADS_DIR))
// Create database connection and entity wrapper classes
const connection = await createPostgresConnection(fetchConfiguration(), logger)
const dumpManager = new DumpManager(connection, settings.STORAGE_ROOT)
public static create({ service, logger = DEFAULT_LOGGER, tracer, spanLogLevel }: NodeMonitorCreate): NodeMonitor {
prom.collectDefaultMetrics({ timeout: 4000 });
return new NodeMonitor({
service,
component: service,
logger,
tracer,
// Perfhooks is broken in 8.9 - there's no way to get the current
// high resolution timestamp. Fix is in 9.8.0.
now: () => Date.now(),
spanLogLevel,
});
}
'use strict'
const express = require('express')
const Prometheus = require('prom-client')
const app = express()
const port = process.env.PORT || 3001
const metricsInterval = Prometheus.collectDefaultMetrics()
const checkoutsTotal = new Prometheus.Counter({
name: 'checkouts_total',
help: 'Total number of checkouts',
labelNames: ['payment_method']
})
const httpRequestDurationMicroseconds = new Prometheus.Histogram({
name: 'http_request_duration_ms',
help: 'Duration of HTTP requests in ms',
labelNames: ['method', 'route', 'code'],
buckets: [0.10, 5, 15, 50, 100, 200, 300, 400, 500] // buckets for response time from 0.1ms to 500ms
})
// Runs before each requests
app.use((req, res, next) => {
res.locals.startEpoch = Date.now()
next()
import client from 'prom-client';
import connect from 'connect';
import http from 'http';
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';
import { Info } from '../../../utils';
import { Migrations } from '../../../migrations';
import { settings } from '../../../settings';
import { Statistics } from '../../../models';
client.collectDefaultMetrics();
export const metrics = {};
metrics.meteorMethods = new client.Summary({
name: 'rocketchat_meteor_methods',
help: 'summary of meteor methods count and time',
labelNames: ['method', 'has_connection', 'has_user'],
});
metrics.rocketchatCallbacks = new client.Summary({
name: 'rocketchat_callbacks',
help: 'summary of rocketchat callbacks count and time',
labelNames: ['hook', 'callback'],
});
metrics.rocketchatHooks = new client.Summary({
defaultOpts.register = register;
opts.histogram.registers = [register];
opts.summary.registers = [register];
}
if (prefix) {
defaultOpts.prefix = prefix;
opts.histogram.name = `${prefix}${opts.histogram.name}`;
opts.summary.name = `${prefix}${opts.summary.name}`;
}
Object.keys(metrics)
.filter(opts.hasOwnProperty.bind(opts))
.forEach((key) => {
Object.assign(opts[key], metrics[key]);
});
client.collectDefaultMetrics(defaultOpts);
const routeHist = new client.Histogram(opts.histogram);
const routeSum = new client.Summary(opts.summary);
if (endpoint) {
fastify.route({
url: endpoint,
method: 'GET',
schema: {hide: true},
handler: (_, reply) => {
const data = register
? register.metrics()
: client.register.metrics();
reply.type('text/plain').send(data);
},
});
}
didStart(app: BaseApp, pluginContext: PluginContext) {
this.prometheusTimer = prometheus.collectDefaultMetrics();
prometheus.register.setDefaultLabels({ app: app.getConfig('app.name', 'not_set') });
const startGcStats = gcStats();
startGcStats();
this.registerOSMetrics(app);
const context = app.getContext();
const adminExpress: e.Express = pluginContext.get(AdminPortPlugin.CONTEXT_APP_KEY);
if (adminExpress) {
Logger.info('Registering metrics endpoint in Admin port');
adminExpress.get('/metrics', async (req, res) => {
NewrelicUtil.setIgnoreTransaction(true);
res.type('text/plain');
res.send(prometheus.register.metrics());
});
}
}
help: `duration summary of http responses labeled with: ${labelNames.join(', ')}`,
labelNames,
percentiles: this.options.quantileBuckets,
maxAgeSeconds: this.options.quantileMaxAge,
ageBuckets: this.options.quantileAgeBuckets,
}));
}
if (this.options.enableDurationHistogram) {
this.durationMetrics.push(new promClient.Histogram({
name: this.options.durationHistogramName,
help: `duration histogram of http responses labeled with: ${labelNames.join(', ')}`,
labelNames,
buckets: this.options.timeBuckets,
}));
}
promClient.collectDefaultMetrics();
this.router.get('/metrics', this.metricsRoute.bind(this));
this.router.use(this.trackDuration.bind(this));
return this.router;
}
function bindPrometheus (app) {
app.controls['/prometheus'] = {
request () {
return {
headers: {
'Content-Type': prometheus.register.contentType
},
body: prometheus.register.metrics()
}
}
}
if (app.options.controlPassword) {
prometheus.collectDefaultMetrics()
app.log.on('add', action => {
actionsCount.inc({ type: action.type })
})
app.on('processed', (action, meta, latency) => {
requestsCount.inc({ type: action.type })
processingTime.observe(latency)
})
app.on('subscribed', (action, meta, latency) => {
subscriptionsCount.inc()
subscribingTime.observe(latency)
})
app.on('subscriptionCancelled', () => {
cancelCount.inc()
})
app.on('connected', () => {
clientCount.set(Object.keys(app.connected).length)