com.codahale.metrics.MetricFilter Java Examples

The following examples show how to use com.codahale.metrics.MetricFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WithMetricsSupport.java    From beam with Apache License 2.0 7 votes vote down vote up
private Map<String, Gauge> extractGauges(
    final MetricRegistry metricRegistry, final MetricFilter filter) {
  Map<String, Gauge> gauges = new HashMap<>();

  // find the AggregatorMetric metrics from within all currently registered metrics
  final Optional<Map<String, Gauge>> aggregatorMetrics =
      FluentIterable.from(metricRegistry.getMetrics().entrySet())
          .firstMatch(isAggregatorMetric())
          .transform(aggregatorMetricToGauges());

  // find the SparkBeamMetric metrics from within all currently registered metrics
  final Optional<Map<String, Gauge>> beamMetrics =
      FluentIterable.from(metricRegistry.getMetrics().entrySet())
          .firstMatch(isSparkBeamMetric())
          .transform(beamMetricToGauges());

  if (aggregatorMetrics.isPresent()) {
    gauges.putAll(Maps.filterEntries(aggregatorMetrics.get(), matches(filter)));
  }

  if (beamMetrics.isPresent()) {
    gauges.putAll(Maps.filterEntries(beamMetrics.get(), matches(filter)));
  }

  return gauges;
}
 
Example #2
Source File: RedisSessionRepository.java    From HttpSessionReplacer with MIT License 6 votes vote down vote up
/**
 * This method starts a separate thread that listens to key expirations events.
 *
 * @param sessionManager
 */
@Override
public void setSessionManager(final SessionManager sessionManager) {
  this.sessionManager = sessionManager;
  MetricRegistry metrics = sessionManager.getMetrics();
  if (metrics != null) {
    // Cleanup old metrics related to this namespace
    metrics.removeMatching(new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        return name.startsWith(name(RedisConfiguration.METRIC_PREFIX, "redis"));
      }
    });
    if (sticky) {
      failoverMetrics = metrics.meter(name(RedisConfiguration.METRIC_PREFIX, namespace, "redis", "failover"));
    }

    redis.startMonitoring(metrics);
  }
  expirationManager.startExpiredSessionsTask(sessionManager);
}
 
Example #3
Source File: GraphiteReporterTest.java    From styx with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    Clock clock = mock(Clock.class);
    graphite = mock(Graphite.class);

    MetricRegistry registry = mock(MetricRegistry.class);

    when(clock.getTime()).thenReturn(TIMESTAMP * 1000);
    reporter = forRegistry(registry)
            .withClock(clock)
            .prefixedWith("prefix")
            .convertRatesTo(SECONDS)
            .convertDurationsTo(MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);

    logging = new LoggingTestSupport(GraphiteReporter.class);
}
 
Example #4
Source File: InfluxdbReporter.java    From jboot with Apache License 2.0 6 votes vote down vote up
@Override
    public void report(MetricRegistry metricRegistry) {

        JbootMetricInfluxdbReporterConfig config = Jboot.config(JbootMetricInfluxdbReporterConfig.class);


        final ScheduledReporter reporter = metrics_influxdb.InfluxdbReporter.forRegistry(metricRegistry)
                .protocol(new HttpInfluxdbProtocol("http"
                        , config.getHost()
                        , config.getPort()
                        , config.getUser()
                        , config.getPassword()
                        , config.getDbName()))
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .filter(MetricFilter.ALL)
                .skipIdleMetrics(false)
//                .tag("cluster", config.getTagCluster())
//                .tag("client", config.getTagClient())
//                .tag("server", serverIP)
//                .transformer(new CategoriesMetricMeasurementTransformer("module", "artifact"))
                .build();

        reporter.start(10, TimeUnit.SECONDS);
    }
 
