summaryrefslogtreecommitdiff
path: root/app-metrics/burrow_exporter/files/burrow_exporter-0.0.6-skippable-metrics.patch
blob: 1b9c84599eb046ab1dd561d99a9272ab97cc7c9d (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
From 50db40e49750378e22e2b638754ff07ff29f5362 Mon Sep 17 00:00:00 2001
From: NovaPS6 <NovaPS6@ostmw0195464.bskyb.com>
Date: Wed, 8 Aug 2018 14:43:33 +0100
Subject: [PATCH] make all metrics skippable

Change import back to jirwin
---
 .gitignore                  |   1 +
 burrow-exporter.go          |  67 +++++++++++++++++------
 burrow_exporter/exporter.go | 102 +++++++++++++++++++++---------------
 3 files changed, 113 insertions(+), 57 deletions(-)

diff --git a/.gitignore b/.gitignore
index 502219c..a8e0d62 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,3 +18,4 @@
 burrow-exporter
 dist/
 vendor/
+.idea/
diff --git a/burrow-exporter.go b/burrow-exporter.go
index 1e60d67..b4e871b 100644
--- a/burrow-exporter.go
+++ b/burrow-exporter.go
@@ -14,7 +14,7 @@ import (
 	"github.com/jirwin/burrow_exporter/burrow_exporter"
 )
 
-var Version = "0.0.4"
+var Version = "0.0.5"
 
 func main() {
 	app := cli.NewApp()
@@ -22,36 +22,61 @@ func main() {
 	app.Name = "burrow-exporter"
 	app.Flags = []cli.Flag{
 		cli.StringFlag{
-			Name:  "burrow-addr",
-			Usage: "Address that burrow is listening on",
+			Name:   "burrow-addr",
+			Usage:  "Address that burrow is listening on",
 			EnvVar: "BURROW_ADDR",
 		},
 		cli.StringFlag{
-			Name:  "metrics-addr",
-			Usage: "Address to run prometheus on",
+			Name:   "metrics-addr",
+			Usage:  "Address to run prometheus on",
 			EnvVar: "METRICS_ADDR",
 		},
 		cli.IntFlag{
-			Name:  "interval",
-			Usage: "The interval(seconds) specifies how often to scrape burrow.",
+			Name:   "interval",
+			Usage:  "The interval(seconds) specifies how often to scrape burrow.",
 			EnvVar: "INTERVAL",
 		},
 		cli.IntFlag{
-			Name:  "api-version",
-			Usage: "Burrow API version to leverage",
-			Value: 2,
+			Name:   "api-version",
+			Usage:  "Burrow API version to leverage",
+			Value:  2,
 			EnvVar: "API_VERSION",
 		},
 		cli.BoolFlag{
-			Name: "skip-partition-status",
-			Usage: "Skip exporting the per-partition status",
+			Name:   "skip-partition-status",
+			Usage:  "Skip exporting the per-partition status",
 			EnvVar: "SKIP_PARTITION_STATUS",
 		},
 		cli.BoolFlag{
-			Name: "skip-group-status",
-			Usage: "Skip exporting the per-group status",
+			Name:   "skip-group-status",
+			Usage:  "Skip exporting the per-group status",
 			EnvVar: "SKIP_GROUP_STATUS",
 		},
+		cli.BoolFlag{
+			Name:   "skip-partition-lag",
+			Usage:  "Skip exporting the partition lag",
+			EnvVar: "SKIP_PARTITION_LAG",
+		},
+		cli.BoolFlag{
+			Name:   "skip-partition-current-offset",
+			Usage:  "Skip exporting the current offset per partition",
+			EnvVar: "SKIP_PARTITION_CURRENT_OFFSET",
+		},
+		cli.BoolFlag{
+			Name:   "skip-partition-max-offset",
+			Usage:  "Skip exporting the partition max offset",
+			EnvVar: "SKIP_PARTITION_MAX_OFFSET",
+		},
+		cli.BoolFlag{
+			Name:   "skip-total-lag",
+			Usage:  "Skip exporting the total lag",
+			EnvVar: "SKIP_TOTAL_LAG",
+		},
+		cli.BoolFlag{
+			Name:   "skip-topic-partition-offset",
+			Usage:  "Skip exporting topic partition offset",
+			EnvVar: "SKIP_TOPIC_PARTITION_OFFSET",
+		},
 	}
 
 	app.Action = func(c *cli.Context) error {
@@ -76,8 +101,18 @@ func main() {
 
 		ctx, cancel := context.WithCancel(context.Background())
 
-		exporter := burrow_exporter.MakeBurrowExporter(c.String("burrow-addr"), c.Int("api-version"),
-			c.String("metrics-addr"), c.Int("interval"), c.Bool("skip-partition-status"), c.Bool("skip-group-status"))
+		exporter := burrow_exporter.MakeBurrowExporter(
+			c.String("burrow-addr"),
+			c.Int("api-version"),
+			c.String("metrics-addr"),
+			c.Int("interval"),
+			c.Bool("skip-partition-status"),
+			c.Bool("skip-group-status"),
+			c.Bool("skip-partition-lag"),
+			c.Bool("skip-partition-current-offset"),
+			c.Bool("skip-partition-max-offset"),
+			c.Bool("skip-total-lag"),
+			c.Bool("skip-topic-partition-offset"))
 		go exporter.Start(ctx)
 
 		<-done
diff --git a/burrow_exporter/exporter.go b/burrow_exporter/exporter.go
index 7adc398..8b48b35 100644
--- a/burrow_exporter/exporter.go
+++ b/burrow_exporter/exporter.go
@@ -16,12 +16,17 @@ import (
 )
 
 type BurrowExporter struct {
-	client              *BurrowClient
-	metricsListenAddr   string
-	interval            int
-	wg                  sync.WaitGroup
-	skipPartitionStatus bool
-	skipConsumerStatus  bool
+	client                     *BurrowClient
+	metricsListenAddr          string
+	interval                   int
+	wg                         sync.WaitGroup
+	skipPartitionStatus        bool
+	skipConsumerStatus         bool
+	skipPartitionLag           bool
+	skipPartitionCurrentOffset bool
+	skipPartitionMaxOffset     bool
+	skipTotalLag               bool
+	skipTopicPartitionOffset   bool
 }
 
 func (be *BurrowExporter) processGroup(cluster, group string) {
@@ -34,19 +39,23 @@ func (be *BurrowExporter) processGroup(cluster, group string) {
 	}
 
 	for _, partition := range status.Status.Partitions {
-		KafkaConsumerPartitionLag.With(prometheus.Labels{
-			"cluster":   status.Status.Cluster,
-			"group":     status.Status.Group,
-			"topic":     partition.Topic,
-			"partition": strconv.Itoa(int(partition.Partition)),
-		}).Set(float64(partition.End.Lag))
-
-		KafkaConsumerPartitionCurrentOffset.With(prometheus.Labels{
-			"cluster":   status.Status.Cluster,
-			"group":     status.Status.Group,
-			"topic":     partition.Topic,
-			"partition": strconv.Itoa(int(partition.Partition)),
-		}).Set(float64(partition.End.Offset))
+		if !be.skipPartitionLag {
+			KafkaConsumerPartitionLag.With(prometheus.Labels{
+				"cluster":   status.Status.Cluster,
+				"group":     status.Status.Group,
+				"topic":     partition.Topic,
+				"partition": strconv.Itoa(int(partition.Partition)),
+			}).Set(float64(partition.End.Lag))
+		}
+
+		if !be.skipPartitionCurrentOffset {
+			KafkaConsumerPartitionCurrentOffset.With(prometheus.Labels{
+				"cluster":   status.Status.Cluster,
+				"group":     status.Status.Group,
+				"topic":     partition.Topic,
+				"partition": strconv.Itoa(int(partition.Partition)),
+			}).Set(float64(partition.End.Offset))
+		}
 
 		if !be.skipPartitionStatus {
 			KafkaConsumerPartitionCurrentStatus.With(prometheus.Labels{
@@ -57,18 +66,22 @@ func (be *BurrowExporter) processGroup(cluster, group string) {
 			}).Set(float64(Status[partition.Status]))
 		}
 
-		KafkaConsumerPartitionMaxOffset.With(prometheus.Labels{
-			"cluster":   status.Status.Cluster,
-			"group":     status.Status.Group,
-			"topic":     partition.Topic,
-			"partition": strconv.Itoa(int(partition.Partition)),
-		}).Set(float64(partition.End.MaxOffset))
+		if !be.skipPartitionMaxOffset {
+			KafkaConsumerPartitionMaxOffset.With(prometheus.Labels{
+				"cluster":   status.Status.Cluster,
+				"group":     status.Status.Group,
+				"topic":     partition.Topic,
+				"partition": strconv.Itoa(int(partition.Partition)),
+			}).Set(float64(partition.End.MaxOffset))
+		}
 	}
 
-	KafkaConsumerTotalLag.With(prometheus.Labels{
-		"cluster": status.Status.Cluster,
-		"group":   status.Status.Group,
-	}).Set(float64(status.Status.TotalLag))
+	if !be.skipTotalLag {
+		KafkaConsumerTotalLag.With(prometheus.Labels{
+			"cluster": status.Status.Cluster,
+			"group":   status.Status.Group,
+		}).Set(float64(status.Status.TotalLag))
+	}
 
 	if !be.skipConsumerStatus {
 		KafkaConsumerStatus.With(prometheus.Labels{
@@ -88,12 +101,14 @@ func (be *BurrowExporter) processTopic(cluster, topic string) {
 		return
 	}
 
-	for i, offset := range details.Offsets {
-		KafkaTopicPartitionOffset.With(prometheus.Labels{
-			"cluster":   cluster,
-			"topic":     topic,
-			"partition": strconv.Itoa(i),
-		}).Set(float64(offset))
+	if !be.skipTopicPartitionOffset {
+		for i, offset := range details.Offsets {
+			KafkaTopicPartitionOffset.With(prometheus.Labels{
+				"cluster":   cluster,
+				"topic":     topic,
+				"partition": strconv.Itoa(i),
+			}).Set(float64(offset))
+		}
 	}
 }
 
@@ -208,12 +223,17 @@ func (be *BurrowExporter) mainLoop(ctx context.Context) {
 }
 
 func MakeBurrowExporter(burrowUrl string, apiVersion int, metricsAddr string, interval int, skipPartitionStatus bool,
-	skipConsumerStatus bool) *BurrowExporter {
+	skipConsumerStatus bool, skipPartitionLag bool, skipPartitionCurrentOffset bool, skipPartitionMaxOffset bool, skipTotalLag bool, skipTopicPartitionOffset bool) *BurrowExporter {
 	return &BurrowExporter{
-		client:              MakeBurrowClient(burrowUrl, apiVersion),
-		metricsListenAddr:   metricsAddr,
-		interval:            interval,
-		skipPartitionStatus: skipPartitionStatus,
-		skipConsumerStatus:  skipConsumerStatus,
+		client:                     MakeBurrowClient(burrowUrl, apiVersion),
+		metricsListenAddr:          metricsAddr,
+		interval:                   interval,
+		skipPartitionStatus:        skipPartitionStatus,
+		skipConsumerStatus:         skipConsumerStatus,
+		skipPartitionLag:           skipPartitionLag,
+		skipPartitionCurrentOffset: skipPartitionCurrentOffset,
+		skipPartitionMaxOffset:     skipPartitionMaxOffset,
+		skipTotalLag:               skipTotalLag,
+		skipTopicPartitionOffset:   skipTopicPartitionOffset,
 	}
 }