Search in sources :

Example 16 with MetricFilter

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)));
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) MetricsBroadcaster(ratpack.dropwizard.metrics.internal.MetricsBroadcaster) MetricFilter(com.codahale.metrics.MetricFilter) RegexMetricFilter(ratpack.dropwizard.metrics.internal.RegexMetricFilter) MetricRegistryJsonMapper(ratpack.dropwizard.metrics.internal.MetricRegistryJsonMapper) RegexMetricFilter(ratpack.dropwizard.metrics.internal.RegexMetricFilter)

Example 17 with MetricFilter

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);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) TreeMap(java.util.TreeMap) MetricFilter(com.codahale.metrics.MetricFilter) Counter(com.codahale.metrics.Counter) Metric(com.codahale.metrics.Metric) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 18 with MetricFilter

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);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) TreeMap(java.util.TreeMap) MetricFilter(com.codahale.metrics.MetricFilter) Counter(com.codahale.metrics.Counter) Metric(com.codahale.metrics.Metric) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 19 with MetricFilter

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);
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) MetricFilter(com.codahale.metrics.MetricFilter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) Graphite(com.codahale.metrics.graphite.Graphite) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 20 with MetricFilter

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);
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Slf4jReporter(com.codahale.metrics.Slf4jReporter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Aggregations

MetricFilter (com.codahale.metrics.MetricFilter)28 Metric (com.codahale.metrics.Metric)17 MetricRegistry (com.codahale.metrics.MetricRegistry)12 Counter (com.codahale.metrics.Counter)5 Map (java.util.Map)5 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)5 Gauge (com.codahale.metrics.Gauge)4 Histogram (com.codahale.metrics.Histogram)4 Timer (com.codahale.metrics.Timer)4 Test (org.junit.Test)4 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)3 HashSet (java.util.HashSet)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Meter (com.codahale.metrics.Meter)2 MetricsModule (com.codahale.metrics.json.MetricsModule)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 MethodHandles (java.lang.invoke.MethodHandles)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2