-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
consumer_metrics.go
74 lines (62 loc) · 2.3 KB
/
consumer_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
// Copyright (c) 2018 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package consumer
import (
"strconv"
"github.com/jaegertracing/jaeger/pkg/metrics"
)
const consumerNamespace = "sarama-consumer"
type msgMetrics struct {
counter metrics.Counter
offsetGauge metrics.Gauge
lagGauge metrics.Gauge
}
type errMetrics struct {
errCounter metrics.Counter
}
type partitionMetrics struct {
startCounter metrics.Counter
closeCounter metrics.Counter
}
func (c *Consumer) namespace(topic string, partition int32) metrics.Factory {
return c.metricsFactory.Namespace(
metrics.NSOptions{
Name: consumerNamespace,
Tags: map[string]string{
"topic": topic,
"partition": strconv.Itoa(int(partition)),
},
})
}
func (c *Consumer) newMsgMetrics(topic string, partition int32) msgMetrics {
f := c.namespace(topic, partition)
return msgMetrics{
counter: f.Counter(metrics.Options{Name: "messages", Tags: nil}),
offsetGauge: f.Gauge(metrics.Options{Name: "current-offset", Tags: nil}),
lagGauge: f.Gauge(metrics.Options{Name: "offset-lag", Tags: nil}),
}
}
func (c *Consumer) newErrMetrics(topic string, partition int32) errMetrics {
return errMetrics{errCounter: c.namespace(topic, partition).Counter(metrics.Options{Name: "errors", Tags: nil})}
}
func (c *Consumer) partitionMetrics(topic string, partition int32) partitionMetrics {
f := c.namespace(topic, partition)
return partitionMetrics{
closeCounter: f.Counter(metrics.Options{Name: "partition-close", Tags: nil}),
startCounter: f.Counter(metrics.Options{Name: "partition-start", Tags: nil}),
}
}
func partitionsHeldGauge(metricsFactory metrics.Factory) metrics.Gauge {
return metricsFactory.Namespace(metrics.NSOptions{Name: consumerNamespace, Tags: nil}).Gauge(metrics.Options{Name: "partitions-held", Tags: nil})
}