()
| 32 | var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.") |
| 33 | |
| 34 | func main() { |
| 35 | flag.Parse() |
| 36 | |
| 37 | // Create a new registry. |
| 38 | reg := prometheus.NewRegistry() |
| 39 | |
| 40 | // Register metrics from GoCollector collecting statistics from the Go Runtime. |
| 41 | // This enabled default, recommended metrics with the additional, recommended metric for |
| 42 | // goroutine scheduling latencies histogram that is currently bit too expensive for default option. |
| 43 | // |
| 44 | // See the related GopherConUK talk to learn more: https://www.youtube.com/watch?v=18dyI_8VFa0 |
| 45 | reg.MustRegister( |
| 46 | collectors.NewGoCollector( |
| 47 | collectors.WithGoCollectorRuntimeMetrics( |
| 48 | collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/sched/latencies:seconds")}, |
| 49 | ), |
| 50 | ), |
| 51 | ) |
| 52 | |
| 53 | // Expose the registered metrics via HTTP. |
| 54 | http.Handle("/metrics", promhttp.HandlerFor( |
| 55 | reg, |
| 56 | promhttp.HandlerOpts{ |
| 57 | // Opt into OpenMetrics to support exemplars. |
| 58 | EnableOpenMetrics: true, |
| 59 | }, |
| 60 | )) |
| 61 | fmt.Println("Hello world from new Go Collector!") |
| 62 | log.Fatal(http.ListenAndServe(*addr, nil)) |
| 63 | } |
nothing calls this directly
no test coverage detected