use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.
the class ThroughputCounter method gauges.
public Map<String, Gauge<Long>> gauges() {
Map<String, Gauge<Long>> gauges = Maps.newHashMap();
final TrafficCounter tc = this.getTrafficCounter();
gauges.put("read_bytes_1sec", new Gauge<Long>() {
@Override
public Long getValue() {
return tc.getLastReadBytes();
}
});
gauges.put("written_bytes_1sec", new Gauge<Long>() {
@Override
public Long getValue() {
return tc.getLastWrittenBytes();
}
});
gauges.put("read_bytes_total", new Gauge<Long>() {
@Override
public Long getValue() {
return tc.getCumulativeReadBytes();
}
});
gauges.put("written_bytes_total", new Gauge<Long>() {
@Override
public Long getValue() {
return tc.getCumulativeWrittenBytes();
}
});
return gauges;
}
use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.
the class ThroughputResource method total.
@GET
@Timed
@RequiresPermissions(RestPermissions.THROUGHPUT_READ)
@ApiOperation(value = "Current throughput of this node in messages per second")
@Produces(MediaType.APPLICATION_JSON)
public Throughput total() {
final SortedMap<String, Gauge> gauges = metricRegistry.getGauges(MetricUtils.filterSingleMetric(GlobalMetricNames.OUTPUT_THROUGHPUT_RATE));
final Gauge gauge = Iterables.getOnlyElement(gauges.values(), null);
if (gauge == null || !(gauge.getValue() instanceof Number)) {
return Throughput.create(0);
} else {
return Throughput.create(((Number) gauge.getValue()).longValue());
}
}
use of com.codahale.metrics.Gauge in project graylog2-server by Graylog2.
the class MetricUtilsTest method safelyRegister.
@Test
public void safelyRegister() {
final MetricRegistry metricRegistry = new MetricRegistry();
final Gauge<Long> longGauge = new Gauge<Long>() {
@Override
public Long getValue() {
return 0L;
}
};
final Gauge<Long> newGauge = MetricUtils.safelyRegister(metricRegistry, "somename", longGauge);
assertSame("metric objects are identical", longGauge, newGauge);
try {
MetricUtils.safelyRegister(metricRegistry, "somename", longGauge);
} catch (Exception e) {
fail("Should not have thrown: " + e.getMessage());
}
try {
//noinspection unused
final Counter somename = MetricUtils.safelyRegister(metricRegistry, "somename", new Counter());
} catch (Exception e) {
assertTrue("Registering a metric with a different metric type fails on using it", e instanceof ClassCastException);
}
}
use of com.codahale.metrics.Gauge in project beam by apache.
the class WithMetricsSupport method aggregatorMetricToGauges.
private Function<Map.Entry<String, Metric>, Map<String, Gauge>> aggregatorMetricToGauges() {
return new Function<Map.Entry<String, Metric>, Map<String, Gauge>>() {
@Override
public Map<String, Gauge> apply(final Map.Entry<String, Metric> entry) {
final NamedAggregators agg = ((AggregatorMetric) entry.getValue()).getNamedAggregators();
final String parentName = entry.getKey();
final Map<String, Gauge> gaugeMap = Maps.transformEntries(agg.renderAll(), toGauge());
final Map<String, Gauge> fullNameGaugeMap = Maps.newLinkedHashMap();
for (Map.Entry<String, Gauge> gaugeEntry : gaugeMap.entrySet()) {
fullNameGaugeMap.put(parentName + "." + gaugeEntry.getKey(), gaugeEntry.getValue());
}
return Maps.filterValues(fullNameGaugeMap, Predicates.notNull());
}
};
}
use of com.codahale.metrics.Gauge in project lucene-solr by apache.
the class RequestHandlersTest method testInitCount.
@Test
public void testInitCount() {
String registry = h.getCore().getCoreMetricManager().getRegistryName();
SolrMetricManager manager = h.getCoreContainer().getMetricManager();
Gauge<Number> g = (Gauge<Number>) manager.registry(registry).getMetrics().get("QUERY.mock.initCount");
assertEquals("Incorrect init count", 1, g.getValue().intValue());
}
Aggregations