Giter Club home page Giter Club logo

Comments (2)

bojanv55 avatar bojanv55 commented on June 8, 2024

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.

ahus1 avatar ahus1 commented on June 8, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.