Example #5
Source File: JVMMetricsServlet.java    From hermes with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {
	final ServletContext context = config.getServletContext();
	if (null == registry) {
		final Object registryAttr = context.getAttribute(JVM_METRICS_REGISTRY);
		if (registryAttr instanceof MetricRegistry) {
			this.registry = (MetricRegistry) registryAttr;
		} else {
			throw new ServletException("Couldn't find a JVMMetricRegistry instance.");
		}
	}

	final TimeUnit rateUnit = parseTimeUnit(context.getInitParameter(RATE_UNIT), TimeUnit.SECONDS);
	final TimeUnit durationUnit = parseTimeUnit(context.getInitParameter(DURATION_UNIT), TimeUnit.SECONDS);
	final boolean showSamples = Boolean.parseBoolean(context.getInitParameter(SHOW_SAMPLES));
	MetricFilter filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
	if (filter == null) {
		filter = MetricFilter.ALL;
	}
	this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter));

	this.allowedOrigin = context.getInitParameter(ALLOWED_ORIGIN);
	this.jsonpParamName = context.getInitParameter(CALLBACK_PARAM);
}
 
Example #6
Source File: HadoopMetrics2Reporter.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
private HadoopMetrics2Reporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit,
        MetricFilter filter, MetricsSystem metrics2System, String jmxContext, String description, String recordName,
        String context) {
    super(registry, "hadoop-metrics2-reporter", filter, rateUnit, durationUnit);
    this.metrics2Registry = new MetricsRegistry(Interns.info(jmxContext, description));
    this.metrics2System = metrics2System;
    this.recordName = recordName;
    this.context = context;

    // These could really be Collection.emptyMap(), but this makes testing a bit easier.
    this.dropwizardGauges = EMPTY_GAUGE_MAP;
    this.dropwizardCounters = EMPTY_COUNTER_MAP;
    this.dropwizardHistograms = EMPTY_HISTOGRAM_MAP;
    this.dropwizardMeters = EMPTY_METER_MAP;
    this.dropwizardTimers = EMPTY_TIMER_MAP;

    // Register this source with the Metrics2 system.
    // Make sure this is the last thing done as getMetrics() can be called at any time after.
    this.metrics2System.register(Objects.requireNonNull(jmxContext), Objects.requireNonNull(description), this);
}
 
Example #7
Source File: BasicJvmMetrisTest.java    From signalfx-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testPointsSent() throws Exception {
    MetricRegistry registry = new MetricRegistry();
    new BasicJvmMetrics(registry);

    ScheduledReporter reporter = new ScheduledReporter(registry, "test", MetricFilter.ALL,
            TimeUnit.SECONDS, TimeUnit.MILLISECONDS) {

        @Override
        public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters,
                           SortedMap<String, Histogram> histograms,
                           SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
            Assert.assertFalse(gauges.isEmpty());
            Assert.assertNotNull(gauges.get("jvm.uptime"));
            for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
                Assert.assertNotNull(entry.getValue().getValue());
            }
        }
    };

    reporter.report();
    reporter.close();
}
 
Example #8
Source File: SpectatorReporter.java    From spectator with Apache License 2.0 6 votes vote down vote up
/** Create a new instance. */
SpectatorReporter(
    MetricRegistry metricRegistry,
    Registry spectatorRegistry,
    NameFunction nameFunction,
    ValueFunction valueFunction,
    Pattern gaugeCounters) {
  super(metricRegistry,
      "spectator",       // name
      MetricFilter.ALL,  // filter
      TimeUnit.SECONDS,  // rateUnit
      TimeUnit.SECONDS); // durationUnit
  this.spectatorRegistry = spectatorRegistry;
  this.nameFunction = nameFunction;
  this.valueFunction = valueFunction;
  this.gaugeCounters = gaugeCounters;
}
 
Example #9
Source File: JBossLoggingReporter.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.logger = Logger.getLogger(JBossLoggingReporter.class);
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.filter = MetricFilter.ALL;
    this.loggingLevel = LoggingLevel.INFO;
}
 
