question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow setting counter value when exposing existing counts

See original GitHub issue

I am just started to use prometheus, and your library and have come across this issue.

Counter only allows you to increase the value which is fine if you actually using it to count things but breaks down if you have an existing counter you are trying to expose though prometheus.

E.g. the DotNetStatsCollector seems to increment based on a calculated diff. _cpuTotal.Inc(_process.TotalProcessorTime.TotalSeconds - _cpuTotal.Value); This looks like a race condition to me as I cannot see anything stopping two scrapes occurring at the same time. In fact as I understand it multiple parallel scrapes is the preferred way to achive high availability of the prometheus server.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gambrosecommented, Jan 29, 2018

@sandersaares I took a look at the go client (I do not use go so I could be wrong). They had a set method on counter but it was removed in favour of using a ConstantMetric that is just used when creating a custom collector.

https://github.com/prometheus/client_golang/blob/b49b54cdb5f9850eb4c0090e5f9a8b3fc5113d5d/prometheus/value.go#L81

1reaction
godefroicommented, Jan 29, 2018

I have no experience with any other Prometheus client libraries. I think that #73 expresses a sufficient resolution; if it were clear how to create a custom class that could report to Prometheus that it was a counter, but in fact behave from an API perspective as a gauge, then I would be satisfied. Windows performance counters are the obvious use case here, but it’s quite possible that there are others. While I would love to rewrite all my software to expose metrics directly instead of relying on performance counters, in reality I have >150 environments all running various versions of my products, and updating each version to expose metrics to Prometheus is a gargantuan task that will realistically take years. I would like to use Prometheus as best I can in the mean time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to map a count() value from a QueryAlias in Exposed
Just define a count "column" before the query. Here is an example: val count = FooTable.status.count().alias("count") FooTable ...
Read more >
How to add results count in exposed filter? - Drupal Answers
I have a view with some better exposed filter and I'd like to add the count of items for each filter like this...
Read more >
Metric types
Do not use a counter to expose a value that can decrease. For example, do not use a counter for the number of...
Read more >
An Introduction to Atomic Variables in Java
Learn how to use atomic variables for solving concurrency issues.
Read more >
Add statefulness to apps - Streamlit Docs
Let's call our script counter.py . It initializes a count variable and has a button to increment the value stored in the count...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found