Skip to content

Commit f6443e7

Browse files
authored
Merge pull request #495 from SvenDowideit/add-extra-hints-to-clustermanager-example
Add the last few lines needed to show a new user how the Collector/Gatherer fits together
2 parents 9d73466 + 8324e65 commit f6443e7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

prometheus/example_clustermanager_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313

1414
package prometheus_test
1515

16-
import "github.com/prometheus/client_golang/prometheus"
16+
import (
17+
"log"
18+
"net/http"
19+
20+
"github.com/prometheus/client_golang/prometheus"
21+
"github.com/prometheus/client_golang/prometheus/promhttp"
22+
)
1723

1824
// ClusterManager is an example for a system that might have been built without
1925
// Prometheus in mind. It models a central manager of jobs running in a
@@ -124,4 +130,13 @@ func ExampleCollector() {
124130
// variables to then do something with them.
125131
NewClusterManager("db", reg)
126132
NewClusterManager("ca", reg)
133+
134+
// Add the built in process and golang metrics to this registry
135+
reg.MustRegister(
136+
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
137+
prometheus.NewGoCollector(),
138+
)
139+
140+
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{}))
141+
log.Fatal(http.ListenAndServe(":8080", nil))
127142
}

0 commit comments

Comments
 (0)