Example #10
Source File: DefaultGraphiteReporterFactory.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized Reporter getReporter(MetricRegistry registry) {
    if (null == reporter) {
        Graphite graphite = new Graphite(new InetSocketAddress(graphiteURL, graphitePort));
        reporter = GraphiteReporter.forRegistry(registry)
                                   .prefixedWith(prefix)
                                   .convertRatesTo(TimeUnit.SECONDS)
                                   .convertDurationsTo(TimeUnit.MILLISECONDS)
                                   .filter(MetricFilter.ALL)
                                   .build(graphite);
    }
    return reporter;
}
 
Example #11
Source File: BaragonAgentGraphiteReporterManaged.java    From Baragon with Apache License 2.0 5 votes vote down vote up
@Override
public void start() throws Exception {
  if (!graphiteConfiguration.isEnabled()) {
    LOG.info("Not reporting data points to graphite.");
    return;
  }

  LOG.info("Reporting data points to graphite server {}:{} every {} seconds with prefix '{}' and predicates '{}'.", graphiteConfiguration.getHostname(),
      graphiteConfiguration.getPort(), graphiteConfiguration.getPeriodSeconds(), graphiteConfiguration.getPrefix(), JavaUtils.COMMA_JOINER.join(graphiteConfiguration.getPredicates()));

  final Graphite graphite = new Graphite(new InetSocketAddress(graphiteConfiguration.getHostname(), graphiteConfiguration.getPort()));

  final GraphiteReporter.Builder reporterBuilder = GraphiteReporter.forRegistry(registry);

  if (!Strings.isNullOrEmpty(graphiteConfiguration.getPrefix())) {
    reporterBuilder.prefixedWith(graphiteConfiguration.getPrefix());
  }

  if (!graphiteConfiguration.getPredicates().isEmpty()) {
    reporterBuilder.filter(new MetricFilter() {
      @Override
      public boolean matches(String name, Metric metric) {
        for (String predicate : graphiteConfiguration.getPredicates()) {
          if (name.startsWith(predicate)) {
            return true;
          }
        }
        return false;
      }
    });
  }

  reporter = Optional.of(reporterBuilder.build(graphite));
  reporter.get().start(graphiteConfiguration.getPeriodSeconds(), TimeUnit.SECONDS);
}
 
Example #12
Source File: WavefrontMetricsReporter.java    From dropwizard-wavefront with Apache License 2.0 5 votes vote down vote up
public WavefrontMetricsReporter(MetricRegistry registry, String token, String hostname,
                                MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit)
    throws UnknownHostException
{
  super(registry, "json-reporter", filter, rateUnit, durationUnit);
  this.token    = token;
  this.hostname = hostname;
  this.host     = InetAddress.getLocalHost().getHostName();
}
 
Example #13
Source File: JBossLoggingReporter.java    From hawkular-agent with Apache License 2.0 5 votes vote down vote up
private JBossLoggingReporter(MetricRegistry registry,
        LoggerProxy loggerProxy,
        TimeUnit rateUnit,
        TimeUnit durationUnit,
        MetricFilter filter) {
    super(registry, "hawkular-monitor", filter, rateUnit, durationUnit);
    this.loggerProxy = loggerProxy;
}
 
Example #14
Source File: PrometheusReporter.java    From dropwizard-prometheus with Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.prefix = null;
    this.filter = MetricFilter.ALL;
    this.executor = null;
    this.shutdownExecutorOnStop = true;
}
 
Example #15
Source File: MetricsSetup.java    From quarks with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the metric {@code JMXReporter}. If no MBeanServer was set, use 
 * the virtual machine's platform MBeanServer.
 */
public MetricsSetup startJMXReporter(String jmxDomainName) {
    final JmxReporter reporter = JmxReporter.forRegistry(registry()).
            registerWith(mbeanServer())
            .inDomain(jmxDomainName).createsObjectNamesWith(new MetricObjectNameFactory())
            .convertDurationsTo(durationsUnit).convertRatesTo(ratesUnit)
            .filter(MetricFilter.ALL).build();
    reporter.start();
    return this;
}
 
