com.netflix.hystrix.HystrixThreadPoolMetrics Java Examples

The following examples show how to use com.netflix.hystrix.HystrixThreadPoolMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicrometerMetricsPublisherThreadPool.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public MicrometerMetricsPublisherThreadPool(
    final MeterRegistry meterRegistry,
    final HystrixThreadPoolKey threadPoolKey,
    final HystrixThreadPoolMetrics metrics,
    final HystrixThreadPoolProperties properties,
    final HystrixMetricsPublisherThreadPool metricsPublisherForThreadPool) {
  this.meterRegistry = meterRegistry;
  this.metrics = metrics;
  this.properties = properties;
  this.metricsPublisherForThreadPool = metricsPublisherForThreadPool;

  this.tags = Tags.of("key", threadPoolKey.name());
}
 
Example #2
Source File: HystrixPrometheusMetricsPublisherThreadPool.java    From prometheus-hystrix with Apache License 2.0 5 votes vote down vote up
public HystrixPrometheusMetricsPublisherThreadPool(
        HystrixMetricsCollector collector, HystrixThreadPoolKey key, HystrixThreadPoolMetrics metrics,
        HystrixThreadPoolProperties properties, boolean exportProperties,
        HystrixMetricsPublisherThreadPool delegate) {

    this.metrics = metrics;
    this.collector = collector;
    this.properties = properties;
    this.exportProperties = exportProperties;
    this.labels = new TreeMap<String, String>();
    this.labels.put("pool_name", key.name());
    this.delegate = delegate;
}
 
