Closed NickLarsenNZ closed 2 years ago
I have managed to get metrics to appear in the right place using the LocalClient
. I had to set PROMETHEUS_EXPORTER_PORT
to be the same as METRICS_PORT
.
PROMETHEUS_EXPORTER_PORT=9090 METRICS_PORT=9090 rvm 2.7 do rake jobs:work
I think that means I shouldn't set a server port in the initializer, and control both the server and client port through PROMETHEUS_EXPORTER_PORT
.
I have to run, but I'll try it tonight, and if that works, I'll comment and close the issue.
It seems PROMETHEUS_EXPORTER_PORT
is only for the Client. The server needs to have the port configured, or it falls back to PrometheusExporter::DEFAULT_PORT
.
Client:
Note:
localhost
is used instead ofPrometheusExporter::DEFAULT_BIND_ADDRESS
.
Server:
I think the Server should read the env var like the Client does, but until that happens, here is how I work around it in my initializer:
server = PrometheusExporter::Server::WebServer.new(
bind: ENV.fetch("PROMETHEUS_EXPORTER_HOST") { PrometheusExporter::DEFAULT_BIND_ADDRESS },
port: ENV.fetch("PROMETHEUS_EXPORTER_PORT") { PrometheusExporter::DEFAULT_PORT }
)
server.start
PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
I'm having trouble exposing delayed_job metrics. I would like to use the built in client (
LocalClient
) and a server, rather than running the server in a separate process.Here is how I've setup:
Dummy
articles
controller to trigger a delayed job.config/initializers/prometheus.rb
Run Delayed Job
Run the web server:
Trigger the delayed job by browsing the app
http://localhost:3000/articles/index
I see console output from Delayed Job showing the job completed
Then check both apps metrics ports
No
delayed_job
metrics appear (I do see other metrics).It works with the external prometheus_exporter
Now, if I remove the server and client from
config/initializers/prometheus.rb
, and run the exporter as a separate process:When I visit http://localhost:9394/metrics, I can see the delayed_job metrics:
I notice that these metrics were published even before I stopped and started delayed_job with the exporter server and client removed - so I assume the metrics were populated from code running from the
rails server
.