summaryrefslogtreecommitdiffhomepage
path: root/pkg/metric
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-04-21 16:48:30 +0000
committergVisor bot <gvisor-bot@google.com>2020-04-21 16:48:30 +0000
commit4813fb89ce2049644fe8bf13b214d89c65950642 (patch)
tree76b3e329656726f85664805c26355100b2ffd3d6 /pkg/metric
parent80adf98cbdd5306410c005fc5ea1fe994cefb793 (diff)
parent8b72623e6ababc5448de0cb347476eaf4a611e2c (diff)
Merge release-20200323.0-201-g8b72623 (automated)
Diffstat (limited to 'pkg/metric')
-rw-r--r--pkg/metric/metric.go41
-rwxr-xr-xpkg/metric/metric_go_proto/metric.pb.go100
2 files changed, 90 insertions, 51 deletions
diff --git a/pkg/metric/metric.go b/pkg/metric/metric.go
index 895253625..64aa365ce 100644
--- a/pkg/metric/metric.go
+++ b/pkg/metric/metric.go
@@ -39,16 +39,11 @@ var (
// Uint64Metric encapsulates a uint64 that represents some kind of metric to be
// monitored.
//
-// All metrics must be cumulative, meaning that their values will only increase
-// over time.
-//
// Metrics are not saved across save/restore and thus reset to zero on restore.
//
-// TODO(b/67298402): Support non-cumulative metrics.
// TODO(b/67298427): Support metric fields.
type Uint64Metric struct {
- // value is the actual value of the metric. It must be accessed
- // atomically.
+ // value is the actual value of the metric. It must be accessed atomically.
value uint64
}
@@ -110,13 +105,10 @@ type customUint64Metric struct {
// Register must only be called at init and will return and error if called
// after Initialized.
//
-// All metrics must be cumulative, meaning that the return values of value must
-// only increase over time.
-//
// Preconditions:
// * name must be globally unique.
// * Initialize/Disable have not been called.
-func RegisterCustomUint64Metric(name string, sync bool, description string, value func() uint64) error {
+func RegisterCustomUint64Metric(name string, cumulative, sync bool, units pb.MetricMetadata_Units, description string, value func() uint64) error {
if initialized {
return ErrInitializationDone
}
@@ -129,9 +121,10 @@ func RegisterCustomUint64Metric(name string, sync bool, description string, valu
metadata: &pb.MetricMetadata{
Name: name,
Description: description,
- Cumulative: true,
+ Cumulative: cumulative,
Sync: sync,
- Type: pb.MetricMetadata_UINT64,
+ Type: pb.MetricMetadata_TYPE_UINT64,
+ Units: units,
},
value: value,
}
@@ -140,24 +133,32 @@ func RegisterCustomUint64Metric(name string, sync bool, description string, valu
// MustRegisterCustomUint64Metric calls RegisterCustomUint64Metric and panics
// if it returns an error.
-func MustRegisterCustomUint64Metric(name string, sync bool, description string, value func() uint64) {
- if err := RegisterCustomUint64Metric(name, sync, description, value); err != nil {
+func MustRegisterCustomUint64Metric(name string, cumulative, sync bool, description string, value func() uint64) {
+ if err := RegisterCustomUint64Metric(name, cumulative, sync, pb.MetricMetadata_UNITS_NONE, description, value); err != nil {
panic(fmt.Sprintf("Unable to register metric %q: %v", name, err))
}
}
-// NewUint64Metric creates and registers a new 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, description string) (*Uint64Metric, error) {
+func NewUint64Metric(name string, sync bool, units pb.MetricMetadata_Units, description string) (*Uint64Metric, error) {
var m Uint64Metric
- return &m, RegisterCustomUint64Metric(name, sync, description, m.Value)
+ 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, description)
+ m, err := NewUint64Metric(name, sync, pb.MetricMetadata_UNITS_NONE, description)
+ if err != nil {
+ panic(fmt.Sprintf("Unable to create metric %q: %v", name, err))
+ }
+ return m
+}
+
+// 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 {
panic(fmt.Sprintf("Unable to create metric %q: %v", name, err))
}
diff --git a/pkg/metric/metric_go_proto/metric.pb.go b/pkg/metric/metric_go_proto/metric.pb.go
index 553236535..13f41a80d 100755
--- a/pkg/metric/metric_go_proto/metric.pb.go
+++ b/pkg/metric/metric_go_proto/metric.pb.go
@@ -23,15 +23,15 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type MetricMetadata_Type int32
const (
- MetricMetadata_UINT64 MetricMetadata_Type = 0
+ MetricMetadata_TYPE_UINT64 MetricMetadata_Type = 0
)
var MetricMetadata_Type_name = map[int32]string{
- 0: "UINT64",
+ 0: "TYPE_UINT64",
}
var MetricMetadata_Type_value = map[string]int32{
- "UINT64": 0,
+ "TYPE_UINT64": 0,
}
func (x MetricMetadata_Type) String() string {
@@ -42,15 +42,41 @@ func (MetricMetadata_Type) EnumDescriptor() ([]byte, []int) {
return fileDescriptor_87b8778a4ff2ab5c, []int{0, 0}
}
+type MetricMetadata_Units int32
+
+const (
+ MetricMetadata_UNITS_NONE MetricMetadata_Units = 0
+ MetricMetadata_UNITS_NANOSECONDS MetricMetadata_Units = 1
+)
+
+var MetricMetadata_Units_name = map[int32]string{
+ 0: "UNITS_NONE",
+ 1: "UNITS_NANOSECONDS",
+}
+
+var MetricMetadata_Units_value = map[string]int32{
+ "UNITS_NONE": 0,
+ "UNITS_NANOSECONDS": 1,
+}
+
+func (x MetricMetadata_Units) String() string {
+ return proto.EnumName(MetricMetadata_Units_name, int32(x))
+}
+
+func (MetricMetadata_Units) EnumDescriptor() ([]byte, []int) {
+ return fileDescriptor_87b8778a4ff2ab5c, []int{0, 1}
+}
+
type MetricMetadata struct {
- Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
- Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
- Cumulative bool `protobuf:"varint,3,opt,name=cumulative,proto3" json:"cumulative,omitempty"`
- Sync bool `protobuf:"varint,4,opt,name=sync,proto3" json:"sync,omitempty"`
- Type MetricMetadata_Type `protobuf:"varint,5,opt,name=type,proto3,enum=gvisor.MetricMetadata_Type" json:"type,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
+ Cumulative bool `protobuf:"varint,3,opt,name=cumulative,proto3" json:"cumulative,omitempty"`
+ Sync bool `protobuf:"varint,4,opt,name=sync,proto3" json:"sync,omitempty"`
+ Type MetricMetadata_Type `protobuf:"varint,5,opt,name=type,proto3,enum=gvisor.MetricMetadata_Type" json:"type,omitempty"`
+ Units MetricMetadata_Units `protobuf:"varint,6,opt,name=units,proto3,enum=gvisor.MetricMetadata_Units" json:"units,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
}
func (m *MetricMetadata) Reset() { *m = MetricMetadata{} }
@@ -110,7 +136,14 @@ func (m *MetricMetadata) GetType() MetricMetadata_Type {
if m != nil {
return m.Type
}
- return MetricMetadata_UINT64
+ return MetricMetadata_TYPE_UINT64
+}
+
+func (m *MetricMetadata) GetUnits() MetricMetadata_Units {
+ if m != nil {
+ return m.Units
+ }
+ return MetricMetadata_UNITS_NONE
}
type MetricRegistration struct {
@@ -266,6 +299,7 @@ func (m *MetricUpdate) GetMetrics() []*MetricValue {
func init() {
proto.RegisterEnum("gvisor.MetricMetadata_Type", MetricMetadata_Type_name, MetricMetadata_Type_value)
+ proto.RegisterEnum("gvisor.MetricMetadata_Units", MetricMetadata_Units_name, MetricMetadata_Units_value)
proto.RegisterType((*MetricMetadata)(nil), "gvisor.MetricMetadata")
proto.RegisterType((*MetricRegistration)(nil), "gvisor.MetricRegistration")
proto.RegisterType((*MetricValue)(nil), "gvisor.MetricValue")
@@ -275,23 +309,27 @@ func init() {
func init() { proto.RegisterFile("pkg/metric/metric.proto", fileDescriptor_87b8778a4ff2ab5c) }
var fileDescriptor_87b8778a4ff2ab5c = []byte{
- // 288 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4b, 0xc3, 0x30,
- 0x14, 0xc6, 0x17, 0xd7, 0x75, 0xfa, 0x3a, 0x86, 0x44, 0xd0, 0x80, 0x20, 0xa5, 0x5e, 0x7a, 0xb1,
- 0x93, 0x39, 0x76, 0xf3, 0xe2, 0x41, 0xf4, 0x30, 0x85, 0xb0, 0x79, 0x95, 0xd8, 0x86, 0x12, 0x5c,
- 0xdb, 0xd0, 0xa4, 0x85, 0xfe, 0x75, 0xfe, 0x6b, 0xd2, 0x17, 0x95, 0x4d, 0x76, 0xca, 0xcb, 0xfb,
- 0xde, 0xf7, 0xf1, 0xcb, 0x0b, 0x5c, 0xe8, 0xcf, 0x7c, 0x56, 0x48, 0x5b, 0xab, 0xf4, 0xe7, 0x48,
- 0x74, 0x5d, 0xd9, 0x8a, 0xfa, 0x79, 0xab, 0x4c, 0x55, 0x47, 0x5f, 0x04, 0xa6, 0x2b, 0x14, 0x56,
- 0xd2, 0x8a, 0x4c, 0x58, 0x41, 0x29, 0x78, 0xa5, 0x28, 0x24, 0x23, 0x21, 0x89, 0x4f, 0x38, 0xd6,
- 0x34, 0x84, 0x20, 0x93, 0x26, 0xad, 0x95, 0xb6, 0xaa, 0x2a, 0xd9, 0x11, 0x4a, 0xbb, 0x2d, 0x7a,
- 0x05, 0x90, 0x36, 0x45, 0xb3, 0x15, 0x56, 0xb5, 0x92, 0x0d, 0x43, 0x12, 0x1f, 0xf3, 0x9d, 0x4e,
- 0x9f, 0x6a, 0xba, 0x32, 0x65, 0x1e, 0x2a, 0x58, 0xd3, 0x19, 0x78, 0xb6, 0xd3, 0x92, 0x8d, 0x42,
- 0x12, 0x4f, 0xe7, 0x97, 0x89, 0x63, 0x4a, 0xf6, 0x79, 0x92, 0x75, 0xa7, 0x25, 0xc7, 0xc1, 0x88,
- 0x82, 0xd7, 0xdf, 0x28, 0x80, 0xbf, 0x79, 0x7e, 0x59, 0x2f, 0x17, 0xa7, 0x83, 0xe8, 0x11, 0xa8,
- 0x33, 0x70, 0x99, 0x2b, 0x63, 0x6b, 0x81, 0x38, 0xb7, 0x30, 0x76, 0xef, 0x35, 0x8c, 0x84, 0xc3,
- 0x38, 0x98, 0x9f, 0x1f, 0x4e, 0xe7, 0xbf, 0x63, 0xd1, 0x2b, 0x04, 0x4e, 0x7a, 0x13, 0xdb, 0x46,
- 0x1e, 0xdc, 0xc2, 0x35, 0x4c, 0x1a, 0x55, 0xda, 0xe5, 0xe2, 0xbd, 0xed, 0x67, 0x70, 0x0d, 0xde,
- 0xd3, 0x80, 0x07, 0xae, 0x8b, 0xc6, 0x87, 0x31, 0x8c, 0x50, 0x8d, 0xee, 0x61, 0xe2, 0x02, 0x37,
- 0x3a, 0x13, 0x56, 0xd2, 0x9b, 0xff, 0x48, 0x67, 0xfb, 0x48, 0x68, 0xff, 0xe3, 0xf9, 0xf0, 0xf1,
- 0xa3, 0xee, 0xbe, 0x03, 0x00, 0x00, 0xff, 0xff, 0xcb, 0x7f, 0xcb, 0x46, 0xc3, 0x01, 0x00, 0x00,
+ // 349 bytes of a gzipped FileDescriptorProto
+ 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0x4f, 0x4f, 0xc2, 0x40,
+ 0x10, 0xc5, 0x29, 0xb4, 0xa0, 0x53, 0x82, 0xb8, 0x46, 0x69, 0xa2, 0x31, 0x4d, 0xbd, 0xf4, 0x62,
+ 0x31, 0x48, 0xb8, 0x79, 0xf0, 0x0f, 0x46, 0x0e, 0xb4, 0xa6, 0xb4, 0x26, 0x9e, 0xc8, 0x5a, 0x36,
+ 0x64, 0x23, 0xb4, 0x4d, 0xbb, 0x25, 0xe1, 0x1b, 0xf9, 0x31,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