OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package monitor | 5 package monitor |
6 | 6 |
7 import ( | 7 import ( |
8 "math" | 8 "math" |
9 "time" | 9 "time" |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 func SerializeCell(c types.Cell) *pb.MetricsData { | 37 func SerializeCell(c types.Cell) *pb.MetricsData { |
38 d := pb.MetricsData{} | 38 d := pb.MetricsData{} |
39 d.Name = proto.String(c.Name) | 39 d.Name = proto.String(c.Name) |
40 d.Description = proto.String(c.Description) | 40 d.Description = proto.String(c.Description) |
41 d.MetricNamePrefix = proto.String(metricNamePrefix) | 41 d.MetricNamePrefix = proto.String(metricNamePrefix) |
42 d.Fields = field.Serialize(c.Fields, c.FieldVals) | 42 d.Fields = field.Serialize(c.Fields, c.FieldVals) |
43 if c.ValueType.IsCumulative() { | 43 if c.ValueType.IsCumulative() { |
44 d.StartTimestampUs = proto.Uint64(uint64(c.ResetTime.UnixNano()
/ int64(time.Microsecond))) | 44 d.StartTimestampUs = proto.Uint64(uint64(c.ResetTime.UnixNano()
/ int64(time.Microsecond))) |
45 } | 45 } |
46 c.Target.PopulateProto(&d) | 46 c.Target.PopulateProto(&d) |
| 47 if c.Units.IsSpecified() { |
| 48 d.Units = c.Units.AsProto() |
| 49 } |
47 | 50 |
48 SerializeValue(c.ValueType, c.Value, &d) | 51 SerializeValue(c.ValueType, c.Value, &d) |
49 return &d | 52 return &d |
50 } | 53 } |
51 | 54 |
52 // SerializeValue writes one metric's value into the MetricsData message. | 55 // SerializeValue writes one metric's value into the MetricsData message. |
53 func SerializeValue(typ types.ValueType, value interface{}, d *pb.MetricsData) { | 56 func SerializeValue(typ types.ValueType, value interface{}, d *pb.MetricsData) { |
54 switch typ { | 57 switch typ { |
55 case types.NonCumulativeIntType: | 58 case types.NonCumulativeIntType: |
56 d.Gauge = proto.Int64(value.(int64)) | 59 d.Gauge = proto.Int64(value.(int64)) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if len(d.Buckets()) == d.Bucketer().NumBuckets() { | 133 if len(d.Buckets()) == d.Bucketer().NumBuckets() { |
131 ret.Overflow = proto.Int64(d.Buckets()[d.Bucketer().NumBuckets()
-1]) | 134 ret.Overflow = proto.Int64(d.Buckets()[d.Bucketer().NumBuckets()
-1]) |
132 } | 135 } |
133 | 136 |
134 if d.Count() > 0 { | 137 if d.Count() > 0 { |
135 ret.Mean = proto.Float64(d.Sum() / float64(d.Count())) | 138 ret.Mean = proto.Float64(d.Sum() / float64(d.Count())) |
136 } | 139 } |
137 | 140 |
138 return &ret | 141 return &ret |
139 } | 142 } |
OLD | NEW |