@@ -2,6 +2,7 @@ package controller
2
2
3
3
import (
4
4
"context"
5
+ "strconv"
5
6
6
7
kuikv1alpha1 "github.com/enix/kube-image-keeper/api/kuik/v1alpha1"
7
8
"github.com/enix/kube-image-keeper/internal/info"
@@ -59,7 +60,7 @@ func (m *kuikMetrics) Register(elected <-chan struct{}, client client.Client) {
59
60
Name : "tasks_total" ,
60
61
Help : "Total number of image monitoring tasks, labeled by registry and status." ,
61
62
},
62
- []string {"registry" , "status" },
63
+ []string {"registry" , "status" , "unused" },
63
64
)
64
65
m .addCollector (m .monitoringTasks )
65
66
@@ -71,35 +72,36 @@ func (m *kuikMetrics) Register(elected <-chan struct{}, client client.Client) {
71
72
Help : "Number of images monitored, labeled by registry and status." ,
72
73
},
73
74
prometheus .GaugeValue ,
74
- []string {"registry" , "status" },
75
+ []string {"registry" , "status" , "unused" },
75
76
func (collect func (value float64 , labels ... string )) {
76
77
imageList := & kuikv1alpha1.ImageList {}
77
78
if err := client .List (context .Background (), imageList ); err != nil {
78
79
logf .Log .Error (err , "failed to list images for metrics" )
79
80
return
80
81
}
81
82
82
- images := make (map [string ]map [string ]float64 )
83
+ images := make (map [string ]map [string ]map [ bool ] float64 )
83
84
for _ , image := range imageList .Items {
84
85
registry := image .Spec .Registry
85
86
if _ , exists := images [registry ]; ! exists {
86
- images [registry ] = make (map [string ]float64 )
87
+ images [registry ] = make (map [string ]map [ bool ] float64 )
87
88
for _ , status := range kuikv1alpha1 .ImageStatusUpstreamList {
88
- images [registry ][status .ToString ()] = 0
89
+ images [registry ][status .ToString ()] = map [bool ]float64 {
90
+ true : 0 ,
91
+ false : 0 ,
92
+ }
89
93
}
90
94
}
91
95
92
96
status := image .Status .Upstream .Status .ToString ()
93
- if _ , exists := images [registry ][status ]; ! exists {
94
- images [registry ][status ] = 0
95
- }
96
-
97
- images [registry ][status ]++
97
+ images [registry ][status ][image .IsUnused ()]++
98
98
}
99
99
100
100
for registry , statuses := range images {
101
- for status , count := range statuses {
102
- collect (count , registry , status )
101
+ for status , unuseds := range statuses {
102
+ for unused , count := range unuseds {
103
+ collect (count , registry , status , strconv .FormatBool (unused ))
104
+ }
103
105
}
104
106
}
105
107
}))
@@ -139,13 +141,14 @@ func (m *kuikMetrics) addCollector(collector prometheus.Collector) {
139
141
func (m * kuikMetrics ) InitMonitoringTaskRegistry (registry string ) {
140
142
for _ , status := range kuikv1alpha1 .ImageStatusUpstreamList {
141
143
if status != kuikv1alpha1 .ImageStatusUpstreamScheduled {
142
- m .monitoringTasks .WithLabelValues (registry , status .ToString ()).Add (0 )
144
+ m .monitoringTasks .WithLabelValues (registry , status .ToString (), "true" ).Add (0 )
145
+ m .monitoringTasks .WithLabelValues (registry , status .ToString (), "false" ).Add (0 )
143
146
}
144
147
}
145
148
}
146
149
147
- func (m * kuikMetrics ) MonitoringTaskCompleted (registry string , status kuikv1alpha1.ImageStatusUpstream ) {
148
- m .monitoringTasks .WithLabelValues (registry , status .ToString ()).Inc ()
150
+ func (m * kuikMetrics ) MonitoringTaskCompleted (registry string , status kuikv1alpha1.ImageStatusUpstream , unused bool ) {
151
+ m .monitoringTasks .WithLabelValues (registry , status .ToString (), strconv . FormatBool ( unused ) ).Inc ()
149
152
}
150
153
151
154
type GenericCollector struct {
0 commit comments