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

Missing documentation on combination of autoregister false and metricsApp #103

Open
ArktinenSieni opened this issue Aug 17, 2022 · 2 comments

Comments

@ArktinenSieni
Copy link

Hey! In #101 there were additional options added, but they're missing examples. I am unsure how I should use combination of autoregister and metricsApp. I could use the suggestions in #25 , but I'd rather use the options presented in the #101 PR.

@Routhinator
Copy link

Also confused here, not sure if we just pass true in or an app instance..

@Routhinator
Copy link

Looks like an app instance. My solution that worked:

export function metrics(): express.Express {
  const metricsAppInstance = express();
 // do stuff if you like
  return metricsAppInstance
}

// The Express app is exported so that it can be used by serverless Functions.
export function app(metricsAppInstance: express.Express): express.Express {
  const server = express();
...
  // Prometheus Setup
  server.use(
    '*',
    promBundle({
      buckets: [0.10, 5, 15, 50, 100, 200, 300, 400, 500],
      includeMethod: true,
      includePath: true,
      customLabels: {
        app: 'angular-express-ssr'
      },
      autoregister: false,
      metricsPath: '/metrics',
      metricsApp: metricsAppInstance,
      promClient: {
        collectDefaultMetrics: {}
      },
    })
  );
...
return server;
}

function run(): void {
  const port = config.get('server.port') || 4000;
  const metricsPort = config.get('metrics.port') || 4001;

  const metricsServer = metrics();
  // Start up the Node server
  const server = app(metricsServer);
  metricsServer.listen(metricsPort, ()=>{
    console.log(`Node Express Prometheus Exporter listening on http://localhost:${metricsPort}`);
  })
  server.listen(port, () => {
    console.log(`Node Express server listening on http://localhost:${port}`);
  });
}

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

No branches or pull requests

2 participants