bfmatei / apollo-prometheus-exporter

Plugin for Apollo Server to export metrics in Prometheus format

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support clustering mode

lala7573 opened this issue · comments

I can add multiple worker but it expose only one worker metrics at a time.
How can I support the cluster mode using this plugin?

I checked out the code, and find out that this library doesn't support AggregatorRegistry which is for clustering.
Who looking for the way can follow the steps below. It works.

  1. Use createPrometheusExporterPlugin with each new registry and registry to AggregatorRegistry
  • In worker,
const registry = new Registry();

createPrometheusExporterPlugin({ ..., register: registry, defaultMetrics: true, defaultMetricsOption: { register: registry }})
AggregatorRegistry.setRegistry(registry)
  1. In master, I opened a new metrics server to expose aggregatorRegistry.
const registry = new AggregatorRegistry();
const metricsApp = express()
metricsApp.get('/metrics', async (req, res) => {
  try {
	  const metrics = await aggregatorRegistry.clusterMetrics();
	  res.set('Content-Type', aggregatorRegistry.contentType);
	  res.send(metrics);
  } catch (ex) {
	  res.status(500);
	  res.send(ex.message);
  }
  res.end()
});

metricsApp.listen({another port})

https://github.com/siimon/prom-client/tree/master#usage-with-nodejss-cluster-module