runsc metric-server: Export aggregate metrics about number of sandboxes.

These metrics were defined but not actually populated.

PiperOrigin-RevId: 511314252
This commit is contained in:
Etienne Perot
2023-02-21 15:05:35 -08:00
committed by gVisor bot
parent f7a3a23d30
commit 87a0113a69
+6
View File
@@ -556,6 +556,7 @@ func (m *MetricServer) serveMetrics(w http.ResponseWriter, req *http.Request) ht
loadedSandboxes = append(loadedSandboxes, <-loadedSandboxesCh)
}
close(loadedSandboxesCh)
numSandboxesTotal := m.numSandboxes
m.mu.Unlock()
// Now iterate over all sandboxes.
@@ -683,6 +684,11 @@ func (m *MetricServer) serveMetrics(w http.ResponseWriter, req *http.Request) ht
snapshotsToOptions[snapshotAndOptions.snapshot] = snapshotAndOptions.options
}
// Add our own metrics.
selfMetrics.Add(prometheus.NewIntData(&NumRunningSandboxesMetric, meta.numRunningSandboxes))
selfMetrics.Add(prometheus.NewIntData(&NumCannotExportSandboxesMetric, meta.numCannotExportSandboxes))
selfMetrics.Add(prometheus.NewIntData(&NumTotalSandboxesMetric, numSandboxesTotal))
// Write out all data.
lastMetricsWrittenSize := int(m.lastMetricsWrittenSize.Load())
metricsWritten := make(map[string]bool, lastMetricsWrittenSize)