Debian Codegraph @

pdata/pmetric/metrics.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package pmetric // import "go.opentelemetry.io/collector/pdata/pmetric"
5
6 // MarkReadOnly marks the Metrics as shared so that no further modifications can be done on it.
7 func (ms Metrics) MarkReadOnly() {
8 ms.getState().MarkReadOnly()
9 }
10
11 // IsReadOnly returns true if this Metrics instance is read-only.
12 func (ms Metrics) IsReadOnly() bool {
13 return ms.getState().IsReadOnly()
14 }
15
16 // MetricCount calculates the total number of metrics.
17 func (ms Metrics) MetricCount() int {
18 metricCount := 0
19 rms := ms.ResourceMetrics()
20 for i := 0; i < rms.Len(); i++ {
21 rm := rms.At(i)
22 ilms := rm.ScopeMetrics()
23 for j := 0; j < ilms.Len(); j++ {
24 ilm := ilms.At(j)
25 metricCount += ilm.Metrics().Len()
26 }
27 }
28 return metricCount
29 }
30
31 // DataPointCount calculates the total number of data points.
32 func (ms Metrics) DataPointCount() (dataPointCount int) {
33 rms := ms.ResourceMetrics()
34 for i := 0; i < rms.Len(); i++ {
35 rm := rms.At(i)
36 ilms := rm.ScopeMetrics()
37 for j := 0; j < ilms.Len(); j++ {
38 ilm := ilms.At(j)
39 ms := ilm.Metrics()
40 for k := 0; k < ms.Len(); k++ {
41 m := ms.At(k)
42 switch m.Type() {
43 case MetricTypeGauge:
44 dataPointCount += m.Gauge().DataPoints().Len()
45 case MetricTypeSum:
46 dataPointCount += m.Sum().DataPoints().Len()
47 case MetricTypeHistogram:
48 dataPointCount += m.Histogram().DataPoints().Len()
49 case MetricTypeExponentialHistogram:
50 dataPointCount += m.ExponentialHistogram().DataPoints().Len()
51 case MetricTypeSummary:
52 dataPointCount += m.Summary().DataPoints().Len()
53 }
54 }
55 }
56 }
57 return dataPointCount
58 }