Instrument nginx to expose metric "ssl certficate expiration time "

Add a console warning message 10 days before the certificate expire
This commit is contained in:
Giancarlo Rubio 2017-06-12 14:45:08 +02:00
parent e258ee19d1
commit d9cf043552
5 changed files with 41 additions and 3 deletions

View file

@ -18,17 +18,22 @@ package controller
import (
"github.com/prometheus/client_golang/prometheus"
"k8s.io/ingress/core/pkg/ingress"
)
const (
ns = "ingress_controller"
operation = "count"
reloadLabel = "reloads"
ns = "ingress_controller"
operation = "count"
reloadLabel = "reloads"
sslLabelExpire = "ssl_expire_time_seconds"
sslLabelHost = "host"
)
func init() {
prometheus.MustRegister(reloadOperation)
prometheus.MustRegister(reloadOperationErrors)
prometheus.MustRegister(sslExpireTime)
}
var (
@ -48,6 +53,15 @@ var (
},
[]string{operation},
)
sslExpireTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: ns,
Name: sslLabelExpire,
Help: "Number of seconds since 1970 to the SSL Certificate expire. An example to check if this " +
"certificate will expire in 10 days is: \"ingress_controller_ssl_expire_time_seconds < (time() + (10 * 24 * 3600))\"",
},
[]string{sslLabelHost},
)
)
func incReloadCount() {
@ -57,3 +71,11 @@ func incReloadCount() {
func incReloadErrorCount() {
reloadOperationErrors.WithLabelValues(reloadLabel).Inc()
}
func setSSLExpireTime(servers []*ingress.Server) {
for _, s := range servers {
sslExpireTime.WithLabelValues(s.Hostname).Set(float64(s.SSLExpireTime.Unix()))
}
}