mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Export metric server metrics.
PiperOrigin-RevId: 511305940
This commit is contained in:
committed by
gVisor bot
parent
81d6f80caf
commit
f7a3a23d30
+25
-13
@@ -463,48 +463,60 @@ func (m *MetricServer) serveIndex(w http.ResponseWriter, req *http.Request) http
|
||||
|
||||
// Metrics generated by the metrics server itself.
|
||||
var (
|
||||
sandboxPresenceMetric = prometheus.Metric{
|
||||
SandboxPresenceMetric = prometheus.Metric{
|
||||
Name: "sandbox_presence",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Boolean metric set to 1 for each known sandbox.",
|
||||
}
|
||||
sandboxRunningMetric = prometheus.Metric{
|
||||
SandboxRunningMetric = prometheus.Metric{
|
||||
Name: "sandbox_running",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Boolean metric set to 1 for each running sandbox.",
|
||||
}
|
||||
sandboxMetadataMetric = prometheus.Metric{
|
||||
SandboxMetadataMetric = prometheus.Metric{
|
||||
Name: "sandbox_metadata",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Key-value pairs about per-sandbox metadata.",
|
||||
}
|
||||
sandboxCreationMetric = prometheus.Metric{
|
||||
SandboxCreationMetric = prometheus.Metric{
|
||||
Name: "sandbox_creation_time_seconds",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "When the sandbox was created, as a unix timestamp in milliseconds.",
|
||||
}
|
||||
numRunningSandboxesMetric = prometheus.Metric{
|
||||
NumRunningSandboxesMetric = prometheus.Metric{
|
||||
Name: "num_sandboxes_running",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Number of sandboxes running at present.",
|
||||
}
|
||||
numCannotExportSandboxesMetric = prometheus.Metric{
|
||||
NumCannotExportSandboxesMetric = prometheus.Metric{
|
||||
Name: "num_sandboxes_broken_metrics",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Number of sandboxes from which we cannot export metrics.",
|
||||
}
|
||||
numTotalSandboxesMetric = prometheus.Metric{
|
||||
NumTotalSandboxesMetric = prometheus.Metric{
|
||||
Name: "num_sandboxes_total",
|
||||
Type: prometheus.TypeCounter,
|
||||
Help: "Counter of sandboxes that have ever been started.",
|
||||
}
|
||||
processStartTimeMetric = prometheus.Metric{
|
||||
ProcessStartTimeMetric = prometheus.Metric{
|
||||
Name: "process_start_time_seconds",
|
||||
Type: prometheus.TypeGauge,
|
||||
Help: "Unix timestamp at which the process started. Used by Prometheus for counter resets.",
|
||||
}
|
||||
)
|
||||
|
||||
// ServerMetrics is a list of metrics that the metric server generates.
|
||||
var ServerMetrics = []prometheus.Metric{
|
||||
SandboxPresenceMetric,
|
||||
SandboxRunningMetric,
|
||||
SandboxMetadataMetric,
|
||||
SandboxCreationMetric,
|
||||
NumRunningSandboxesMetric,
|
||||
NumCannotExportSandboxesMetric,
|
||||
NumTotalSandboxesMetric,
|
||||
ProcessStartTimeMetric,
|
||||
}
|
||||
|
||||
// serveMetrics serves metrics requests.
|
||||
func (m *MetricServer) serveMetrics(w http.ResponseWriter, req *http.Request) httpResult {
|
||||
ctx, ctxCancel := context.WithTimeout(req.Context(), metricsExportTimeout)
|
||||
@@ -616,16 +628,16 @@ func (m *MetricServer) serveMetrics(w http.ResponseWriter, req *http.Request) ht
|
||||
func() {
|
||||
metricsMu.Lock()
|
||||
defer metricsMu.Unlock()
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&sandboxPresenceMetric, served.extraLabels, 1))
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&SandboxPresenceMetric, served.extraLabels, 1))
|
||||
sandboxRunning := int64(0)
|
||||
if isRunning {
|
||||
sandboxRunning = 1
|
||||
meta.numRunningSandboxes++
|
||||
}
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&sandboxRunningMetric, served.extraLabels, sandboxRunning))
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&SandboxRunningMetric, served.extraLabels, sandboxRunning))
|
||||
if loadErr == nil {
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&sandboxMetadataMetric, served.labelsWithMetadata, 1))
|
||||
selfMetrics.Add(prometheus.LabeledFloatData(&sandboxCreationMetric, served.extraLabels, float64(served.createdAt.Unix())+(float64(served.createdAt.Nanosecond())/1e9)))
|
||||
selfMetrics.Add(prometheus.LabeledIntData(&SandboxMetadataMetric, served.labelsWithMetadata, 1))
|
||||
selfMetrics.Add(prometheus.LabeledFloatData(&SandboxCreationMetric, served.extraLabels, float64(served.createdAt.Unix())+(float64(served.createdAt.Nanosecond())/1e9)))
|
||||
}
|
||||
if sandboxErr != nil {
|
||||
// If the sandbox isn't running, it is normal that metrics are not exported for it, so
|
||||
@@ -659,7 +671,7 @@ func (m *MetricServer) serveMetrics(w http.ResponseWriter, req *http.Request) ht
|
||||
ExporterPrefix: fmt.Sprintf("%smeta_", m.exporterPrefix),
|
||||
}
|
||||
processMetrics := prometheus.NewSnapshot()
|
||||
processMetrics.Add(prometheus.NewFloatData(&processStartTimeMetric, float64(m.startTime.Unix())+(float64(m.startTime.Nanosecond())/1e9)))
|
||||
processMetrics.Add(prometheus.NewFloatData(&ProcessStartTimeMetric, float64(m.startTime.Unix())+(float64(m.startTime.Nanosecond())/1e9)))
|
||||
snapshotsToOptions[processMetrics] = prometheus.SnapshotExportOptions{
|
||||
// These metrics must be written without any prefix.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user