| 1 |
// Copyright 2016 The Prometheus Authors |
| 2 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 |
// you may not use this file except in compliance with the License. |
| 4 |
// You may obtain a copy of the License at |
| 5 |
// |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package version |
| 15 |
|
| 16 |
import ( |
| 17 |
"fmt" |
| 18 |
|
| 19 |
"github.com/prometheus/common/version" |
| 20 |
|
| 21 |
"github.com/prometheus/client_golang/prometheus" |
| 22 |
) |
| 23 |
|
| 24 |
// NewCollector returns a collector that exports metrics about current version |
| 25 |
// information. |
| 26 |
func NewCollector(program string) prometheus.Collector { |
| 27 |
return prometheus.NewGaugeFunc( |
| 28 |
prometheus.GaugeOpts{ |
| 29 |
Namespace: program, |
| 30 |
Name: "build_info", |
| 31 |
Help: fmt.Sprintf( |
| 32 |
"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.", |
| 33 |
program, |
| 34 |
), |
| 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 |
}, |
| 44 |
}, |
| 45 |
func() float64 { return 1 }, |
| 46 |
) |
| 47 |
} |