@@ -36,7 +36,7 @@ type goCollector struct {
3636 msMaxAge time.Duration // Maximum allowed age of old memstats.
3737}
3838
39- // NewGoCollector returns a collector which exports metrics about the current Go
39+ // NewGoCollector returns a collector that exports metrics about the current Go
4040// process. This includes memory stats. To collect those, runtime.ReadMemStats
4141// is called. This requires to “stop the world”, which usually only happens for
4242// garbage collection (GC). Take the following implications into account when
@@ -364,3 +364,33 @@ type memStatsMetrics []struct {
364364 eval func (* runtime.MemStats ) float64
365365 valType ValueType
366366}
367+
368+ // NewBuildInfoCollector returns a collector collecting a single metric
369+ // "go_build_info" with the constant value 1 and three labels "path", "version",
370+ // and "checksum". Their label values contain the main module path, version, and
371+ // checksum, respectively. The labels will only have meaningful values if the
372+ // binary is built with Go module support and from source code retrieved from
373+ // the source repository (rather than the local file system). This is usually
374+ // accomplished by building from outside of GOPATH, specifying the full address
375+ // of the main package, e.g. "GO111MODULE=on go run
376+ // github.com/prometheus/client_golang/examples/random". If built without Go
377+ // module support, all label values will be "unknown". If built with Go module
378+ // support but using the source code from the local file system, the "path" will
379+ // be set appropriately, but "checksum" will be empty and "version" will be
380+ // "(devel)".
381+ //
382+ // This collector uses only the build information for the main module. See
383+ // https://github.com/povilasv/prommod for an example of a collector for the
384+ // module dependencies.
385+ func NewBuildInfoCollector () Collector {
386+ path , version , sum := readBuildInfo ()
387+ c := & selfCollector {MustNewConstMetric (
388+ NewDesc (
389+ "go_build_info" ,
390+ "Build information about the main Go module." ,
391+ nil , Labels {"path" : path , "version" : version , "checksum" : sum },
392+ ),
393+ GaugeValue , 1 )}
394+ c .init (c .self )
395+ return c
396+ }
0 commit comments