Skip to content

Commit

Permalink
kata-monitor: export get stats for sandbox
Browse files Browse the repository at this point in the history
Gathering stats for a given sandbox is pretty useful; let's export a
function from katamonitor pkg to do this.

Signed-off-by: Eric Ernst <eric_ernst@apple.com>
(cherry picked from commit 3787306)
  • Loading branch information
egernst authored and fidencio committed May 12, 2021
1 parent 59b9e5d commit 1b3cf2f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/runtime/pkg/kata-monitor/metrics.go
Expand Up @@ -176,7 +176,7 @@ func (km *KataMonitor) aggregateSandboxMetrics(encoder expfmt.Encoder) error {
for sandboxID, namespace := range sandboxes {
wg.Add(1)
go func(sandboxID, namespace string, results chan<- []*dto.MetricFamily) {
sandboxMetrics, err := getSandboxMetrics(sandboxID)
sandboxMetrics, err := getParsedMetrics(sandboxID)
if err != nil {
monitorLog.WithError(err).WithField("sandbox_id", sandboxID).Errorf("failed to get metrics for sandbox")
}
Expand Down Expand Up @@ -229,12 +229,11 @@ func (km *KataMonitor) aggregateSandboxMetrics(encoder expfmt.Encoder) error {
return err
}
}

return nil

}

// getSandboxMetrics will get sandbox's metrics from shim
func getSandboxMetrics(sandboxID string) ([]*dto.MetricFamily, error) {
func getParsedMetrics(sandboxID string) ([]*dto.MetricFamily, error) {
body, err := doGet(sandboxID, defaultTimeout, "metrics")
if err != nil {
return nil, err
Expand All @@ -243,6 +242,16 @@ func getSandboxMetrics(sandboxID string) ([]*dto.MetricFamily, error) {
return parsePrometheusMetrics(sandboxID, body)
}

// GetSandboxMetrics will get sandbox's metrics from shim
func GetSandboxMetrics(sandboxID string) (string, error) {
body, err := doGet(sandboxID, defaultTimeout, "metrics")
if err != nil {
return "", err
}

return string(body), nil
}

// parsePrometheusMetrics will decode metrics from Prometheus text format
// and return array of *dto.MetricFamily with an ASC order
func parsePrometheusMetrics(sandboxID string, body []byte) ([]*dto.MetricFamily, error) {
Expand Down

0 comments on commit 1b3cf2f

Please sign in to comment.