Example #3
Source File: JsonMapper.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
static String toJson(HystrixThreadPoolMetrics threadPoolMetrics) throws IOException {
    HystrixThreadPoolKey key = threadPoolMetrics.getThreadPoolKey();

    StringWriter jsonString = new StringWriter();
    JsonGenerator json = jsonFactory.createJsonGenerator(jsonString);
    json.writeStartObject();

    json.writeStringField("type", "HystrixThreadPool");
    json.writeStringField("name", key.name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    json.writeNumberField("currentActiveCount", threadPoolMetrics.getCurrentActiveCount().intValue());
    json.writeNumberField("currentCompletedTaskCount", threadPoolMetrics.getCurrentCompletedTaskCount().longValue());
    json.writeNumberField("currentCorePoolSize", threadPoolMetrics.getCurrentCorePoolSize().intValue());
    json.writeNumberField("currentLargestPoolSize", threadPoolMetrics.getCurrentLargestPoolSize().intValue());
    json.writeNumberField("currentMaximumPoolSize", threadPoolMetrics.getCurrentMaximumPoolSize().intValue());
    json.writeNumberField("currentPoolSize", threadPoolMetrics.getCurrentPoolSize().intValue());
    json.writeNumberField("currentQueueSize", threadPoolMetrics.getCurrentQueueSize().intValue());
    json.writeNumberField("currentTaskCount", threadPoolMetrics.getCurrentTaskCount().longValue());
    json.writeNumberField("rollingCountThreadsExecuted", threadPoolMetrics.getRollingCountThreadsExecuted());
    json.writeNumberField("rollingMaxActiveThreads", threadPoolMetrics.getRollingMaxActiveThreads());

    json.writeNumberField("propertyValue_queueSizeRejectionThreshold", threadPoolMetrics.getProperties().queueSizeRejectionThreshold().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds", threadPoolMetrics.getProperties().metricsRollingStatisticalWindowInMilliseconds().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster

    json.writeEndObject();
    json.close();

    return jsonString.getBuffer().toString();
}
 
Example #4
Source File: HystrixMetricsStreamHandler.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
private Observable<Void> handleHystrixRequest(final HttpServerResponse<O> response) {
    writeHeaders(response);

    final Subject<Void, Void> subject = PublishSubject.create();
    final MultipleAssignmentSubscription subscription = new MultipleAssignmentSubscription();
    Subscription actionSubscription = Observable.timer(0, interval, TimeUnit.MILLISECONDS, Schedulers.computation())
            .subscribe(new Action1<Long>() {
                @Override
                public void call(Long tick) {
                    if (!response.getChannel().isOpen()) {
                        subscription.unsubscribe();
                        return;
                    }
                    try {
                        for (HystrixCommandMetrics commandMetrics : HystrixCommandMetrics.getInstances()) {
                            writeMetric(JsonMapper.toJson(commandMetrics), response);
                        }
                        for (HystrixThreadPoolMetrics threadPoolMetrics : HystrixThreadPoolMetrics.getInstances()) {
                            writeMetric(JsonMapper.toJson(threadPoolMetrics), response);
                        }
                    } catch (Exception e) {
                        subject.onError(e);
                    }
                }
            });
    subscription.set(actionSubscription);
    return subject;
}
 
Example #5
Source File: MicrometerMetricsPublisherThreadPool.java    From micrometer with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() {
  metricsPublisherForThreadPool.initialize();

  Gauge.builder(metricName("threads.active.current.count"), metrics::getCurrentActiveCount)
      .description("The approximate number of threads that are actively executing tasks.")
      .tags(tags)
      .register(meterRegistry);

  FunctionCounter.builder(metricName("threads.cumulative.count"), metrics, HystrixThreadPoolMetrics::getCumulativeCountThreadsExecuted)
      .description("Cumulative count of number of threads since the start of the application.")
      .tags(tags.and(Tag.of("type", "executed")))
      .register(meterRegistry);

  FunctionCounter.builder(metricName("threads.cumulative.count"), metrics, HystrixThreadPoolMetrics::getCumulativeCountThreadsRejected)
      .description("Cumulative count of number of threads since the start of the application.")
      .tags(tags.and(Tag.of("type", "rejected")))
      .register(meterRegistry);

  Gauge.builder(metricName("threads.pool.current.size"), metrics::getCurrentPoolSize)
      .description("The current number of threads in the pool.")
      .tags(tags)
      .register(meterRegistry);

  Gauge.builder(metricName("threads.largest.pool.current.size"), metrics::getCurrentLargestPoolSize)
      .description("The largest number of threads that have ever simultaneously been in the pool.")
      .tags(tags)
      .register(meterRegistry);

  Gauge.builder(metricName("threads.max.pool.current.size"), metrics::getCurrentMaximumPoolSize)
      .description("The maximum allowed number of threads.")
      .tags(tags)
      .register(meterRegistry);

  Gauge.builder(metricName("threads.core.pool.current.size"), metrics::getCurrentCorePoolSize)
      .description("The core number of threads.")
      .tags(tags)
      .register(meterRegistry);

  FunctionCounter.builder(metricName("tasks.cumulative.count"), metrics, m -> m.getCurrentCompletedTaskCount().longValue())
      .description("The approximate total number of tasks since the start of the application.")
      .tags(tags.and(Tag.of("type", "completed")))
      .register(meterRegistry);

  FunctionCounter.builder(metricName("tasks.cumulative.count"), metrics, m -> m.getCurrentTaskCount().longValue())
      .description("The approximate total number of tasks since the start of the application.")
      .tags(tags.and(Tag.of("type", "scheduled")))
      .register(meterRegistry);

  Gauge.builder(metricName("queue.current.size"), metrics::getCurrentQueueSize)
      .description("Current size of BlockingQueue used by the thread-pool.")
      .tags(tags)
      .register(meterRegistry);

  Gauge.builder(metricName("queue.max.size"), () -> properties.maxQueueSize().get())
      .description("Max size of BlockingQueue used by the thread-pool.")
      .tags(tags)
      .register(meterRegistry);

  Gauge.builder(metricName("queue.rejection.threshold.size"), () -> properties.queueSizeRejectionThreshold().get())
      .description("Artificial max size at which rejections will occur even if maxQueueSize has not been reached.")
      .tags(tags)
      .register(meterRegistry);
}
 
Example #6
Source File: HystrixMetricsProcessingJob.java    From cerberus with Apache License 2.0 4 votes vote down vote up
public void processHystrixThreadPoolMetrics() {
  for (HystrixThreadPoolMetrics metrics : HystrixThreadPoolMetrics.getInstances()) {
    Map<String, String> dimensions = ImmutableMap.of("name", metrics.getThreadPoolKey().name());
    log.debug(
        "threadPool:{}, rollingCounts[rejected:{}, executed:{}, maxActiveThreads:{}], cumulativeCounts[rejected:{}, executed:{}], {}",
        metrics.getThreadPoolKey().name(),
        metrics.getRollingCountThreadsRejected(),
        metrics.getRollingCountThreadsExecuted(),
        metrics.getRollingMaxActiveThreads(),
        metrics.getCumulativeCountThreadsRejected(),
        metrics.getCumulativeCountThreadsExecuted(),
        metrics.getThreadPool());

    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.rolling.rejected", metrics::getRollingCountThreadsRejected, dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.rolling.executed", metrics::getRollingCountThreadsExecuted, dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.rolling.maxActiveThreads",
        metrics::getRollingMaxActiveThreads,
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.cumulative.rejected",
        metrics::getCumulativeCountThreadsRejected,
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.cumulative.executed",
        metrics::getCumulativeCountThreadsExecuted,
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.activeThreads",
        () -> metrics.getThreadPool().getActiveCount(),
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.queuedTasks",
        () -> metrics.getThreadPool().getQueue().size(),
        dimensions);
    metricsService.getOrCreateCallbackGauge(
        "hystrix.threads.completedTasks",
        () -> metrics.getThreadPool().getCompletedTaskCount(),
        dimensions);
  }
}