-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to kafka-2.0.0 profile as the default
And add the missing MicrometerMetricsCollector from #1342
- Loading branch information
Henry Cai
committed
May 25, 2020
1 parent
5d109e3
commit 556ca78
Showing
2 changed files
with
78 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/com/pinterest/secor/monitoring/MicroMeterMetricCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 com.pinterest.secor.monitoring; | ||
|
||
import com.pinterest.secor.common.SecorConfig; | ||
|
||
import com.google.common.util.concurrent.AtomicDouble; | ||
import io.micrometer.core.instrument.Clock; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Metrics; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.jmx.JmxConfig; | ||
import io.micrometer.jmx.JmxMeterRegistry; | ||
import io.micrometer.statsd.StatsdConfig; | ||
import io.micrometer.statsd.StatsdMeterRegistry; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* MicorMeter meters can integrate with many different metrics backend | ||
* (StatsD/Promethus/Graphite/JMX etc, see https://micrometer.io/docs) | ||
*/ | ||
public class MicroMeterMetricCollector implements MetricCollector { | ||
@Override | ||
public void initialize(SecorConfig config) { | ||
if (config.getMicroMeterCollectorStatsdEnabled()) { | ||
MeterRegistry statsdRegistry = | ||
new StatsdMeterRegistry(StatsdConfig.DEFAULT, Clock.SYSTEM); | ||
Metrics.addRegistry(statsdRegistry); | ||
} | ||
|
||
if (config.getMicroMeterCollectorJmxEnabled()) { | ||
MeterRegistry jmxRegistry = new JmxMeterRegistry(JmxConfig.DEFAULT, Clock.SYSTEM); | ||
Metrics.addRegistry(jmxRegistry); | ||
} | ||
} | ||
|
||
@Override | ||
public void increment(String label, String topic) { | ||
Metrics.counter(label, Collections.singletonList(Tag.of("topic", topic))).increment(); | ||
} | ||
|
||
@Override | ||
public void increment(String label, int delta, String topic) { | ||
Metrics.counter(label, Collections.singletonList(Tag.of("topic", topic))).increment(delta); | ||
} | ||
|
||
@Override | ||
public void metric(String label, double value, String topic) { | ||
Metrics.gauge(label, Collections.singletonList( | ||
Tag.of("topic", topic)), new AtomicDouble(0)).set(value); | ||
} | ||
|
||
@Override | ||
public void gauge(String label, double value, String topic) { | ||
Metrics.gauge(label, Collections.singletonList( | ||
Tag.of("topic", topic)), new AtomicDouble(0)).set(value); | ||
} | ||
} |