Skip to content

Commit 6bec0d3

Browse files
committed
use a const metric for build_info
Signed-off-by: Michael Crosby <[email protected]>
1 parent ae27a6b commit 6bec0d3

3 files changed

Lines changed: 5 additions & 99 deletions

File tree

cmd/containerd/command/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/containerd/containerd/defaults"
3131
"github.com/containerd/containerd/errdefs"
3232
"github.com/containerd/containerd/log"
33-
"github.com/containerd/containerd/metrics"
33+
_ "github.com/containerd/containerd/metrics" // import containerd build info
3434
"github.com/containerd/containerd/mount"
3535
"github.com/containerd/containerd/services/server"
3636
srvconfig "github.com/containerd/containerd/services/server/config"
@@ -219,7 +219,6 @@ can be used and modified as necessary as a custom configuration.`
219219
serve(ctx, l, server.ServeDebug)
220220
}
221221
if config.Metrics.Address != "" {
222-
metrics.Register()
223222
l, err := net.Listen("tcp", config.Metrics.Address)
224223
if err != nil {
225224
return errors.Wrapf(err, "failed to get listener for metrics endpoint")

metrics/buildinfo.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

metrics/metrics.go

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,13 @@
1717
package metrics
1818

1919
import (
20+
"github.com/containerd/containerd/version"
2021
goMetrics "github.com/docker/go-metrics"
21-
"github.com/prometheus/client_golang/prometheus"
2222
)
2323

24-
// Collector provides the ability to collect generic metrics and export
25-
// them in the prometheus format
26-
type Collector struct {
27-
ns *goMetrics.Namespace
28-
m metric
29-
}
30-
31-
type metric struct {
32-
name string
33-
help string
34-
unit goMetrics.Unit
35-
vt prometheus.ValueType
36-
labels []string
37-
// getValues returns the value and labels for the data
38-
getValues func() []value
39-
}
40-
41-
type value struct {
42-
v float64
43-
l []string
44-
}
45-
46-
// Describe prometheus metrics
47-
func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
48-
m := c.m
49-
ch <- c.ns.NewDesc(m.name, m.help, m.unit, m.labels...)
50-
}
51-
52-
// Collect prometheus metrics
53-
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
54-
m := c.m
55-
for _, v := range m.getValues() {
56-
ch <- prometheus.MustNewConstMetric(
57-
c.ns.NewDesc(m.name, m.help, m.unit, m.labels...),
58-
m.vt,
59-
v.v,
60-
v.l...,
61-
)
62-
}
63-
}
64-
65-
// Register a prometheus namespace for generic metrics
66-
func Register() {
24+
func init() {
6725
ns := goMetrics.NewNamespace("containerd", "", nil)
68-
69-
c := newBuildInfoCollector(ns)
70-
ns.Add(c)
26+
c := ns.NewLabeledCounter("build_info", "containerd build information", "version", "revision")
27+
c.WithValues(version.Version, version.Revision).Inc()
7128
goMetrics.Register(ns)
7229
}

0 commit comments

Comments
 (0)