discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
538 stars 156 forks source link

PrometheusExporter Server with graphql_collector as rails initializer #308

Closed jonathan-anyword closed 9 months ago

jonathan-anyword commented 9 months ago

Hi, In graphql-ruby prometheus implementation the docs ask to run the exporter with the command: bundle exec prometheus_exporter -a lib/graphql_collector.rb

This server exporter have the option to run as rails initializer with: PrometheusExporter::Server::WebServer.new

Is it possible to run the server from the main process flow with the graphql_collector without the need of the bundle exec command?

jonathan-anyword commented 9 months ago

Found solution:

  collector = PrometheusExporter::Server::Collector.new
  require 'graphql/tracing/prometheus_tracing/graphql_collector'
  collector.register_collector(GraphQL::Tracing::PrometheusTracing::GraphQLCollector.new)

  server = PrometheusExporter::Server::WebServer.new bind: '0.0.0.0',
                                                     port: PROMETHEUS_METRICS_PORT,
                                                     collector: collector
  server.start