2016-11-10 22:56:29 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package controller
|
|
|
|
|
2016-11-29 01:39:17 +00:00
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2017-09-17 18:42:31 +00:00
|
|
|
|
2017-11-07 22:02:12 +00:00
|
|
|
"k8s.io/ingress-nginx/internal/ingress"
|
2016-11-29 01:39:17 +00:00
|
|
|
)
|
2016-11-10 22:56:29 +00:00
|
|
|
|
|
|
|
const (
|
2017-06-12 12:45:08 +00:00
|
|
|
ns = "ingress_controller"
|
|
|
|
operation = "count"
|
|
|
|
reloadLabel = "reloads"
|
|
|
|
sslLabelExpire = "ssl_expire_time_seconds"
|
|
|
|
sslLabelHost = "host"
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
prometheus.MustRegister(reloadOperation)
|
|
|
|
prometheus.MustRegister(reloadOperationErrors)
|
2017-06-12 12:45:08 +00:00
|
|
|
prometheus.MustRegister(sslExpireTime)
|
2016-11-10 22:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
reloadOperation = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: ns,
|
|
|
|
Name: "success",
|
|
|
|
Help: "Cumulative number of Ingress controller reload operations",
|
|
|
|
},
|
|
|
|
[]string{operation},
|
|
|
|
)
|
|
|
|
reloadOperationErrors = prometheus.NewCounterVec(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Namespace: ns,
|
|
|
|
Name: "errors",
|
|
|
|
Help: "Cumulative number of Ingress controller errors during reload operations",
|
|
|
|
},
|
|
|
|
[]string{operation},
|
|
|
|
)
|
2017-06-12 12:45:08 +00:00
|
|
|
sslExpireTime = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: ns,
|
|
|
|
Name: sslLabelExpire,
|
2017-06-13 13:07:14 +00:00
|
|
|
Help: "Number of seconds since 1970 to the SSL Certificate expire. An example to check if this " +
|
2017-06-12 12:45:08 +00:00
|
|
|
"certificate will expire in 10 days is: \"ingress_controller_ssl_expire_time_seconds < (time() + (10 * 24 * 3600))\"",
|
|
|
|
},
|
|
|
|
[]string{sslLabelHost},
|
|
|
|
)
|
2016-11-10 22:56:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func incReloadCount() {
|
|
|
|
reloadOperation.WithLabelValues(reloadLabel).Inc()
|
|
|
|
}
|
|
|
|
|
|
|
|
func incReloadErrorCount() {
|
|
|
|
reloadOperationErrors.WithLabelValues(reloadLabel).Inc()
|
|
|
|
}
|
2017-06-12 12:45:08 +00:00
|
|
|
|
|
|
|
func setSSLExpireTime(servers []*ingress.Server) {
|
|
|
|
for _, s := range servers {
|
2017-06-13 14:01:05 +00:00
|
|
|
if s.Hostname != defServerName {
|
|
|
|
sslExpireTime.WithLabelValues(s.Hostname).Set(float64(s.SSLExpireTime.Unix()))
|
|
|
|
}
|
2017-06-12 12:45:08 +00:00
|
|
|
}
|
|
|
|
}
|