Open yoonsio opened 2 years ago
Prometheus CachedReporter provides a handler for metrics endpoint. It is useful to have the ability to access baseReporter from Scope so that the handler method can be called from the top level.
func getScope() (tally.Scope, io.Closer, error) { r := promreporter.NewReporter(promreporter.Options{}) scope, closer := tally.NewRootScope(tally.ScopeOptions{ Prefix: "my_service", Tags: map[string]string{}, CachedReporter: r, Separator: promreporter.DefaultSeparator, }, 1*time.Second) return scope, closer, nil } func main() { scope, closer, _ := getScope() // TODO: get the http handler from the scope r, _, := scope.BaseReporter.(promreporter.Reporter) http.Handle("/metrics", r.HTTPHandler()) fmt.Printf("Serving :8080/metrics\n") fmt.Printf("%v\n", http.ListenAndServe(":8080", nil)) }
Prometheus CachedReporter provides a handler for metrics endpoint. It is useful to have the ability to access baseReporter from Scope so that the handler method can be called from the top level.