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

Is there any way to stop UpdatePrometheusMetrics? #19

Open
nickylogan opened this issue Jul 20, 2020 · 3 comments
Open

Is there any way to stop UpdatePrometheusMetrics? #19

nickylogan opened this issue Jul 20, 2020 · 3 comments

Comments

@nickylogan
Copy link

I'm trying to collect metrics of my service into prometheus using this rough implementation:

pc := prometheusmetrics.NewPrometheusProvider(someRegistry, someNameSpace, someSubSystem, prometheus.DefaultRegisterer, time.Second)
go pc.UpdatePrometheusMetrics()

http.Handle("/metrics", promhttp.Handler())
err := http.ListenAndServe(":8080", nil)
if err != nil {
	// stop UpdatePrometheusMetrics
}

Is there any way to stop UpdatePrometheusMetrics()? I don't want to leak an unnecessary goroutine if the endpoint is not even accessible.

@deathowl
Copy link
Owner

Hey @nickylogan . So basically it's a goroutine. If you want to stop it you could do something like that
https://yourbasic.org/golang/stop-goroutine/

@nickylogan
Copy link
Author

Hi @deathowl, thanks for replying. I don't think my question is understood quite correctly.

Internally, pc.UpdatePrometheusMetrics() runs an infinite ticker calling UpdatePrometheusMetricsOnce(). What I'm saying is, is there a method to stop the infinite ticker?

@deathowl
Copy link
Owner

Ah thanks for the clarification. I'll add that tonight

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