@@ -24,6 +24,24 @@ import (
2424// NewCollector returns a collector that exports metrics about current version
2525// information.
2626func NewCollector (program string ) prometheus.Collector {
27+ return NewCollectorWithLabels (program , nil )
28+ }
29+
30+ // NewCollectorWithLabels returns a collector that exports metrics about current
31+ // version information and allows to set additional custom labels.
32+ func NewCollectorWithLabels (program string , labels prometheus.Labels ) prometheus.Collector {
33+
34+ constLabels := prometheus.Labels {
35+ "version" : version .Version ,
36+ "revision" : version .GetRevision (),
37+ "branch" : version .Branch ,
38+ "goversion" : version .GoVersion ,
39+ "goos" : version .GoOS ,
40+ "goarch" : version .GoArch ,
41+ "tags" : version .GetTags (),
42+ }
43+ maps .Copy (constLabels , labels )
44+
2745 return prometheus .NewGaugeFunc (
2846 prometheus.GaugeOpts {
2947 Namespace : program ,
@@ -32,16 +50,9 @@ func NewCollector(program string) prometheus.Collector {
3250 "A metric with a constant '1' value labeled by version, revision, branch, goversion from which %s was built, and the goos and goarch for the build." ,
3351 program ,
3452 ),
35- ConstLabels : prometheus.Labels {
36- "version" : version .Version ,
37- "revision" : version .GetRevision (),
38- "branch" : version .Branch ,
39- "goversion" : version .GoVersion ,
40- "goos" : version .GoOS ,
41- "goarch" : version .GoArch ,
42- "tags" : version .GetTags (),
43- },
53+ ConstLabels : constLabels ,
4454 },
4555 func () float64 { return 1 },
4656 )
57+
4758}
0 commit comments