Search in sources :

Example 1 with MetricFilter

use of com.codahale.metrics.MetricFilter in project opennms by OpenNMS.

the class DispatcherState method close.

@Override
public void close() throws Exception {
    final String prefix = MetricRegistry.name(module.getId());
    metrics.removeMatching(new MetricFilter() {

        @Override
        public boolean matches(String name, Metric metric) {
            return name.startsWith(prefix);
        }
    });
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) Metric(com.codahale.metrics.Metric)

Example 2 with MetricFilter

use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.

the class SolrGangliaReporter method start.

//this is a separate method for unit tests
void start() {
    if (!testing) {
        String id = host + ":" + port + ":" + multicast;
        ganglia = serviceRegistry.getOrCreate(id, () -> new GMetric(host, port, multicast ? GMetric.UDPAddressingMode.MULTICAST : GMetric.UDPAddressingMode.UNICAST, 1));
        if (ganglia == null) {
            return;
        }
    }
    if (instancePrefix == null) {
        instancePrefix = registryName;
    } else {
        instancePrefix = instancePrefix + "." + registryName;
    }
    GangliaReporter.Builder builder = GangliaReporter.forRegistry(metricManager.registry(registryName)).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).prefixedWith(instancePrefix);
    MetricFilter filter;
    if (!filters.isEmpty()) {
        filter = new SolrMetricManager.PrefixFilter(filters);
    } else {
        filter = MetricFilter.ALL;
    }
    builder = builder.filter(filter);
    reporter = builder.build(ganglia);
    reporter.start(period, TimeUnit.SECONDS);
}
Also used : GMetric(info.ganglia.gmetric4j.gmetric.GMetric) MetricFilter(com.codahale.metrics.MetricFilter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) GangliaReporter(com.codahale.metrics.ganglia.GangliaReporter)

Example 3 with MetricFilter

use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.

the class SolrJmxReporter method init.

/**
   * Initializes the reporter by finding an MBeanServer
   * and registering the metricManager's metric registry.
   *
   * @param pluginInfo the configuration for the reporter
   */
@Override
public synchronized void init(PluginInfo pluginInfo) {
    super.init(pluginInfo);
    if (!enabled) {
        log.info("Reporter disabled for registry " + registryName);
        return;
    }
    log.debug("Initializing for registry " + registryName);
    if (serviceUrl != null && agentId != null) {
        mBeanServer = JmxUtil.findFirstMBeanServer();
        log.warn("No more than one of serviceUrl({}) and agentId({}) should be configured, using first MBeanServer instead of configuration.", serviceUrl, agentId, mBeanServer);
    } else if (serviceUrl != null) {
        // reuse existing services
        mBeanServer = serviceRegistry.getOrCreate(serviceUrl, () -> JmxUtil.findMBeanServerForServiceUrl(serviceUrl));
    } else if (agentId != null) {
        mBeanServer = JmxUtil.findMBeanServerForAgentId(agentId);
    } else {
        mBeanServer = JmxUtil.findFirstMBeanServer();
        log.debug("No serviceUrl or agentId was configured, using first MBeanServer: " + mBeanServer);
    }
    if (mBeanServer == null) {
        log.warn("No JMX server found. Not exposing Solr metrics via JMX.");
        return;
    }
    if (domain == null || domain.isEmpty()) {
        domain = registryName;
    }
    String fullDomain = domain;
    if (rootName != null && !rootName.isEmpty()) {
        fullDomain = rootName + "." + domain;
    }
    JmxObjectNameFactory jmxObjectNameFactory = new JmxObjectNameFactory(pluginInfo.name, fullDomain);
    registry = metricManager.registry(registryName);
    // filter out MetricsMap gauges - we have a better way of handling them
    MetricFilter mmFilter = (name, metric) -> !(metric instanceof MetricsMap);
    MetricFilter filter;
    if (filters.isEmpty()) {
        filter = mmFilter;
    } else {
        // apply also prefix filters
        SolrMetricManager.PrefixFilter prefixFilter = new SolrMetricManager.PrefixFilter(filters);
        filter = new SolrMetricManager.AndFilter(prefixFilter, mmFilter);
    }
    reporter = JmxReporter.forRegistry(registry).registerWith(mBeanServer).inDomain(fullDomain).filter(filter).createsObjectNamesWith(jmxObjectNameFactory).build();
    reporter.start();
    // workaround for inability to register custom MBeans (to be available in metrics 4.0?)
    listener = new MetricsMapListener(mBeanServer, jmxObjectNameFactory);
    registry.addListener(listener);
    log.info("JMX monitoring for '" + fullDomain + "' (registry '" + registryName + "') enabled at server: " + mBeanServer);
}
Also used : ObjectInstance(javax.management.ObjectInstance) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) JmxUtil(org.apache.solr.util.JmxUtil) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MetricRegistryListener(com.codahale.metrics.MetricRegistryListener) ObjectName(javax.management.ObjectName) MetricsMap(org.apache.solr.metrics.MetricsMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Locale(java.util.Locale) MBeanServer(javax.management.MBeanServer) MetricFilter(com.codahale.metrics.MetricFilter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) PluginInfo(org.apache.solr.core.PluginInfo) Gauge(com.codahale.metrics.Gauge) InstanceNotFoundException(javax.management.InstanceNotFoundException) JmxReporter(com.codahale.metrics.JmxReporter) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) MetricFilter(com.codahale.metrics.MetricFilter) MetricsMap(org.apache.solr.metrics.MetricsMap) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 4 with MetricFilter

