This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
76 lines (62 loc) · 2.3 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package controller
import (
templateapi "github.com/openshift/origin/pkg/template/apis/template"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/apimachinery/pkg/labels"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
kapi "k8s.io/kubernetes/pkg/api"
)
var templateInstancesTotal = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "openshift_template_instance_total",
Help: "Counts TemplateInstance objects",
},
nil,
)
var templateInstanceStatusCondition = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "openshift_template_instance_status_condition_total",
Help: "Counts TemplateInstance objects by condition type and status",
},
[]string{"type", "status"},
)
var templateInstancesActiveStartTime = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "openshift_template_instance_active_start_time_seconds",
Help: "Show the start time in unix epoch form of active TemplateInstance objects by namespace and name",
},
[]string{"namespace", "name"},
)
func (c *TemplateInstanceController) Describe(ch chan<- *prometheus.Desc) {
templateInstancesTotal.Describe(ch)
templateInstanceStatusCondition.Describe(ch)
templateInstancesActiveStartTime.Describe(ch)
}
func (c *TemplateInstanceController) Collect(ch chan<- prometheus.Metric) {
templateInstances, err := c.lister.List(labels.Everything())
if err != nil {
utilruntime.HandleError(err)
return
}
templateInstancesTotal.Reset()
templateInstanceStatusCondition.Reset()
templateInstancesActiveStartTime.Reset()
templateInstancesTotal.WithLabelValues().Set(0)
for _, templateInstance := range templateInstances {
waiting := true
templateInstancesTotal.WithLabelValues().Inc()
for _, cond := range templateInstance.Status.Conditions {
templateInstanceStatusCondition.WithLabelValues(string(cond.Type), string(cond.Status)).Inc()
if cond.Status == kapi.ConditionTrue &&
(cond.Type == templateapi.TemplateInstanceInstantiateFailure || cond.Type == templateapi.TemplateInstanceReady) {
waiting = false
}
}
if waiting {
templateInstancesActiveStartTime.WithLabelValues(templateInstance.Namespace, templateInstance.Name).Set(float64(templateInstance.CreationTimestamp.Unix()))
}
}
templateInstancesTotal.Collect(ch)
templateInstanceStatusCondition.Collect(ch)
templateInstancesActiveStartTime.Collect(ch)
}