@@ -25,6 +25,7 @@ type Metrics struct {
25
25
26
26
registry * prometheus.Registry
27
27
containerImageVersion * prometheus.GaugeVec
28
+ containerImageChecked * prometheus.GaugeVec
28
29
containerImageDuration * prometheus.GaugeVec
29
30
containerImageErrors * prometheus.CounterVec
30
31
@@ -60,6 +61,16 @@ func NewServer(log *logrus.Entry) *Metrics {
60
61
"namespace" , "pod" , "container" , "container_type" , "image" , "current_version" , "latest_version" ,
61
62
},
62
63
)
64
+ containerImageChecked := promauto .With (reg ).NewGaugeVec (
65
+ prometheus.GaugeOpts {
66
+ Namespace : "version_checker" ,
67
+ Name : "last_checked" ,
68
+ Help : "Timestamp when the image was checked" ,
69
+ },
70
+ []string {
71
+ "namespace" , "pod" , "container" , "container_type" , "image" ,
72
+ },
73
+ )
63
74
containerImageDuration := promauto .With (reg ).NewGaugeVec (
64
75
prometheus.GaugeOpts {
65
76
Namespace : "version_checker" ,
@@ -84,6 +95,7 @@ func NewServer(log *logrus.Entry) *Metrics {
84
95
registry : reg ,
85
96
containerImageVersion : containerImageVersion ,
86
97
containerImageDuration : containerImageDuration ,
98
+ containerImageChecked : containerImageChecked ,
87
99
containerImageErrors : containerImageErrors ,
88
100
containerCache : make (map [string ]cacheItem ),
89
101
roundTripper : NewRoundTripper (reg ),
@@ -135,9 +147,14 @@ func (m *Metrics) AddImage(namespace, pod, container, containerType, imageURL st
135
147
}
136
148
137
149
m .containerImageVersion .With (
138
- m .buildLabels (namespace , pod , container , containerType , imageURL , currentVersion , latestVersion ),
150
+ m .buildFullLabels (namespace , pod , container , containerType , imageURL , currentVersion , latestVersion ),
139
151
).Set (isLatestF )
140
152
153
+ // Bump last updated timestamp
154
+ m .containerImageChecked .With (
155
+ m .buildLastUpdatedLabels (namespace , pod , container , containerType , imageURL ),
156
+ ).Set (float64 (time .Now ().Unix ()))
157
+
141
158
index := m .latestImageIndex (namespace , pod , container , containerType )
142
159
m .containerCache [index ] = cacheItem {
143
160
image : imageURL ,
@@ -162,6 +179,9 @@ func (m *Metrics) RemoveImage(namespace, pod, container, containerType string) {
162
179
m .containerImageDuration .DeletePartialMatch (
163
180
m .buildPartialLabels (namespace , pod ),
164
181
)
182
+ m .containerImageChecked .DeletePartialMatch (
183
+ m .buildPartialLabels (namespace , pod ),
184
+ )
165
185
delete (m .containerCache , index )
166
186
}
167
187
@@ -178,11 +198,10 @@ func (m *Metrics) latestImageIndex(namespace, pod, container, containerType stri
178
198
}
179
199
180
200
func (m * Metrics ) ErrorsReporting (namespace , pod , container , imageURL string ) {
181
-
182
201
m .containerImageErrors .WithLabelValues (namespace , pod , container , imageURL ).Inc ()
183
202
}
184
203
185
- func (m * Metrics ) buildLabels (namespace , pod , container , containerType , imageURL , currentVersion , latestVersion string ) prometheus.Labels {
204
+ func (m * Metrics ) buildFullLabels (namespace , pod , container , containerType , imageURL , currentVersion , latestVersion string ) prometheus.Labels {
186
205
return prometheus.Labels {
187
206
"namespace" : namespace ,
188
207
"pod" : pod ,
@@ -194,6 +213,16 @@ func (m *Metrics) buildLabels(namespace, pod, container, containerType, imageURL
194
213
}
195
214
}
196
215
216
+ func (m * Metrics ) buildLastUpdatedLabels (namespace , pod , container , containerType , imageURL string ) prometheus.Labels {
217
+ return prometheus.Labels {
218
+ "namespace" : namespace ,
219
+ "pod" : pod ,
220
+ "container_type" : containerType ,
221
+ "container" : container ,
222
+ "image" : imageURL ,
223
+ }
224
+ }
225
+
197
226
func (m * Metrics ) buildPartialLabels (namespace , pod string ) prometheus.Labels {
198
227
return prometheus.Labels {
199
228
"namespace" : namespace ,
0 commit comments