use of com.codahale.metrics.MetricFilter in project ratpack by ratpack.
the class MetricsWebsocketBroadcastHandler method handle.
@Override
public void handle(final Context context) throws Exception {
final MetricsBroadcaster broadcaster = context.get(MetricsBroadcaster.class);
final ByteBufAllocator byteBufAllocator = context.get(ByteBufAllocator.class);
final DropwizardMetricsConfig config = context.get(DropwizardMetricsConfig.class);
MetricFilter filter = MetricFilter.ALL;
if (config.getWebSocket().isPresent()) {
filter = new RegexMetricFilter(config.getWebSocket().get().getIncludeFilter(), config.getWebSocket().get().getExcludeFilter());
}
websocketByteBufBroadcast(context, broadcaster.map(new MetricRegistryJsonMapper(byteBufAllocator, filter)));
}
use of com.codahale.metrics.MetricFilter 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.MetricFilter 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.MetricFilter in project lucene-solr by apache.
the class SolrGraphiteReporter method validate.
@Override
protected void validate() throws IllegalStateException {
if (!enabled) {
log.info("Reporter disabled for registry " + registryName);
return;
}
if (host == null) {
throw new IllegalStateException("Init argument 'host' must be set to a valid Graphite server name.");
}
if (port == -1) {
throw new IllegalStateException("Init argument 'port' must be set to a valid Graphite server port.");
}
if (reporter != null) {
throw new IllegalStateException("Already started once?");
}
if (period < 1) {
throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
}
GraphiteSender graphite;
String id = host + ":" + port + ":" + pickled;
graphite = serviceRegistry.getOrCreate(id, () -> {
if (pickled) {
return new PickledGraphite(host, port);
} else {
return new Graphite(host, port);
}
});
if (instancePrefix == null) {
instancePrefix = registryName;
} else {
instancePrefix = instancePrefix + "." + registryName;
}
GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metricManager.registry(registryName)).prefixedWith(instancePrefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS);
MetricFilter filter;
if (!filters.isEmpty()) {
filter = new SolrMetricManager.PrefixFilter(filters);
} else {
filter = MetricFilter.ALL;
}
builder = builder.filter(filter);
reporter = builder.build(graphite);
reporter.start(period, TimeUnit.SECONDS);
}
use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.
the class SolrSlf4jReporter method validate.
@Override
protected void validate() throws IllegalStateException {
if (!enabled) {
log.info("Reporter disabled for registry " + registryName);
return;
}
if (period < 1) {
throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
}
if (instancePrefix == null) {
instancePrefix = registryName;
} else {
instancePrefix = instancePrefix + "." + registryName;
}
Slf4jReporter.Builder builder = Slf4jReporter.forRegistry(metricManager.registry(registryName)).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS);
MetricFilter filter;
if (!filters.isEmpty()) {
filter = new SolrMetricManager.PrefixFilter(filters);
} else {
filter = MetricFilter.ALL;
}
builder = builder.filter(filter);
if (logger == null || logger.isEmpty()) {
// construct logger name from Group
if (pluginInfo.attributes.containsKey("group")) {
logger = SolrMetricManager.overridableRegistryName(pluginInfo.attributes.get("group"));
} else if (pluginInfo.attributes.containsKey("registry")) {
String reg = SolrMetricManager.overridableRegistryName(pluginInfo.attributes.get("registry"));
String[] names = reg.split("\\.");
if (names.length < 2) {
logger = reg;
} else {
logger = names[0] + "." + names[1];
}
}
}
builder = builder.outputTo(LoggerFactory.getLogger(logger));
reporter = builder.build();
reporter.start(period, TimeUnit.SECONDS);
}
Aggregations