add a metric with build info (#7660)
This commit is contained in:
parent
ddbb0be0a0
commit
c6566a558c
1 changed files with 22 additions and 0 deletions
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"k8s.io/ingress-nginx/internal/ingress"
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
|
"k8s.io/ingress-nginx/version"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ type Controller struct {
|
||||||
labels prometheus.Labels
|
labels prometheus.Labels
|
||||||
|
|
||||||
leaderElection *prometheus.GaugeVec
|
leaderElection *prometheus.GaugeVec
|
||||||
|
|
||||||
|
buildInfo prometheus.Collector
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewController creates a new prometheus collector for the
|
// NewController creates a new prometheus collector for the
|
||||||
|
@ -69,6 +72,23 @@ func NewController(pod, namespace, class string) *Controller {
|
||||||
"class": class,
|
"class": class,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
buildInfo: prometheus.NewGaugeFunc(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Namespace: PrometheusNamespace,
|
||||||
|
Name: "build_info",
|
||||||
|
Help: "A metric with a constant '1' labeled with information about the build.",
|
||||||
|
ConstLabels: prometheus.Labels{
|
||||||
|
"controller_namespace": namespace,
|
||||||
|
"controller_class": class,
|
||||||
|
"controller_pod": pod,
|
||||||
|
"release": version.RELEASE,
|
||||||
|
"build": version.COMMIT,
|
||||||
|
"repository": version.REPO,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
func() float64 { return 1 },
|
||||||
|
),
|
||||||
|
|
||||||
configHash: prometheus.NewGauge(
|
configHash: prometheus.NewGauge(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Namespace: PrometheusNamespace,
|
Namespace: PrometheusNamespace,
|
||||||
|
@ -210,6 +230,7 @@ func (cm Controller) Describe(ch chan<- *prometheus.Desc) {
|
||||||
cm.checkIngressOperationErrors.Describe(ch)
|
cm.checkIngressOperationErrors.Describe(ch)
|
||||||
cm.sslExpireTime.Describe(ch)
|
cm.sslExpireTime.Describe(ch)
|
||||||
cm.leaderElection.Describe(ch)
|
cm.leaderElection.Describe(ch)
|
||||||
|
cm.buildInfo.Describe(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect implements the prometheus.Collector interface.
|
// Collect implements the prometheus.Collector interface.
|
||||||
|
@ -223,6 +244,7 @@ func (cm Controller) Collect(ch chan<- prometheus.Metric) {
|
||||||
cm.checkIngressOperationErrors.Collect(ch)
|
cm.checkIngressOperationErrors.Collect(ch)
|
||||||
cm.sslExpireTime.Collect(ch)
|
cm.sslExpireTime.Collect(ch)
|
||||||
cm.leaderElection.Collect(ch)
|
cm.leaderElection.Collect(ch)
|
||||||
|
cm.buildInfo.Collect(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSSLExpireTime sets the expiration time of SSL Certificates
|
// SetSSLExpireTime sets the expiration time of SSL Certificates
|
||||||
|
|
Loading…
Reference in a new issue