@@ -66,6 +66,7 @@ const scrapeInterval = 1 * time.Minute
6666const pullArtifactPath = "/mnt/storage/pull-artifact.txt"
6767const pullTag = ":pull"
6868const metadataTag = ":metadata"
69+ var k8sNodeName = os .Getenv ("NODE_NAME" )
6970
7071// Target file size in bytes (10MB)
7172const targetFileSize = 10 * 1024 * 1024
@@ -79,59 +80,59 @@ func InitMetrics(reg prometheus.Registerer, registryMap map[string]RegistryConfi
7980 Name : "registry_exporter_pull_success" ,
8081 Help : "Gauge indicating if a pull from the registry was successful (1 if successful, 0 otherwise)." ,
8182 },
82- []string {"tested_registry" },
83+ []string {"tested_registry" , "node" },
8384 ),
8485 RegistryPullErrorCount : prometheus .NewCounterVec (
8586 prometheus.CounterOpts {
8687 Name : "registry_exporter_pull_error_count" ,
8788 Help : "Total number of errors encountered during pulls from the registry." ,
8889 },
89- []string {"tested_registry" , "error" },
90+ []string {"tested_registry" ,"node" , "error" },
9091 ),
9192 RegistryPullDuration : prometheus .NewHistogramVec (
9293 prometheus.HistogramOpts {
9394 Name : "registry_exporter_pull_duration_seconds" ,
9495 Help : "Histogram of durations for pulls from the registry in seconds." ,
9596 Buckets : []float64 {2 , 3 , 4 , 5 },
9697 },
97- []string {"tested_registry" },
98+ []string {"tested_registry" , "node" },
9899 ),
99100 RegistryPullImageSize : prometheus .NewGaugeVec (
100101 prometheus.GaugeOpts {
101102 Name : "registry_exporter_pull_image_size_mbytes" ,
102103 Help : "Gauge of image size for pulls from the registry in megabytes." ,
103104 },
104- []string {"tested_registry" },
105+ []string {"tested_registry" , "node" },
105106 ),
106107 // Push metrics
107108 RegistryPushSuccess : prometheus .NewGaugeVec (
108109 prometheus.GaugeOpts {
109110 Name : "registry_exporter_push_success" ,
110111 Help : "Gauge indicating if a push to the registry was successful (1 if successful, 0 otherwise)." ,
111112 },
112- []string {"tested_registry" },
113+ []string {"tested_registry" , "node" },
113114 ),
114115 RegistryPushErrorCount : prometheus .NewCounterVec (
115116 prometheus.CounterOpts {
116117 Name : "registry_exporter_push_error_count" ,
117118 Help : "Total number of errors encountered during pushes to the registry." ,
118119 },
119- []string {"tested_registry" , "error" },
120+ []string {"tested_registry" ,"node" , "error" },
120121 ),
121122 RegistryPushDuration : prometheus .NewHistogramVec (
122123 prometheus.HistogramOpts {
123124 Name : "registry_exporter_push_duration_seconds" ,
124125 Help : "Histogram of durations for pushes to the registry." ,
125126 Buckets : []float64 {5 , 6 , 7 , 8 , 9 , 10 },
126127 },
127- []string {"tested_registry" },
128+ []string {"tested_registry" , "node" },
128129 ),
129130 RegistryPushImageSize : prometheus .NewGaugeVec (
130131 prometheus.GaugeOpts {
131132 Name : "registry_exporter_push_image_size_mbytes" ,
132133 Help : "Gauge of image size for pushes to the registry in megabytes." ,
133134 },
134- []string {"tested_registry" },
135+ []string {"tested_registry" , "node" },
135136 ),
136137
137138 // Metadata metrics
@@ -140,22 +141,22 @@ func InitMetrics(reg prometheus.Registerer, registryMap map[string]RegistryConfi
140141 Name : "registry_exporter_metadata_success" ,
141142 Help : "Gauge indicating if a metadata test for the registry was successful (1 if successful, 0 otherwise)." ,
142143 },
143- []string {"tested_registry" },
144+ []string {"tested_registry" , "node" },
144145 ),
145146 RegistryMetadataErrorCount : prometheus .NewCounterVec (
146147 prometheus.CounterOpts {
147148 Name : "registry_exporter_metadata_error_count" ,
148149 Help : "Total number of errors encountered during metadata tests for the registry." ,
149150 },
150- []string {"tested_registry" , "error" },
151+ []string {"tested_registry" ,"node" , "error" },
151152 ),
152153 RegistryMetadataDuration : prometheus .NewHistogramVec (
153154 prometheus.HistogramOpts {
154155 Name : "registry_exporter_metadata_duration_seconds" ,
155156 Help : "Histogram of durations for metadata tests for the registry in seconds." ,
156157 Buckets : []float64 {2 , 3 , 4 , 5 },
157158 },
158- []string {"tested_registry" },
159+ []string {"tested_registry" , "node" },
159160 ),
160161
161162 // Authentication metrics
@@ -164,22 +165,22 @@ func InitMetrics(reg prometheus.Registerer, registryMap map[string]RegistryConfi
164165 Name : "registry_exporter_authentication_success" ,
165166 Help : "Gauge indicating if an authentication test for the registry was successful (1 if successful, 0 otherwise)." ,
166167 },
167- []string {"tested_registry" },
168+ []string {"tested_registry" , "node" },
168169 ),
169170 RegistryAuthenticationErrorCount : prometheus .NewCounterVec (
170171 prometheus.CounterOpts {
171172 Name : "registry_exporter_authentication_error_count" ,
172173 Help : "Total number of errors encountered during authentication tests for the registry." ,
173174 },
174- []string {"tested_registry" , "error" },
175+ []string {"tested_registry" ,"node" , "error" },
175176 ),
176177 RegistryAuthenticationDuration : prometheus .NewHistogramVec (
177178 prometheus.HistogramOpts {
178179 Name : "registry_exporter_authentication_duration_seconds" ,
179180 Help : "Histogram of durations for authentication tests for the registry in seconds." ,
180181 Buckets : []float64 {1 , 1.5 , 2 , 2.5 , 3 , 3.5 , 4 , 4.5 , 5 },
181182 },
182- []string {"tested_registry" },
183+ []string {"tested_registry" , "node" },
183184 ),
184185 }
185186 reg .MustRegister (m .RegistryPullSuccess )
@@ -232,13 +233,13 @@ func ExtractErrorReason(output []byte) string {
232233func setSuccessState (metrics * Metrics , registryType string , testType string ) {
233234 switch testType {
234235 case "pull" :
235- metrics .RegistryPullSuccess .WithLabelValues (registryType ).Set (1 )
236+ metrics .RegistryPullSuccess .WithLabelValues (registryType , k8sNodeName ).Set (1 )
236237 case "push" :
237- metrics .RegistryPushSuccess .WithLabelValues (registryType ).Set (1 )
238+ metrics .RegistryPushSuccess .WithLabelValues (registryType , k8sNodeName ).Set (1 )
238239 case "metadata" :
239- metrics .RegistryMetadataSuccess .WithLabelValues (registryType ).Set (1 )
240+ metrics .RegistryMetadataSuccess .WithLabelValues (registryType , k8sNodeName ).Set (1 )
240241 case "authentication" :
241- metrics .RegistryAuthenticationSuccess .WithLabelValues (registryType ).Set (1 )
242+ metrics .RegistryAuthenticationSuccess .WithLabelValues (registryType , k8sNodeName ).Set (1 )
242243 }
243244}
244245
@@ -248,16 +249,16 @@ func setErrorState(metrics *Metrics, registryType string, testType string, outpu
248249
249250 switch testType {
250251 case "pull" :
251- metrics .RegistryPullSuccess .WithLabelValues (registryType ).Set (0 )
252+ metrics .RegistryPullSuccess .WithLabelValues (registryType , k8sNodeName ).Set (0 )
252253 metrics .RegistryPullErrorCount .WithLabelValues (registryType , errorType ).Inc ()
253254 case "push" :
254- metrics .RegistryPushSuccess .WithLabelValues (registryType ).Set (0 )
255+ metrics .RegistryPushSuccess .WithLabelValues (registryType , k8sNodeName ).Set (0 )
255256 metrics .RegistryPushErrorCount .WithLabelValues (registryType , errorType ).Inc ()
256257 case "metadata" :
257- metrics .RegistryMetadataSuccess .WithLabelValues (registryType ).Set (0 )
258+ metrics .RegistryMetadataSuccess .WithLabelValues (registryType , k8sNodeName ).Set (0 )
258259 metrics .RegistryMetadataErrorCount .WithLabelValues (registryType , errorType ).Inc ()
259260 case "authentication" :
260- metrics .RegistryAuthenticationSuccess .WithLabelValues (registryType ).Set (0 )
261+ metrics .RegistryAuthenticationSuccess .WithLabelValues (registryType , k8sNodeName ).Set (0 )
261262 metrics .RegistryAuthenticationErrorCount .WithLabelValues (registryType , errorType ).Inc ()
262263 }
263264}
@@ -275,9 +276,9 @@ func getFileSizeMB(filePath string) (float64, error) {
275276func setImageSize (metrics * Metrics , registryType string , testType string , sizeMB float64 ) {
276277 switch testType {
277278 case "pull" :
278- metrics .RegistryPullImageSize .WithLabelValues (registryType ).Set (sizeMB )
279+ metrics .RegistryPullImageSize .WithLabelValues (registryType , k8sNodeName ).Set (sizeMB )
279280 case "push" :
280- metrics .RegistryPushImageSize .WithLabelValues (registryType ).Set (sizeMB )
281+ metrics .RegistryPushImageSize .WithLabelValues (registryType , k8sNodeName ).Set (sizeMB )
281282 }
282283}
283284
@@ -286,13 +287,13 @@ func recordDuration(metrics *Metrics, registryType string, testType string, dura
286287 durationSeconds := duration .Seconds ()
287288 switch testType {
288289 case "pull" :
289- metrics .RegistryPullDuration .WithLabelValues (registryType ).Observe (durationSeconds )
290+ metrics .RegistryPullDuration .WithLabelValues (registryType , k8sNodeName ).Observe (durationSeconds )
290291 case "push" :
291- metrics .RegistryPushDuration .WithLabelValues (registryType ).Observe (durationSeconds )
292+ metrics .RegistryPushDuration .WithLabelValues (registryType , k8sNodeName ).Observe (durationSeconds )
292293 case "metadata" :
293- metrics .RegistryMetadataDuration .WithLabelValues (registryType ).Observe (durationSeconds )
294+ metrics .RegistryMetadataDuration .WithLabelValues (registryType , k8sNodeName ).Observe (durationSeconds )
294295 case "authentication" :
295- metrics .RegistryAuthenticationDuration .WithLabelValues (registryType ).Observe (durationSeconds )
296+ metrics .RegistryAuthenticationDuration .WithLabelValues (registryType , k8sNodeName ).Observe (durationSeconds )
296297 }
297298}
298299
@@ -587,7 +588,9 @@ func AuthenticationTest(metrics *Metrics, registryMap map[string]RegistryConfig,
587588
588589func main () {
589590 log .SetOutput (os .Stderr )
590-
591+ if k8sNodeName == "" {
592+ log .Fatalf ("FATAL: Missing NODE_NAME environment variable. Metrics must always have node label." )
593+ }
591594 registryMap := PrepareRegistryMap ()
592595
593596 reg := prometheus .NewRegistry ()
0 commit comments