Example #16
Source File: GraphiteMetricsReporter.java    From knox with Apache License 2.0 5 votes vote down vote up
@Override
public void start(MetricsContext metricsContext) throws MetricsReporterException {
  MetricRegistry registry = (MetricRegistry) metricsContext.getProperty(
      DefaultMetricsService.METRICS_REGISTRY);
  reporter = GraphiteReporter.forRegistry(registry)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .filter(MetricFilter.ALL)
      .build(graphite);
  reporter.start(reportingFrequency, TimeUnit.MINUTES);
}
 
Example #17
Source File: HadoopCounterReporterTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {

  String contextName = CONTEXT_NAME + "_" + UUID.randomUUID().toString();

  Reporter mockedReporter = Mockito.mock(Reporter.class);

  this.recordsProcessedCount = Mockito.mock(Counters.Counter.class);
  Mockito.when(mockedReporter.getCounter(
      contextName, MetricRegistry.name(RECORDS_PROCESSED, Measurements.COUNT.getName())))
      .thenReturn(this.recordsProcessedCount);

  this.recordProcessRateCount = Mockito.mock(Counters.Counter.class);
  Mockito.when(mockedReporter.getCounter(
      contextName, MetricRegistry.name(RECORD_PROCESS_RATE, Measurements.COUNT.getName())))
      .thenReturn(this.recordProcessRateCount);

  this.recordSizeDistributionCount = Mockito.mock(Counters.Counter.class);
  Mockito.when(mockedReporter.getCounter(
      contextName, MetricRegistry.name(RECORD_SIZE_DISTRIBUTION, Measurements.COUNT.getName())))
      .thenReturn(this.recordSizeDistributionCount);

  this.totalDurationCount = Mockito.mock(Counters.Counter.class);
  Mockito.when(mockedReporter.getCounter(
      contextName, MetricRegistry.name(TOTAL_DURATION, Measurements.COUNT.getName())))
      .thenReturn(this.totalDurationCount);

  this.queueSize = Mockito.mock(Counters.Counter.class);
  Mockito.when(mockedReporter.getCounter(contextName, QUEUE_SIZE)).thenReturn(this.queueSize);

  this.hadoopCounterReporter = HadoopCounterReporter.builder(mockedReporter)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.SECONDS)
      .filter(MetricFilter.ALL)
      .build(MetricContext.builder(contextName).buildStrict());
}
 
Example #18
Source File: PatternMetricFilterTest.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompletelyEmpty() throws Exception {
  String str = "{}";
  Config config = ConfigFactory.parseString(str);
  MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
  assertSame(filter, MetricFilter.ALL);
  assertTrue(filter.matches("foo", new Counter()));
}
 
Example #19
Source File: TestDatadogReporter.java    From hudi with Apache License 2.0 5 votes vote down vote up
@Test
public void prefixShouldPrepend() {
  DatadogReporter reporter = new DatadogReporter(
      registry, client, "foo", Option.empty(), Option.empty(),
      MetricFilter.ALL, TimeUnit.SECONDS, TimeUnit.SECONDS);
  assertEquals("foo.bar", reporter.prefix("bar"));
}
 
Example #20
Source File: ZabbixReporter.java    From metrics-zabbix with Apache License 2.0 5 votes vote down vote up
public Builder(MetricRegistry registry) {
	this.registry = registry;

	this.rateUnit = TimeUnit.SECONDS;
	this.durationUnit = TimeUnit.MILLISECONDS;
	this.filter = MetricFilter.ALL;

}
 
Example #21
Source File: StackDriverConfigurator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void configureAndStart(String name, MetricRegistry registry, MetricFilter filter) {
  this.producer = new DropWizardMetrics(Collections.singletonList(registry), filter);

  Metrics.getExportComponent().getMetricProducerManager().add(producer);

  try {
    StackdriverStatsExporter.createAndRegister();
  } catch (IOException e) {
    logger.warn("Could not setup stackdriver stats", e);
  }
}
 
