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
This commit is contained in:
Björn Rabenstein 2018-11-20 13:35:42 +01:00 committed by GitHub
commit f6443e74d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -13,7 +13,13 @@
package prometheus_test 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 // 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 // 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. // variables to then do something with them.
NewClusterManager("db", reg) NewClusterManager("db", reg)
NewClusterManager("ca", 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))
} }