From 8324e65597c59ecabe219affea5c64db2d8843ce Mon Sep 17 00:00:00 2001 From: "Dowideit, Sven (O&A, St. Lucia)" Date: Mon, 12 Nov 2018 15:19:09 +1000 Subject: [PATCH] Add the last few lines needed to show a new user how the Collector/Gatherer fits together Signed-off-by: Dowideit, Sven (O&A, St. Lucia) --- prometheus/example_clustermanager_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/prometheus/example_clustermanager_test.go b/prometheus/example_clustermanager_test.go index 9a5a4b8..4cafa55 100644 --- a/prometheus/example_clustermanager_test.go +++ b/prometheus/example_clustermanager_test.go @@ -13,7 +13,13 @@ package prometheus_test -import "github.com/prometheus/client_golang/prometheus" +import ( + "log" + "net/http" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" +) // ClusterManager is an example for a system that might have been built without // Prometheus in mind. It models a central manager of jobs running in a @@ -124,4 +130,13 @@ func ExampleCollector() { // variables to then do something with them. NewClusterManager("db", reg) NewClusterManager("ca", reg) + + // Add the built in process and golang metrics to this registry + reg.MustRegister( + prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}), + prometheus.NewGoCollector(), + ) + + http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{})) + log.Fatal(http.ListenAndServe(":8080", nil)) }