Example #22
Source File: SendToLocalInfluxDB.java    From dropwizard-metrics-influxdb with Apache License 2.0 5 votes vote down vote up
private static InfluxDbReporter startInfluxDbReporter(MetricRegistry registry, InfluxDbSender influxDbSender)
    throws Exception {
    final Map<String, String> tags = new HashMap<String, String>();
    tags.put("host", "localhost");
    final InfluxDbReporter reporter = InfluxDbReporter
        .forRegistry(registry)
        .withTags(tags)
        .skipIdleMetrics(true)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .filter(MetricFilter.ALL)
        .build(influxDbSender);
    reporter.start(10, TimeUnit.SECONDS);
    return reporter;
}
 
Example #23
Source File: PatternMetricFilterTest.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmpty() throws Exception {
  String str = "{ metricFilter : {} }";
  Config config = ConfigFactory.parseString(str);
  MetricFilter filter = PatternMetricFilter.parse(new Configs(), config);
  assertNotSame(filter, MetricFilter.ALL);
  assertTrue(filter.matches("foo", new Counter()));
  assertTrue(filter.toString().length() > 0);
}
 
Example #24
Source File: ScheduledReporter.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
private MetricFilter createMetricFilter(Config config) {
  if (config.hasPath(METRIC_FILTER_NAME_REGEX) && config.hasPath(METRIC_FILTER_TYPE_LIST)) {
    return MetricFilters.and(new MetricNameRegexFilter(config.getString(METRIC_FILTER_NAME_REGEX)),
        new MetricTypeFilter(config.getString(METRIC_FILTER_TYPE_LIST)));
  }
  if (config.hasPath(METRIC_FILTER_NAME_REGEX)) {
    return new MetricNameRegexFilter(config.getString(METRIC_FILTER_NAME_REGEX));
  }
  if (config.hasPath(METRIC_FILTER_TYPE_LIST)) {
    return new MetricTypeFilter(config.getString(METRIC_FILTER_TYPE_LIST));
  }
  return MetricFilter.ALL;
}
 
Example #25
Source File: EmbeddedGobblin.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * This returns the set of jars required by a basic Gobblin ingestion job. In general, these need to be distributed
 * to workers in a distributed environment.
 */
private void loadCoreGobblinJarsToDistributedJars() {
  // Gobblin-api
  distributeJarByClassWithPriority(State.class, 0);
  // Gobblin-core
  distributeJarByClassWithPriority(ConstructState.class, 0);
  // Gobblin-core-base
  distributeJarByClassWithPriority(InstrumentedExtractorBase.class, 0);
  // Gobblin-metrics-base
  distributeJarByClassWithPriority(MetricContext.class, 0);
  // Gobblin-metrics
  distributeJarByClassWithPriority(GobblinMetrics.class, 0);
  // Gobblin-metastore
  distributeJarByClassWithPriority(FsStateStore.class, 0);
  // Gobblin-runtime
  distributeJarByClassWithPriority(Task.class, 0);
  // Gobblin-utility
  distributeJarByClassWithPriority(PathUtils.class, 0);
  // joda-time
  distributeJarByClassWithPriority(ReadableInstant.class, 0);
  // guava
  distributeJarByClassWithPriority(Escaper.class, -10); // Escaper was added in guava 15, so we use it to identify correct jar
  // dropwizard.metrics-core
  distributeJarByClassWithPriority(MetricFilter.class, 0);
  // pegasus
  distributeJarByClassWithPriority(DataTemplate.class, 0);
  // commons-lang3
  distributeJarByClassWithPriority(ClassUtils.class, 0);
  // avro
  distributeJarByClassWithPriority(SchemaBuilder.class, 0);
  // guava-retry
  distributeJarByClassWithPriority(RetryListener.class, 0);
  // config
  distributeJarByClassWithPriority(ConfigFactory.class, 0);
  // reflections
  distributeJarByClassWithPriority(Reflections.class, 0);
  // javassist
  distributeJarByClassWithPriority(ClassFile.class, 0);
}
 
