Allow the id for cgroup metrics to be changed
This makes the metrics package more extensible by allowing the default name of `container_id` to be changed by the package caller. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
7bdec4e47f
commit
d654dbafac
@ -24,6 +24,9 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IDName is the name that is used to identify the id being collected in the metric
|
||||||
|
var IDName = "container_id"
|
||||||
|
|
||||||
type value struct {
|
type value struct {
|
||||||
v float64
|
v float64
|
||||||
l []string
|
l []string
|
||||||
@ -41,7 +44,7 @@ type metric struct {
|
|||||||
|
|
||||||
func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc {
|
func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc {
|
||||||
// the namespace label is for containerd namespaces
|
// the namespace label is for containerd namespaces
|
||||||
return ns.NewDesc(m.name, m.help, m.unit, append([]string{"container_id", "namespace"}, m.labels...)...)
|
return ns.NewDesc(m.name, m.help, m.unit, append([]string{IDName, "namespace"}, m.labels...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *metric) collect(id, namespace string, stats *v1.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) {
|
func (m *metric) collect(id, namespace string, stats *v1.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) {
|
||||||
|
@ -24,6 +24,9 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IDName is the name that is used to identify the id being collected in the metric
|
||||||
|
var IDName = "container_id"
|
||||||
|
|
||||||
type value struct {
|
type value struct {
|
||||||
v float64
|
v float64
|
||||||
l []string
|
l []string
|
||||||
@ -41,7 +44,7 @@ type metric struct {
|
|||||||
|
|
||||||
func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc {
|
func (m *metric) desc(ns *metrics.Namespace) *prometheus.Desc {
|
||||||
// the namespace label is for containerd namespaces
|
// the namespace label is for containerd namespaces
|
||||||
return ns.NewDesc(m.name, m.help, m.unit, append([]string{"container_id", "namespace"}, m.labels...)...)
|
return ns.NewDesc(m.name, m.help, m.unit, append([]string{IDName, "namespace"}, m.labels...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *metric) collect(id, namespace string, stats *v2.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) {
|
func (m *metric) collect(id, namespace string, stats *v2.Metrics, ns *metrics.Namespace, ch chan<- prometheus.Metric, block bool) {
|
||||||
|
Loading…
Reference in New Issue
Block a user