Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Setting Prom Registry For Swagger-stats Metrics #114

Open
thealphadollar opened this issue Aug 27, 2020 · 1 comment
Open

Allow Setting Prom Registry For Swagger-stats Metrics #114

thealphadollar opened this issue Aug 27, 2020 · 1 comment
Assignees

Comments

@thealphadollar
Copy link

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.

@GajenderI
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants