MCPcopy
hub / github.com/kubernetes/node-problem-detector / NewInt64Metric

Function NewInt64Metric

pkg/util/metrics/metric_int64.go:45–81  ·  view source on GitHub ↗

NewInt64Metric create a Int64Metric metric, returns nil when viewName is empty.

(metricID MetricID, viewName string, description string, unit string, aggregation Aggregation, tagNames []string)

Source from the content-addressed store, hash-verified

43
44// NewInt64Metric create a Int64Metric metric, returns nil when viewName is empty.
45func NewInt64Metric(metricID MetricID, viewName string, description string, unit string, aggregation Aggregation, tagNames []string) (*Int64Metric, error) {
46 if viewName == "" {
47 return nil, nil
48 }
49
50 MetricMap.AddMapping(metricID, viewName)
51
52 tagKeys, err := getTagKeysFromNames(tagNames)
53 if err != nil {
54 return nil, fmt.Errorf("failed to create metric %q because of tag creation failure: %v", viewName, err)
55 }
56
57 var aggregationMethod *view.Aggregation
58 switch aggregation {
59 case LastValue:
60 aggregationMethod = view.LastValue()
61 case Sum:
62 aggregationMethod = view.Sum()
63 default:
64 return nil, fmt.Errorf("unknown aggregation option %q", aggregation)
65 }
66
67 measure := stats.Int64(viewName, description, unit)
68 newView := &view.View{
69 Name: viewName,
70 Measure: measure,
71 Description: description,
72 Aggregation: aggregationMethod,
73 TagKeys: tagKeys,
74 }
75 if err := view.Register(newView); err != nil {
76 return nil, fmt.Errorf("failed to register view for metric %q: %v", viewName, err)
77 }
78
79 metric := Int64Metric{viewName, measure}
80 return &metric, nil
81}
82
83// Record records a measurement for the metric, with provided tags as metric labels.
84func (metric *Int64Metric) Record(tags map[string]string, measurement int64) error {

Callers 7

NewHostCollectorOrDieFunction · 0.92
NewDiskCollectorOrDieFunction · 0.92
NewMemoryCollectorOrDieFunction · 0.92
newInt64MetricFunction · 0.92
NewCPUCollectorOrDieFunction · 0.92

Calls 3

getTagKeysFromNamesFunction · 0.85
AddMappingMethod · 0.80
RegisterMethod · 0.80

Tested by

no test coverage detected