2016-10-27 39 views
1

我想從DropWizard使用Guage度量來監視我的線程池大小。從dropWizard度量監視線程池度量

 ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
      2, 
      2, 
      1, 
      TimeUnit.MINUTES, 
      new ArrayBlockingQueue<Runnable>(100), 
      new ThreadPoolExecutor.DiscardPolicy()); 

    metricRegistry.register(name(ThreadPoolExecutor.class, "ThreadPoolRemainingCapacity"), (Gauge<Integer>)() -> threadPoolExecutor.getQueue().remainingCapacity()); 
    metricRegistry.register(name(ThreadPoolExecutor.class, "ThreadPoolOccupiedCapacity"), (Gauge<Integer>)() -> threadPoolExecutor.getQueue().size()); 

    return threadPoolExecutor; 

據我所知,這是在間隔時間內自動完成的。但是,我似乎沒有得到我的註冊指標的任何監測數據。雖然我的應用程序中的其他指標(如計數器和計時器)工作得很好。

有人可以幫我解決我錯了嗎?

謝謝。

+0

在哪裏呢度量標準來系統登錄從?你如何報告? – pandaadb

回答

1

您應該註冊一個實現(在有你可以忽略一些彈簧註釋本)之類的MetricSet接口的類:

@Component 
public class ThreadPoolGaugeSet implements MetricSet { 

    @Autowired 
    @Qualifier("taskExecutor") 
    private ThreadPoolTaskExecutor taskExecutor; 

    @Autowired 
    @Qualifier("taskExecutorLowPrio") 
    private ThreadPoolTaskExecutor lowPriotaskExecutor; 

    @Override 
    public Map<String, Metric> getMetrics() { 
     final Map<String, Metric> gauges = new HashMap<>(); 

     gauges.put("highPrioActive", (Gauge<Long>)() -> (long) taskExecutor.getActiveCount()); 
     gauges.put("lowPrioActive", (Gauge<Long>)() -> (long) lowPriotaskExecutor.getActiveCount()); 
     return gauges; 
    } 
} 

...

metricRegistry.register("threadpool", poolGauge);