/
metrics.go
107 lines (91 loc) · 3.83 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package kafkareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kafkareceiver"
import (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
)
var (
tagInstanceName, _ = tag.NewKey("name")
tagPartition, _ = tag.NewKey("partition")
statMessageCount = stats.Int64("kafka_receiver_messages", "Number of received messages", stats.UnitDimensionless)
statMessageOffset = stats.Int64("kafka_receiver_current_offset", "Current message offset", stats.UnitDimensionless)
statMessageOffsetLag = stats.Int64("kafka_receiver_offset_lag", "Current offset lag", stats.UnitDimensionless)
statPartitionStart = stats.Int64("kafka_receiver_partition_start", "Number of started partitions", stats.UnitDimensionless)
statPartitionClose = stats.Int64("kafka_receiver_partition_close", "Number of finished partitions", stats.UnitDimensionless)
statUnmarshalFailedMetricPoints = stats.Int64("kafka_receiver_unmarshal_failed_metric_points", "Number of metric points failed to be unmarshaled", stats.UnitDimensionless)
statUnmarshalFailedLogRecords = stats.Int64("kafka_receiver_unmarshal_failed_log_records", "Number of log records failed to be unmarshaled", stats.UnitDimensionless)
statUnmarshalFailedSpans = stats.Int64("kafka_receiver_unmarshal_failed_spans", "Number of spans failed to be unmarshaled", stats.UnitDimensionless)
)
// metricViews return metric views for Kafka receiver.
func metricViews() []*view.View {
partitionAgnosticTagKeys := []tag.Key{tagInstanceName}
partitionSpecificTagKeys := []tag.Key{tagInstanceName, tagPartition}
countMessages := &view.View{
Name: statMessageCount.Name(),
Measure: statMessageCount,
Description: statMessageCount.Description(),
TagKeys: partitionSpecificTagKeys,
Aggregation: view.Sum(),
}
lastValueOffset := &view.View{
Name: statMessageOffset.Name(),
Measure: statMessageOffset,
Description: statMessageOffset.Description(),
TagKeys: partitionSpecificTagKeys,
Aggregation: view.LastValue(),
}
lastValueOffsetLag := &view.View{
Name: statMessageOffsetLag.Name(),
Measure: statMessageOffsetLag,
Description: statMessageOffsetLag.Description(),
TagKeys: partitionSpecificTagKeys,
Aggregation: view.LastValue(),
}
countPartitionStart := &view.View{
Name: statPartitionStart.Name(),
Measure: statPartitionStart,
Description: statPartitionStart.Description(),
TagKeys: partitionAgnosticTagKeys,
Aggregation: view.Sum(),
}
countPartitionClose := &view.View{
Name: statPartitionClose.Name(),
Measure: statPartitionClose,
Description: statPartitionClose.Description(),
TagKeys: partitionAgnosticTagKeys,
Aggregation: view.Sum(),
}
countUnmarshalFailedMetricPoints := &view.View{
Name: statUnmarshalFailedMetricPoints.Name(),
Measure: statUnmarshalFailedMetricPoints,
Description: statUnmarshalFailedMetricPoints.Description(),
TagKeys: partitionAgnosticTagKeys,
Aggregation: view.Sum(),
}
countUnmarshalFailedLogRecords := &view.View{
Name: statUnmarshalFailedLogRecords.Name(),
Measure: statUnmarshalFailedLogRecords,
Description: statUnmarshalFailedLogRecords.Description(),
TagKeys: partitionAgnosticTagKeys,
Aggregation: view.Sum(),
}
countUnmarshalFailedSpans := &view.View{
Name: statUnmarshalFailedSpans.Name(),
Measure: statUnmarshalFailedSpans,
Description: statUnmarshalFailedSpans.Description(),
TagKeys: partitionAgnosticTagKeys,
Aggregation: view.Sum(),
}
return []*view.View{
countMessages,
lastValueOffset,
lastValueOffsetLag,
countPartitionStart,
countPartitionClose,
countUnmarshalFailedMetricPoints,
countUnmarshalFailedLogRecords,
countUnmarshalFailedSpans,
}
}