use of org.springside.modules.metrics.metric.Gauge in project springside4 by springside.
the class ReportScheduler method report.
/**
* 定期计算所有Metrics, 并调用所有Reporter进行汇报.
*/
public void report() {
// 取出所有Metrics, 未按名称排序.
Map<String, Gauge> gaugeMap = metricRegistry.getGauges();
Map<String, Counter> counterMap = metricRegistry.getCounters();
Map<String, Histogram> histogramMap = metricRegistry.getHistograms();
Map<String, Timer> timerMap = metricRegistry.getTimers();
// 计算单位时间内的metrics值, 存入该Metrics的Snapshot中,并清零原始数据
for (Gauge gauge : gaugeMap.values()) {
gauge.calculateMetric();
}
for (Counter counter : counterMap.values()) {
counter.calculateMetric();
}
for (Histogram histogram : histogramMap.values()) {
histogram.calculateMetric();
}
for (Timer timer : timerMap.values()) {
timer.calculateMetric();
}
// 调度所有Reporters 输出 metrics值
for (Reporter reporter : reporters) {
reporter.report(gaugeMap, counterMap, histogramMap, timerMap);
}
}
use of org.springside.modules.metrics.metric.Gauge in project springside4 by springside.
the class MetricExamples method gaugeExample.
@Test
public void gaugeExample() throws InterruptedException {
MetricRegistry metricRegistry = new MetricRegistry();
// 使用ConsoleReporter
ConsoleReporter consoleReporter = new ConsoleReporter();
final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
Gauge<Long> usedMemoryGague = new Gauge<Long>() {
public Long getValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
Gauge<Long> cachedUsedMemoryGague = new CachedGauge<Long>(10, TimeUnit.SECONDS) {
public Long loadValue() {
return memoryMXBean.getHeapMemoryUsage().getUsed();
}
};
metricRegistry.registerGauge(MetricRegistry.name("JVM", "usedMemory"), usedMemoryGague);
metricRegistry.registerGauge(MetricRegistry.name("JVM", "cachedUsedMemory"), cachedUsedMemoryGague);
ReportScheduler scheduler = new ReportScheduler(metricRegistry, consoleReporter);
scheduler.start(1, TimeUnit.SECONDS);
Thread.sleep(1050);
// use some memory
List<Integer> list = new ArrayList<Integer>(200000);
list.add(1);
Thread.sleep(1050);
scheduler.stop();
}
Aggregations