Build using ldflags, for example: go build -ldflags "-X github.com/prometheus/common/version.Version=1.0.0 -X github.com/prometheus/common/version.Branch=abc123" .
()
| 33 | // Build using ldflags, for example: |
| 34 | // go build -ldflags "-X github.com/prometheus/common/version.Version=1.0.0 -X github.com/prometheus/common/version.Branch=abc123" . |
| 35 | func main() { |
| 36 | flag.Parse() |
| 37 | |
| 38 | // Create a new registry. |
| 39 | reg := prometheus.NewRegistry() |
| 40 | |
| 41 | // Register version collector. |
| 42 | reg.MustRegister(version.NewCollector("example")) |
| 43 | |
| 44 | // Expose the registered metrics via HTTP. |
| 45 | http.Handle("/metrics", promhttp.HandlerFor( |
| 46 | reg, |
| 47 | promhttp.HandlerOpts{}, |
| 48 | )) |
| 49 | fmt.Println("Hello world from new Version Collector!") |
| 50 | log.Fatal(http.ListenAndServe(*addr, nil)) |
| 51 | } |
nothing calls this directly
no test coverage detected