summaryrefslogtreecommitdiffhomepage
path: root/pkg/metric
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-01-13 16:33:47 +0000
committergVisor bot <gvisor-bot@google.com>2021-01-13 16:33:47 +0000
commit4190065e59a7a3732c823a031735c6b7641e43d3 (patch)
treecfca70142572fd4a6fecb3c3008bcb3093ccaeda /pkg/metric
parentac62523cae713203902dab722ddf1d33bca3d580 (diff)
parente4d8f55cef1aa0b6b48dec5a20fe6e480d70d0a0 (diff)
Merge release-20201216.0-97-ge4d8f55ce (automated)
Diffstat (limited to 'pkg/metric')
-rw-r--r--pkg/metric/metric.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/pkg/metric/metric.go b/pkg/metric/metric.go
index d012c5734..c9f9357de 100644
--- a/pkg/metric/metric.go
+++ b/pkg/metric/metric.go
@@ -18,6 +18,7 @@ package metric
import (
"errors"
"fmt"
+ "sort"
"sync/atomic"
"gvisor.dev/gvisor/pkg/eventchannel"
@@ -139,7 +140,8 @@ func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, descript
}
}
-// NewUint64Metric creates and registers a new cumulative metric with the given name.
+// NewUint64Metric creates and registers a new cumulative metric with the given
+// name.
//
// Metrics must be statically defined (i.e., at init).
func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string) (*Uint64Metric, error) {
@@ -147,7 +149,8 @@ func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, desc
return &m, RegisterCustomUint64Metric(name, true /* cumulative */, sync, units, description, m.Value)
}
-// MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an error.
+// MustCreateNewUint64Metric calls NewUint64Metric and panics if it returns an
+// error.
func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint64Metric {
m, err := NewUint64Metric(name, sync, pb.MetricMetadata_UNITS_NONE, description)
if err != nil {
@@ -156,7 +159,8 @@ func MustCreateNewUint64Metric(name string, sync bool, description string) *Uint
return m
}
-// MustCreateNewUint64NanosecondsMetric calls NewUint64Metric and panics if it returns an error.
+// MustCreateNewUint64NanosecondsMetric calls NewUint64Metric and panics if it
+// returns an error.
func MustCreateNewUint64NanosecondsMetric(name string, sync bool, description string) *Uint64Metric {
m, err := NewUint64Metric(name, sync, pb.MetricMetadata_UNITS_NANOSECONDS, description)
if err != nil {
@@ -245,6 +249,15 @@ func EmitMetricUpdate() {
return
}
- log.Debugf("Emitting metrics: %v", &m)
+ if log.IsLogging(log.Debug) {
+ sort.Slice(m.Metrics, func(i, j int) bool {
+ return m.Metrics[i].Name < m.Metrics[j].Name
+ })
+ log.Debugf("Emitting metrics:")
+ for _, metric := range m.Metrics {
+ log.Debugf("%s: %+v", metric.Name, metric.Value)
+ }
+ }
+
eventchannel.Emit(&m)
}