diff options
author | Steve Durrheimer <s.durrheimer@gmail.com> | 2016-04-30 19:58:17 +0200 |
---|---|---|
committer | Steve Durrheimer <s.durrheimer@gmail.com> | 2016-05-04 08:43:33 +0200 |
commit | 60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037 (patch) | |
tree | 594b54b417bfb9da1ab4cdd0eff21d7a57777f08 /vendor | |
parent | d890b63fb5ebf6144766cd43bf29f0a0e6192491 (diff) | |
download | prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.tar.bz2 prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.tar.xz prometheus_node_collector-60cbc9efc0ff3a5c25394aeaef0c8df3ebad7037.zip |
Make version informations consistent between prometheus components
This also fixes #231 by adding the '-version' flag
Diffstat (limited to 'vendor')
-rw-r--r-- | vendor/github.com/prometheus/common/version/info.go | 89 | ||||
-rw-r--r-- | vendor/vendor.json | 9 |
2 files changed, 97 insertions, 1 deletions
diff --git a/vendor/github.com/prometheus/common/version/info.go b/vendor/github.com/prometheus/common/version/info.go new file mode 100644 index 0000000..84489a5 --- /dev/null +++ b/vendor/github.com/prometheus/common/version/info.go | |||
@@ -0,0 +1,89 @@ | |||
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 | "bytes" | ||
18 | "fmt" | ||
19 | "runtime" | ||
20 | "strings" | ||
21 | "text/template" | ||
22 | |||
23 | "github.com/prometheus/client_golang/prometheus" | ||
24 | ) | ||
25 | |||
26 | // Build information. Populated at build-time. | ||
27 | var ( | ||
28 | Version string | ||
29 | Revision string | ||
30 | Branch string | ||
31 | BuildUser string | ||
32 | BuildDate string | ||
33 | GoVersion = runtime.Version() | ||
34 | ) | ||
35 | |||
36 | // NewCollector returns a collector which exports metrics about current version information. | ||
37 | func NewCollector(program string) *prometheus.GaugeVec { | ||
38 | buildInfo := prometheus.NewGaugeVec( | ||
39 | prometheus.GaugeOpts{ | ||
40 | Namespace: program, | ||
41 | Name: "build_info", | ||
42 | Help: fmt.Sprintf( | ||
43 | "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.", | ||
44 | program, | ||
45 | ), | ||
46 | }, | ||
47 | []string{"version", "revision", "branch", "goversion"}, | ||
48 | ) | ||
49 | buildInfo.WithLabelValues(Version, Revision, Branch, GoVersion).Set(1) | ||
50 | return buildInfo | ||
51 | } | ||
52 | |||
53 | // versionInfoTmpl contains the template used by Info. | ||
54 | var versionInfoTmpl = ` | ||
55 | {{.program}}, version {{.version}} (branch: {{.branch}}, revision: {{.revision}}) | ||
56 | build user: {{.buildUser}} | ||
57 | build date: {{.buildDate}} | ||
58 | go version: {{.goVersion}} | ||
59 | ` | ||
60 | |||
61 | // Print returns version information. | ||
62 | func Print(program string) string { | ||
63 | m := map[string]string{ | ||
64 | "program": program, | ||
65 | "version": Version, | ||
66 | "revision": Revision, | ||
67 | "branch": Branch, | ||
68 | "buildUser": BuildUser, | ||
69 | "buildDate": BuildDate, | ||
70 | "goVersion": GoVersion, | ||
71 | } | ||
72 | t := template.Must(template.New("version").Parse(versionInfoTmpl)) | ||
73 | |||
74 | var buf bytes.Buffer | ||
75 | if err := t.ExecuteTemplate(&buf, "version", m); err != nil { | ||
76 | panic(err) | ||
77 | } | ||
78 | return strings.TrimSpace(buf.String()) | ||
79 | } | ||
80 | |||
81 | // Info returns version, branch and revision information. | ||
82 | func Info() string { | ||
83 | return fmt.Sprintf("(version=%s, branch=%s, revision=%s)", Version, Branch, Revision) | ||
84 | } | ||
85 | |||
86 | // BuildContext returns goVersion, buildUser and buildDate information. | ||
87 | func BuildContext() string { | ||
88 | return fmt.Sprintf("(go=%s, user=%s, date=%s)", GoVersion, BuildUser, BuildDate) | ||
89 | } | ||
diff --git a/vendor/vendor.json b/vendor/vendor.json index a1c8650..edd27bb 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json | |||
@@ -73,6 +73,12 @@ | |||
73 | "revisionTime": "2016-01-04T14:47:38+01:00" | 73 | "revisionTime": "2016-01-04T14:47:38+01:00" |
74 | }, | 74 | }, |
75 | { | 75 | { |
76 | "checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=", | ||
77 | "path": "github.com/prometheus/common/version", | ||
78 | "revision": "dd586c1c5abb0be59e60f942c22af711a2008cb4", | ||
79 | "revisionTime": "2016-05-03T22:05:32Z" | ||
80 | }, | ||
81 | { | ||
76 | "path": "github.com/prometheus/procfs", | 82 | "path": "github.com/prometheus/procfs", |
77 | "revision": "406e5b7bfd8201a36e2bb5f7bdae0b03380c2ce8", | 83 | "revision": "406e5b7bfd8201a36e2bb5f7bdae0b03380c2ce8", |
78 | "revisionTime": "2015-10-29T15:50:50-04:00" | 84 | "revisionTime": "2015-10-29T15:50:50-04:00" |
@@ -87,5 +93,6 @@ | |||
87 | "revision": "833a04a10549a95dc34458c195cbad61bbb6cb4d", | 93 | "revision": "833a04a10549a95dc34458c195cbad61bbb6cb4d", |
88 | "revisionTime": "2015-12-10T17:34:15-08:00" | 94 | "revisionTime": "2015-12-10T17:34:15-08:00" |
89 | } | 95 | } |
90 | ] | 96 | ], |
97 | "rootPath": "github.com/prometheus/node_exporter" | ||
91 | } | 98 | } |