yabeda-rb / yabeda-rails

Yabeda plugin to collect basic metrics for Rails applications
MIT License
154 stars 19 forks source link

Metrics not collected #29

Open Pegorino82 opened 5 months ago

Pegorino82 commented 5 months ago

Hi! I use yabeda-rb + yabeda-rails + yabeda-sidekiq

gem 'yabeda'
gem 'yabeda-rails'
gem 'yabeda-sidekiq'
gem 'yabeda-prometheus'
gem "prometheus-client" 

on /metrics i see all of rails, sidekiq and my custom metrics

# HELP sidekiq_jobs_waiting_count The number of jobs waiting to process in sidekiq.
sidekiq_jobs_waiting_count{queue="default"} 12.0
...
# TYPE rails_requests_total counter
# HELP rails_requests_total A counter of the total number of HTTP requests rails processed.
rails_requests_total{controller="...",action="...",status="200",format="json",method="post"} 2.0
...
# TYPE git_git_tag gauge
# HELP git_git_tag Current git tag of the application.
git_git_tag{tag="..."} 1.0

but when i call

Yabeda.collect!
Prometheus::Client::Push.new(job: JOB_NAME, gateway: PROMETHEUS_URL).add(Yabeda::Prometheus.registry)

it pushes only sidekiq + default metrics, for rails metrics are not collected

...
# TYPE rails_requests_total counter
# HELP rails_requests_total A counter of the total number of HTTP requests rails processed.
# TYPE rails_request_duration_seconds histogram
# HELP rails_request_duration_seconds A histogram of the response latency.
# TYPE rails_view_runtime_seconds histogram
# HELP rails_view_runtime_seconds A histogram of the view rendering time.
# TYPE rails_db_runtime_seconds histogram
# HELP rails_db_runtime_seconds A histogram of the activerecord execution time.
...

in console it looks like

pry(main)> Yabeda.collect!
Cache read: metrics ({:compress=>true, :compress_threshold=>1024, :expires_in=>15 minutes})
Cache generate: metrics ({:compress=>true, :compress_threshold=>1024, :expires_in=>15 minutes})
Cache write: metrics ({:compress=>true, :compress_threshold=>1024, :expires_in=>15 minutes})
=> [#<Proc:0x00007f9d42be01b8 /usr/local/bundle/gems/yabeda-sidekiq-0.12.0/lib/yabeda/sidekiq.rb:67>,
 #<Proc:0x00007f9d42bf68f0 .../config/initializers/yabeda_metrics.rb:11>,
 #<Proc:0x00007f9d42bf5450 .../initializers/yabeda_metrics.rb:23>]

is there way to correctly collect all metrics for pushgateway?

zaibacu commented 3 weeks ago

While documentation says, that these metrics are installed by default, I needed to add initializer with Yabeda::Rails.install! to make it work