Comments (2)
If somebody needs it in future - it is ugly but...
//initialize hystrix to report only "hystrix_command_event_total" to prometheus
static {
CollectorRegistry registry = CollectorRegistry.defaultRegistry;
HystrixMetricsCollector collector = new HystrixMetricsCollector(null, var1 -> {}).register(registry);
HystrixPlugins plugins = HystrixPlugins.getInstance();
plugins.registerMetricsPublisher(new HystrixMetricsPublisher() {
@Override
public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) {
return new HystrixMetricsPublisherCommand() {
private final SortedMap<String, String> labels;
{
this.labels = new TreeMap<>();
this.labels.put("command_group", (commandGroupKey != null) ? commandGroupKey.name() : "default");
this.labels.put("command_name", commandKey.name());
}
private String processEventName(String name){
if(!name.equalsIgnoreCase("success")){
return "not_success";
}
return name;
}
@Override
public void initialize() {
final Map<String, Counter.Child> eventCounters = new HashMap<>();
for (HystrixEventType hystrixEventType : HystrixEventType.values()) {
if(hystrixEventType.isTerminal()) {
eventCounters.put(processEventName(hystrixEventType.name().toLowerCase()), addCounter(
"event", processEventName(hystrixEventType.name().toLowerCase()),
"terminal", Boolean.toString(true)
));
}
}
HystrixCommandCompletionStream.getInstance(commandKey)
.observe()
.subscribe(hystrixCommandCompletion -> {
for (HystrixEventType hystrixEventType : HystrixEventType.values()) {
int count = hystrixCommandCompletion.getEventCounts().getCount(hystrixEventType);
if (count > 0) {
eventCounters.get(processEventName(hystrixEventType.name().toLowerCase())).inc(count);
}
}
});
}
private Counter.Child addCounter(String... additionalLabels) {
SortedMap<String, String> labels = new TreeMap<String, String>(this.labels);
labels.putAll(this.labels);
Iterator<String> l = Arrays.asList(additionalLabels).iterator();
while (l.hasNext()) {
labels.put(l.next(), l.next());
}
return collector.addCounter("hystrix_command", "event_total",
"These are cumulative counts since the start of the application.", labels);
}
};
}
@Override
public HystrixMetricsPublisherThreadPool getMetricsPublisherForThreadPool(HystrixThreadPoolKey threadPoolKey, HystrixThreadPoolMetrics metrics, HystrixThreadPoolProperties properties) {
return () -> {};
}
@Override
public HystrixMetricsPublisherCollapser getMetricsPublisherForCollapser(HystrixCollapserKey collapserKey, HystrixCollapserMetrics metrics, HystrixCollapserProperties properties) {
return () -> {};
}
});
}
from prometheus-hystrix.
Currently there is no way to do this in the API. I would be happy to review and merge a pull request with the following:
- adding a lambda to the builder to filter metrics by name
- passing on the lambda to HystrixMetricsCollector() to apply the filter on each new metric created
What you can do today: you can configure Prometheus to discard unnecessary metrics using relabeling and the discard targets: https://www.robustperception.io/relabelling-can-discard-targets-timeseries-and-alerts
from prometheus-hystrix.
Related Issues (17)
- Negative latency when curcuit breaker is in open state HOT 6
- Ratpack Compatability HOT 4
- Error: text format parsing error in line 1: invalid metric name HOT 8
- java 7 compatibility HOT 6
- Fixed / global labels HOT 3
- hystrix_command_total and hystrix_command_error_total are difficult to use HOT 3
- Release on maven central HOT 8
- Need guide for transformation from old prometheus queries (3.4.0) to new queries (4.0.0) HOT 1
- Update <artifactId>simpleclient</artifactId> to 0.4.0 HOT 1
- prometheus-hystrix not working with micrometer.io libraries HOT 2
- Creating Dashboard for mean Latency HOT 2
- Reporting Hystrix Latency Percentiles as a Histogram HOT 16
- Remove some of hystrix metrics HOT 1
- Another strategy was already registered. HOT 7
- Graveyard this repo. HOT 11
- Metric names do not comply with prometheus standards and buckets sizes are not configurable HOT 18
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prometheus-hystrix.