Example #26
Source File: NewAPIHadoopCounterReporterTest.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
@BeforeClass
@SuppressWarnings("unchecked")
public void setUp() {
  TaskInputOutputContext<Object, Object, Object, Object> mockContext = Mockito.mock(TaskInputOutputContext.class);

  this.recordsProcessedCount = Mockito.mock(Counter.class);
  Mockito.when(mockContext.getCounter(
      this.name, MetricRegistry.name(RECORDS_PROCESSED, Measurements.COUNT.getName())))
      .thenReturn(this.recordsProcessedCount);

  this.recordProcessRateCount = Mockito.mock(Counter.class);
  Mockito.when(mockContext.getCounter(
      this.name, MetricRegistry.name(RECORD_PROCESS_RATE, Measurements.COUNT.getName())))
      .thenReturn(this.recordProcessRateCount);

  this.recordSizeDistributionCount = Mockito.mock(Counter.class);
  Mockito.when(mockContext.getCounter(
      this.name, MetricRegistry.name(RECORD_SIZE_DISTRIBUTION, Measurements.COUNT.getName())))
      .thenReturn(this.recordSizeDistributionCount);

  this.totalDurationCount = Mockito.mock(Counter.class);
  Mockito.when(mockContext.getCounter(
      this.name, MetricRegistry.name(TOTAL_DURATION, Measurements.COUNT.getName())))
      .thenReturn(this.totalDurationCount);

  this.queueSize = Mockito.mock(Counter.class);
  Mockito.when(mockContext.getCounter(this.name, QUEUE_SIZE)).thenReturn(this.queueSize);

  this.hadoopCounterReporter = NewAPIHadoopCounterReporter.builder(mockContext)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.SECONDS)
      .filter(MetricFilter.ALL)
      .build(MetricContext.builder(this.name).build());
}
 
Example #27
Source File: CodahaleMetricsProvider.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private ScheduledReporter createAndGetConfiguredGraphiteReporter(String prefix, String graphiteHost) {
    LOG.info("Configuring Graphite reporter. Sendig data to host:port {}", graphiteHost);
    HostAndPort addr = HostAndPort.fromString(graphiteHost);

    final Graphite graphite = new Graphite(
            new InetSocketAddress(addr.getHostText(), addr.getPort()));

    return GraphiteReporter.forRegistry(metrics)
            .prefixedWith(prefix)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);
}
 
Example #28
Source File: JmxMetricsReporter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private JmxListener(MBeanServer mBeanServer, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit,
                    ObjectNameFactory objectNameFactory, String tag) {
  this.mBeanServer = mBeanServer;
  this.name = name;
  this.filter = filter;
  this.rateUnit = rateUnit;
  this.durationUnit = durationUnit;
  this.registered = new ConcurrentHashMap<>();
  this.objectNameFactory = objectNameFactory;
  this.tag = tag;
  this.exp = Query.eq(Query.attr(INSTANCE_TAG), Query.value(tag));
}
 
Example #29
Source File: Replicator.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
void destroy() {
    final ThreadId savedId = this.id;
    LOG.info("Replicator {} is going to quit", savedId);
    releaseReader();
    // Unregister replicator metric set
    if (this.nodeMetrics.isEnabled()) {
        this.nodeMetrics.getMetricRegistry() //
            .removeMatching(MetricFilter.startsWith(getReplicatorMetricName(this.options)));
    }
    this.state = State.Destroyed;
    notifyReplicatorStatusListener((Replicator) savedId.getData(), ReplicatorEvent.DESTROYED);
    savedId.unlockAndDestroy();
    this.id = null;
}
 
Example #30
Source File: HttpErrorStatusMetricsTest.java    From styx with Apache License 2.0 5 votes vote down vote up
private Collection<Integer> statusCountsExcluding(String excluded) {
    MetricFilter filter = (name, metric) ->
            (name.startsWith("styx.response.status.") || name.startsWith("origins.response.status.")) && !name.equals(excluded);

    return registry.getCounters(filter).values().stream()
            .map(Counter::getCount)
            .map(Long::intValue)
            .collect(toList());
}