use of com.codahale.metrics.Counter in project spring-boot by spring-projects.
the class DropwizardMetricServices method incrementInternal.
private void incrementInternal(String name, long value) {
if (name.startsWith("meter")) {
Meter meter = this.registry.meter(name);
meter.mark(value);
} else {
name = wrapCounterName(name);
Counter counter = this.registry.counter(name);
counter.inc(value);
}
}
use of com.codahale.metrics.Counter in project spring-boot by spring-projects.
the class MetricRegistryMetricReader method findOne.
@Override
public Metric<?> findOne(String metricName) {
String name = this.names.get(metricName);
if (name == null) {
return null;
}
com.codahale.metrics.Metric metric = this.registry.getMetrics().get(name);
if (metric == null) {
return null;
}
if (metric instanceof Counter) {
Counter counter = (Counter) metric;
return new Metric<Number>(metricName, counter.getCount());
}
if (metric instanceof Gauge) {
Object value = ((Gauge<?>) metric).getValue();
if (value instanceof Number) {
return new Metric<>(metricName, (Number) value);
}
if (logger.isDebugEnabled()) {
logger.debug("Ignoring gauge '" + name + "' (" + metric + ") as its value is not a Number");
}
return null;
}
if (metric instanceof Sampling) {
if (metricName.contains(".snapshot.")) {
Number value = getMetric(((Sampling) metric).getSnapshot(), metricName);
if (metric instanceof Timer) {
// convert back to MILLISEC
value = TimeUnit.MILLISECONDS.convert(value.longValue(), TimeUnit.NANOSECONDS);
}
return new Metric<>(metricName, value);
}
}
return new Metric<>(metricName, getMetric(metric, metricName));
}
use of com.codahale.metrics.Counter in project alluxio by Alluxio.
the class WebInterfaceMasterMetricsServlet method populateValues.
/**
* Populates key, value pairs for UI display.
*
* @param request The {@link HttpServletRequest} object
* @throws IOException if an I/O error occurs
*/
private void populateValues(HttpServletRequest request) throws IOException {
MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
Long masterCapacityTotal = (Long) mr.getGauges().get(MetricsSystem.getMasterMetricName(BlockMaster.Metrics.CAPACITY_TOTAL)).getValue();
Long masterCapacityUsed = (Long) mr.getGauges().get(MetricsSystem.getMasterMetricName(BlockMaster.Metrics.CAPACITY_USED)).getValue();
int masterCapacityUsedPercentage = (masterCapacityTotal > 0) ? (int) (100L * masterCapacityUsed / masterCapacityTotal) : 0;
request.setAttribute("masterCapacityUsedPercentage", masterCapacityUsedPercentage);
request.setAttribute("masterCapacityFreePercentage", 100 - masterCapacityUsedPercentage);
Long masterUnderfsCapacityTotal = (Long) mr.getGauges().get(MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.UFS_CAPACITY_TOTAL)).getValue();
Long masterUnderfsCapacityUsed = (Long) mr.getGauges().get(MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.UFS_CAPACITY_USED)).getValue();
int masterUnderfsCapacityUsedPercentage = (masterUnderfsCapacityTotal > 0) ? (int) (100L * masterUnderfsCapacityUsed / masterUnderfsCapacityTotal) : 0;
request.setAttribute("masterUnderfsCapacityUsedPercentage", masterUnderfsCapacityUsedPercentage);
request.setAttribute("masterUnderfsCapacityFreePercentage", 100 - masterUnderfsCapacityUsedPercentage);
Map<String, Counter> counters = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return !(name.endsWith("Ops"));
}
});
Map<String, Counter> rpcInvocations = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.endsWith("Ops");
}
});
Map<String, Metric> operations = new TreeMap<>();
// Remove the instance name from the metrics.
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
operations.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
String filesPinnedProperty = MetricsSystem.getMasterMetricName(FileSystemMaster.Metrics.FILES_PINNED);
operations.put(MetricsSystem.stripInstanceAndHost(filesPinnedProperty), mr.getGauges().get(filesPinnedProperty));
Map<String, Counter> rpcInvocationsUpdated = new TreeMap<>();
for (Map.Entry<String, Counter> entry : rpcInvocations.entrySet()) {
rpcInvocationsUpdated.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
populateCounterValues(operations, rpcInvocationsUpdated, request);
}
use of com.codahale.metrics.Counter in project alluxio by Alluxio.
the class WebInterfaceWorkerMetricsServlet method populateValues.
/**
* Populates key, value pairs for UI display.
*
* @param request The {@link HttpServletRequest} object
* @throws IOException if an I/O error occurs
*/
private void populateValues(HttpServletRequest request) throws IOException {
MetricRegistry mr = MetricsSystem.METRIC_REGISTRY;
Long workerCapacityTotal = (Long) mr.getGauges().get(MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.CAPACITY_TOTAL)).getValue();
Long workerCapacityUsed = (Long) mr.getGauges().get(MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.CAPACITY_USED)).getValue();
int workerCapacityUsedPercentage = (workerCapacityTotal > 0) ? (int) (100L * workerCapacityUsed / workerCapacityTotal) : 0;
request.setAttribute("workerCapacityUsedPercentage", workerCapacityUsedPercentage);
request.setAttribute("workerCapacityFreePercentage", 100 - workerCapacityUsedPercentage);
Map<String, Counter> counters = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return !(name.endsWith("Ops"));
}
});
Map<String, Counter> rpcInvocations = mr.getCounters(new MetricFilter() {
@Override
public boolean matches(String name, Metric metric) {
return name.endsWith("Ops");
}
});
Map<String, Metric> operations = new TreeMap<>();
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
operations.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
String blockCachedProperty = MetricsSystem.getWorkerMetricName(DefaultBlockWorker.Metrics.BLOCKS_CACHED);
operations.put(MetricsSystem.stripInstanceAndHost(blockCachedProperty), mr.getGauges().get(blockCachedProperty));
Map<String, Counter> rpcInvocationsUpdated = new TreeMap<>();
for (Map.Entry<String, Counter> entry : rpcInvocations.entrySet()) {
rpcInvocationsUpdated.put(MetricsSystem.stripInstanceAndHost(entry.getKey()), entry.getValue());
}
populateCounterValues(operations, rpcInvocationsUpdated, request);
}
use of com.codahale.metrics.Counter in project camel by apache.
the class MetricComponentSpringTest method testMetricsRegistryFromCamelRegistry.
@Test
public void testMetricsRegistryFromCamelRegistry() throws Exception {
// TODO - 12.05.2014, Lauri - is there any better way to set this up?
MetricRegistry mockRegistry = endpoint.getCamelContext().getRegistry().lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
Counter mockCounter = Mockito.mock(Counter.class);
InOrder inOrder = Mockito.inOrder(mockRegistry, mockCounter);
when(mockRegistry.counter("A")).thenReturn(mockCounter);
endpoint.expectedMessageCount(1);
producer.sendBody(new Object());
endpoint.assertIsSatisfied();
inOrder.verify(mockRegistry, times(1)).counter("A");
inOrder.verify(mockCounter, times(1)).inc(512L);
inOrder.verifyNoMoreInteractions();
}
Aggregations