-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Servo Metrics Publisher as optional submodule
- Loading branch information
1 parent
767cb9c
commit 6dad259
Showing
6 changed files
with
735 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
apply plugin: 'java' | ||
dependencies { | ||
compile project(':hystrix-core') | ||
compile 'com.netflix.servo:servo-core:0.4.27' | ||
} |
56 changes: 56 additions & 0 deletions
56
...rc/main/java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisher.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,56 @@ | ||
/** | ||
* Copyright 2012 Netflix, Inc. | ||
* | ||
* 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 com.netflix.hystrix.contrib.servopublisher; | ||
|
||
import com.netflix.hystrix.HystrixCircuitBreaker; | ||
import com.netflix.hystrix.HystrixCommandGroupKey; | ||
import com.netflix.hystrix.HystrixCommandKey; | ||
import com.netflix.hystrix.HystrixCommandMetrics; | ||
import com.netflix.hystrix.HystrixCommandProperties; | ||
import com.netflix.hystrix.HystrixThreadPoolKey; | ||
import com.netflix.hystrix.HystrixThreadPoolMetrics; | ||
import com.netflix.hystrix.HystrixThreadPoolProperties; | ||
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher; | ||
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherCommand; | ||
import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisherThreadPool; | ||
|
||
/** | ||
* Servo implementation of {@link HystrixMetricsPublisher}. | ||
* <p> | ||
* See <a href="https://github.com/Netflix/Hystrix/wiki/Plugins">Wiki docs</a> about plugins for more information. | ||
*/ | ||
public class HystrixServoMetricsPublisher extends HystrixMetricsPublisher { | ||
|
||
private static HystrixServoMetricsPublisher INSTANCE = new HystrixServoMetricsPublisher(); | ||
|
||
public static HystrixServoMetricsPublisher getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private HystrixServoMetricsPublisher() { | ||
} | ||
|
||
@Override | ||
public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) { | ||
return new HystrixServoMetricsPublisherCommand(commandKey, commandGroupKey, metrics, circuitBreaker, properties); | ||
} | ||
|
||
@Override | ||
public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties) { | ||
return new HystrixServoMetricsPublisherThreadPool(threadPoolKey, metrics, properties); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
...java/com/netflix/hystrix/contrib/servopublisher/HystrixServoMetricsPublisherAbstract.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,85 @@ | ||
/** | ||
* Copyright 2012 Netflix, Inc. | ||
* | ||
* 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 com.netflix.hystrix.contrib.servopublisher; | ||
|
||
import com.netflix.hystrix.HystrixCommandMetrics; | ||
import com.netflix.hystrix.util.HystrixRollingNumberEvent; | ||
import com.netflix.servo.annotations.DataSourceLevel; | ||
import com.netflix.servo.annotations.DataSourceType; | ||
import com.netflix.servo.monitor.AbstractMonitor; | ||
import com.netflix.servo.monitor.Counter; | ||
import com.netflix.servo.monitor.Gauge; | ||
import com.netflix.servo.monitor.Monitor; | ||
import com.netflix.servo.monitor.MonitorConfig; | ||
import com.netflix.servo.tag.Tag; | ||
|
||
/** | ||
* Utility used for Servo (https://github.com/Netflix/servo) based implementations of metrics publishers. | ||
*/ | ||
/* package */abstract class HystrixServoMetricsPublisherAbstract { | ||
|
||
protected abstract Tag getServoTypeTag(); | ||
|
||
protected abstract Tag getServoInstanceTag(); | ||
|
||
protected abstract class InformationalMetric<K> extends AbstractMonitor<K> { | ||
public InformationalMetric(MonitorConfig config) { | ||
super(config.withAdditionalTag(DataSourceType.INFORMATIONAL).withAdditionalTag(getServoTypeTag()).withAdditionalTag(getServoInstanceTag())); | ||
} | ||
} | ||
|
||
protected abstract class CounterMetric extends AbstractMonitor<Long> implements Counter { | ||
public CounterMetric(MonitorConfig config) { | ||
super(config.withAdditionalTag(DataSourceType.COUNTER).withAdditionalTag(getServoTypeTag()).withAdditionalTag(getServoInstanceTag())); | ||
} | ||
|
||
@Override | ||
public void increment() { | ||
throw new IllegalStateException("We are wrapping a value instead."); | ||
} | ||
|
||
@Override | ||
public void increment(long arg0) { | ||
throw new IllegalStateException("We are wrapping a value instead."); | ||
} | ||
} | ||
|
||
protected abstract class GaugeMetric extends AbstractMonitor<Number> implements Gauge<Number> { | ||
public GaugeMetric(MonitorConfig config) { | ||
super(config.withAdditionalTag(DataSourceType.GAUGE).withAdditionalTag(getServoTypeTag()).withAdditionalTag(getServoInstanceTag())); | ||
} | ||
} | ||
|
||
protected Monitor<?> getCumulativeCountForEvent(String name, final HystrixCommandMetrics metrics, final HystrixRollingNumberEvent event) { | ||
return new CounterMetric(MonitorConfig.builder(name).withTag(getServoTypeTag()).withTag(getServoInstanceTag()).build()) { | ||
@Override | ||
public Long getValue() { | ||
return metrics.getCumulativeCount(event); | ||
} | ||
|
||
}; | ||
} | ||
|
||
protected Monitor<?> getRollingCountForEvent(String name, final HystrixCommandMetrics metrics, final HystrixRollingNumberEvent event) { | ||
return new GaugeMetric(MonitorConfig.builder(name).withTag(DataSourceLevel.DEBUG).withTag(getServoTypeTag()).withTag(getServoInstanceTag()).build()) { | ||
@Override | ||
public Number getValue() { | ||
return metrics.getRollingCount(event); | ||
} | ||
|
||
}; | ||
} | ||
} |
Oops, something went wrong.