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

Can't get custom metrics to work in Rails App #53

Closed
mdesanti opened this issue May 4, 2017 · 1 comment
Closed

Can't get custom metrics to work in Rails App #53

mdesanti opened this issue May 4, 2017 · 1 comment

Comments

@mdesanti
Copy link

mdesanti commented May 4, 2017

Hi!

I've configured the gem in a Rails App and default metrics seem to be working fine. However, If I try to do something like this:

  def index
    gauge = Prometheus::Client::Gauge.new(:room_temperature_celsius, '...')
    gauge.set({ room: 'kitchen' }, 21.534)

    result = User.find_by(username: params[:username])
    if result.nil?
      render json: { msg: 'Error user name not found' }, status: :not_found
    else
      render json: result
    end
  end

The metric does not show in /metrics path.

Is there any I'm doing wrong?
Thank you!

@grobie
Copy link
Member

grobie commented May 8, 2017

You did not register the created gauge metric with the registry. See the readme for an explanation.

Metrics shouldn't be created inside of a Rails action method, as these will be called during every request. Instead, register the metrics once and keep a reference to it.

@grobie grobie closed this as completed May 4, 2018
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