use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.

the class MetricsHandler method parseMustMatchFilter.

private MetricFilter parseMustMatchFilter(SolrQueryRequest req) {
    String[] prefixes = req.getParams().getParams(PREFIX_PARAM);
    MetricFilter prefixFilter = null;
    if (prefixes != null && prefixes.length > 0) {
        Set<String> prefixSet = new HashSet<>();
        for (String prefix : prefixes) {
            prefixSet.addAll(StrUtils.splitSmart(prefix, ','));
        }
        prefixFilter = new SolrMetricManager.PrefixFilter(prefixSet);
    }
    String[] regexes = req.getParams().getParams(REGEX_PARAM);
    MetricFilter regexFilter = null;
    if (regexes != null && regexes.length > 0) {
        regexFilter = new SolrMetricManager.RegexFilter(regexes);
    }
    MetricFilter mustMatchFilter;
    if (prefixFilter == null && regexFilter == null) {
        mustMatchFilter = MetricFilter.ALL;
    } else {
        if (prefixFilter == null) {
            mustMatchFilter = regexFilter;
        } else if (regexFilter == null) {
            mustMatchFilter = prefixFilter;
        } else {
            mustMatchFilter = new SolrMetricManager.OrFilter(prefixFilter, regexFilter);
        }
    }
    return mustMatchFilter;
}
Also used : MetricFilter(com.codahale.metrics.MetricFilter) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) HashSet(java.util.HashSet)

Example 5 with MetricFilter

use of com.codahale.metrics.MetricFilter in project lucene-solr by apache.

the class MetricsHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    if (container == null) {
        throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Core container instance not initialized");
    }
    boolean compact = req.getParams().getBool(COMPACT_PARAM, true);
    MetricFilter mustMatchFilter = parseMustMatchFilter(req);
    MetricUtils.PropertyFilter propertyFilter = parsePropertyFilter(req);
    List<MetricType> metricTypes = parseMetricTypes(req);
    List<MetricFilter> metricFilters = metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
    Set<String> requestedRegistries = parseRegistries(req);
    NamedList response = new SimpleOrderedMap();
    for (String registryName : requestedRegistries) {
        MetricRegistry registry = metricManager.registry(registryName);
        SimpleOrderedMap result = new SimpleOrderedMap();
        MetricUtils.toMaps(registry, metricFilters, mustMatchFilter, propertyFilter, false, false, compact, false, (k, v) -> result.add(k, v));
        if (result.size() > 0) {
            response.add(registryName, result);
        }
    }
    rsp.getValues().add("metrics", response);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricUtils(org.apache.solr.util.stats.MetricUtils) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) MetricFilter(com.codahale.metrics.MetricFilter) SolrException(org.apache.solr.common.SolrException)

Aggregations

MetricFilter (com.codahale.metrics.MetricFilter)27 Metric (com.codahale.metrics.Metric)16 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 HashSet (java.util.HashSet)3 List (java.util.List)3 TimeUnit (java.util.concurrent.TimeUnit)3 Meter (com.codahale.metrics.Meter)2 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)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