swagger-stats icon indicating copy to clipboard operation
swagger-stats copied to clipboard

Allow Setting Prom Registry For Swagger-stats Metrics

Open thealphadollar opened this issue 4 years ago • 1 comments

Thanks a lot for creating this useful library. I wanted to use it with my application which uses clustering and GraphQL metrics. I tried the script present at Scraping with multiple PM2 processes, and mysteriously it did not work and my entire process freezer - I ended up using Aggregation using default prom registry and express-prom-bundle middleware because it supports passing in register to be used. The code snippet for the same is below,

import { AggregatorRegistry, register } from 'prom-client';

const app = express();
const aggregatorRegistry = new AggregatorRegistry();
// register for prometheus
app.get('/metrics', async (_, res) => {
    const metrics = await getAggregateMetrics();
    res.set('Content-Type', aggregatorRegistry.contentType);
    res.send(metrics.metrics());
});
// metrics for graphql requests
const apolloMetricsPlugin = createMetricsPlugin(register);
// metrics for rest requests
app.use(
    promBundle({
        autoregister: false, // disable /metrics for single workers
        includeMethod: true,
        includeStatusCode: true,
        includePath: true,
        promRegistry: register,
    }),
);

I was wondering if a similar approach can be used to allow passing register into the swagger-stats client and use the same register when collecting metrics? This would make the metrics API much more flexible, especially for developers who want to see all metrics collected by various exporters at the same register and, consequently, at the same metrics endpoint. I'm looking for a configuration as follows:

app.use(swStats.getMiddleware({
    promRegistry: register
}));

PS. If we find that we want to implement this feature, I would be glad to raise PR for the same.

thealphadollar avatar Aug 27 '20 15:08 thealphadollar

@thealphadollar where does getAggregateMetrics() is called from in const metrics = await getAggregateMetrics();

GajenderI avatar Apr 28 '23 10:04 GajenderI