client_ruby icon indicating copy to clipboard operation
client_ruby copied to clipboard

Support metric timestamps

Open santiagordguez opened this issue 8 years ago • 12 comments

Hi,

I'm using client_ruby to create/set counter and gauge metrics but i don't see in the prometheus library an option to specify a timestamp.

Is this not possibly?

santiagordguez avatar Apr 04 '17 09:04 santiagordguez

Any such implementation is currently dependent on https://github.com/prometheus/prometheus/issues/398

brian-brazil avatar Apr 04 '17 09:04 brian-brazil

any update ? I see https://github.com/prometheus/prometheus/issues/398 is closed

NitinRanjan avatar Jan 15 '19 07:01 NitinRanjan

Hi @srodriguezOPT. Sorry for the late response to this... I'd like to understand this request better.

Is this a method that sets a gauge to Time.now.to_i (as suggested by the set_to_current_time method in the best practices doc )? Or have I misunderstood the issue?

dmagliola avatar Jul 30 '19 14:07 dmagliola

We've just hit this with @carlhoerberg. We want the metrics exposed to set the timestamp, as captured in the exposition formats doc:

metric_name [
  "{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
] value [ timestamp ]

Are you open to PRs?

gerhard avatar Nov 12 '19 22:11 gerhard

It doesn't make sense to add this until this client supports custom collectors, as there's no valid use cases for it with just direct instrumentation. You can use Go/Java/Python if you need this.

brian-brazil avatar Nov 12 '19 22:11 brian-brazil

This functionality does make sense for our use-case. Maybe we are doing it wrong. How would you recommend we do the following in Ruby?

Given an internal telemetry system, we need a proxy that translates and exposes a subset of telemetry metrics via a public HTTP API, in Prometheus exposition format. The requirement is to expose the original metric timestamp, as recorded in this internal telemetry system.

As a short-term solution, we are using the following metric: last_updated_at 1573654301

Can you think of a better approach?

gerhard avatar Nov 13 '19 14:11 gerhard

I'd recommend not using Ruby, as the client library isn't in a place to support that. You should use a different language, the influxdb/graphite/collectd exporters should provide inspiration.

brian-brazil avatar Nov 13 '19 14:11 brian-brazil

This looks good @carlhoerberg

gerhard avatar Nov 13 '19 15:11 gerhard

@brian-brazil I'd like to understand better this concept of Custom Collectors... The way I understand this, you'd do this by basically subclassic either Metric, and implementing a values method that does whatever it needs to do to get the values that you want to report, correct?

Am I missing something? I feel like I don't fully understand this conversation, and the "we need Custom Collectors" comment comes up a lot...

dmagliola avatar Nov 13 '19 21:11 dmagliola

In theory, however it looks like this client library currently very tightly binds exposition to direct instrumentation (not an uncommon thing) and thus custom collectors aren't possible currently.

brian-brazil avatar Nov 14 '19 00:11 brian-brazil

Could you expand a little bit on what that means, please?

dmagliola avatar Nov 14 '19 08:11 dmagliola

This client library only supports the metric types that it comes with, not generic collectors that can return multiple different types of metric which you need to write an exporter.

brian-brazil avatar Nov 14 '19 09:11 brian-brazil