當前位置: 首頁>>代碼示例>>Java>>正文


Java MetricFilter類代碼示例

本文整理匯總了Java中com.codahale.metrics.MetricFilter的典型用法代碼示例。如果您正苦於以下問題:Java MetricFilter類的具體用法?Java MetricFilter怎麽用?Java MetricFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MetricFilter類屬於com.codahale.metrics包,在下文中一共展示了MetricFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: report

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
@Override
public void report(MetricRegistry metricRegistry) {

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

    if (StringUtils.isBlank(config.getHost())) {
        throw new NullPointerException("graphite reporter host must not be null, please config jboot.metrics.reporter.graphite.host in you properties.");
    }
    if (config.getPort() == null) {
        throw new NullPointerException("graphite reporter port must not be null, please config jboot.metrics.reporter.graphite.port in you properties.");
    }
    if (config.getPrefixedWith() == null) {
        throw new NullPointerException("graphite reporter prefixedWith must not be null, please config jboot.metrics.reporter.graphite.prefixedWith in you properties.");
    }

    Graphite graphite = new Graphite(new InetSocketAddress(config.getHost(), config.getPort()));

    GraphiteReporter reporter = GraphiteReporter.forRegistry(metricRegistry)
            .prefixedWith(config.getPrefixedWith())
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);

    reporter.start(1, TimeUnit.MINUTES);
}
 
開發者ID:yangfuhai,項目名稱:jboot,代碼行數:27,代碼來源:JbootGraphiteReporter.java

示例2: init

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    final ServletContext context = config.getServletContext();
    if (null == registry) {
        final Object registryAttr = context.getAttribute(METRICS_REGISTRY);
        if (registryAttr instanceof MetricRegistry) {
            this.registry = (MetricRegistry) registryAttr;
        } else {
            throw new ServletException("Couldn't find a MetricRegistry instance.");
        }
    }

    filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
    if (filter == null) {
        filter = MetricFilter.ALL;
    }

    this.allowedOrigin = context.getInitParameter(ALLOWED_ORIGIN);
}
 
開發者ID:dhatim,項目名稱:dropwizard-prometheus,代碼行數:22,代碼來源:PrometheusServlet.java

示例3: setSessionManager

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:AmadeusITGroup,項目名稱:HttpSessionReplacer,代碼行數:27,代碼來源:RedisSessionRepository.java

示例4: ElasticsearchReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
private ElasticsearchReporter(MetricRegistry registry, MetricFilter filter, TimeUnit rateUnit,
		TimeUnit durationUnit, String host, String port, String indexName, String timestampField) {

	super(registry, "elasticsearch-reporter", filter, rateUnit, durationUnit);

	this.clock = Clock.defaultClock();
	this.connector = new ElasticsearchConnector(host, port, indexName);
	this.timestampField = timestampField;
	this.timestampFormat = new SimpleDateFormat(timeStampString);
	this.localhost = Utils.localHostName();

	jsonFactory = new JsonFactory();

	indexInitialized = connector.addDefaultMappings();
	if (!indexInitialized) {
		LOGGER.warn("Failed to initialize Elasticsearch index '" + indexName + "' on " + host + ":" + port);
	}
}
 
開發者ID:ibmruntimes,項目名稱:spelk,代碼行數:19,代碼來源:ElasticsearchReporter.java

示例5: createSlf4jReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
/**
 * Creates a {@link DropwizardMetricRegistry} with an {@link Slf4jReporter}.  Only non-zero metrics
 * will be logged to the {@link Slf4jReporter}.
 * 
 * @param registry The registry on which to add the reporter.
 * @param logger The {@link Logger} to report to
 * @param period the amount of time between polls
 * @param unit   the unit for {@code period}
 */
public static void createSlf4jReporter(DropwizardMetricRegistry registry, Logger logger,
    long period, TimeUnit unit) {
  MetricFilter nonZeroMatcher =
      new MetricFilter() {
        @Override
        public boolean matches(String name, Metric metric) {
          if (metric instanceof Counting) {
            Counting counter = (Counting) metric;
            return counter.getCount() > 0;
          }
          return true;
        }
      };
  Slf4jReporter.forRegistry(registry.getRegistry())
      .outputTo(logger)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .filter(nonZeroMatcher)
      .build()
      .start(period, unit);
}
 
開發者ID:benson-git,項目名稱:ibole-microservice,代碼行數:31,代碼來源:DropwizardMetricRegistry.java

示例6: HawkularReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
HawkularReporter(MetricRegistry registry,
                 HawkularHttpClient hawkularClient,
                 Optional<String> prefix,
                 MetricsDecomposer decomposer,
                 MetricsTagger tagger,
                 TimeUnit rateUnit,
                 TimeUnit durationUnit,
                 MetricFilter filter) {
    super(registry, "hawkular-reporter", filter, rateUnit, durationUnit);

    this.prefix = prefix;
    this.clock = Clock.defaultClock();
    this.hawkularClient = hawkularClient;
    this.decomposer = decomposer;
    this.tagger = tagger;
}
 
開發者ID:hawkular,項目名稱:hawkular-dropwizard-reporter,代碼行數:17,代碼來源:HawkularReporter.java

示例7: HadoopMetrics2Reporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
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);
}
 
開發者ID:joshelser,項目名稱:dropwizard-hadoop-metrics2,代碼行數:22,代碼來源:HadoopMetrics2Reporter.java

示例8: init

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
private static void init() {
  // Init JMX reporter
  reporter = JmxReporter.forRegistry(registry).build();
  reporter.start();
  // Init graphite reporter
  Graphite graphite = getGraphite();
  GraphiteReporter graphiteReporter;
  if (graphite == null) {
    graphiteReporter = null;
  } else {
    graphiteReporter =
        GraphiteReporter.forRegistry(registry).prefixedWith(PREFIX).convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
    graphiteReporter.start(AuditConfig.GRAPHITE_REPORT_PERIOD_SEC, TimeUnit.SECONDS);
  }
}
 
開發者ID:uber,項目名稱:chaperone,代碼行數:17,代碼來源:Metrics.java

示例9: CloudWatchReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
private CloudWatchReporter(MetricRegistry registry,
                           AmazonCloudWatchClient client,
                           String namespace,
                           TimeUnit rateUnit,
                           TimeUnit durationUnit,
                           boolean reportAggregates,
                           MetricFilter filter, Map<String, String> dimensions) {
    super(registry, "cloudwatch-reporter", filter, rateUnit, durationUnit);
    this.client = client;
    this.namespace = namespace;
    this.dimensions = new ArrayList<>();
    this.reportAggregates = reportAggregates;
    for (Map.Entry<String, String> me : dimensions.entrySet()) {
        this.dimensions.add(new Dimension().withName(me.getKey()).withValue(me.getValue()));
    }
}
 
開發者ID:basis-technology-corp,項目名稱:metrics-cloudwatch-reporter,代碼行數:17,代碼來源:CloudWatchReporter.java

示例10: KafkaReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
private KafkaReporter(MetricRegistry registry, String name,
		TimeUnit rateUnit, TimeUnit durationUnit, boolean showSamples, MetricFilter filter,
		String topic, ProducerConfig config, String prefix,
		String hostName, String ip) {
	super(registry, name, filter, rateUnit, durationUnit);
	this.topic = topic;
	this.config = config;
	this.prefix = prefix;
	this.hostName = hostName;
	this.ip = ip;
	
	this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit,
               durationUnit,
               showSamples));

	producer = new Producer<String, String>(config);

	kafkaExecutor = Executors
			.newSingleThreadExecutor(new ThreadFactoryBuilder()
					.setNameFormat("kafka-producer-%d").build());
}
 
開發者ID:hengyunabc,項目名稱:metrics-kafka,代碼行數:22,代碼來源:KafkaReporter.java

示例11: shouldSkipIdleMetrics

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
@Test
public void shouldSkipIdleMetrics() throws Exception {
    when(influxDb.hasSeriesData()).thenReturn(true);

    final Meter meter = mock(Meter.class);
    when(meter.getCount()).thenReturn(1L);
    when(meter.getOneMinuteRate()).thenReturn(2.0);
    when(meter.getFiveMinuteRate()).thenReturn(3.0);
    when(meter.getFifteenMinuteRate()).thenReturn(4.0);
    when(meter.getMeanRate()).thenReturn(5.0);

    InfluxDbReporter skippingReporter = InfluxDbReporter
        .forRegistry(registry)
        .convertRatesTo(TimeUnit.SECONDS)
        .convertDurationsTo(TimeUnit.MILLISECONDS)
        .filter(MetricFilter.ALL)
        .withTags(globalTags)
        .skipIdleMetrics(true)
        .build(influxDb);

    skippingReporter.report(this.<Gauge>map(), this.<Counter>map(), this.<Histogram>map(), this.map("meter", meter), this.<Timer>map());
    skippingReporter.report(this.<Gauge>map(), this.<Counter>map(), this.<Histogram>map(), this.map("meter", meter), this.<Timer>map());

    verify(influxDb, times(1)).appendPoints(Mockito.any(InfluxDbPoint.class));
}
 
開發者ID:iZettle,項目名稱:dropwizard-metrics-influxdb,代碼行數:26,代碼來源:InfluxDbReporterTest.java

示例12: attachGraphiteReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
/**
 * Attaches a {@link GraphiteReporter} to provided {@link MetricsHandler}
 * @param metricsHandler
 * @param id
 * @param period
 * @param host
 * @param port
 * @throws RequiredInputMissingException
 */
private static void attachGraphiteReporter(final MetricsHandler metricsHandler, final String id, final int period, final String host, final int port) throws RequiredInputMissingException {
	
	//////////////////////////////////////////////////////////////////////////
	// validate input
	if(StringUtils.isBlank(id))
		throw new RequiredInputMissingException("Missing required metric reporter id");
	if(metricsHandler == null)
		throw new RequiredInputMissingException("Missing required metrics handler");
	if(StringUtils.isBlank(host))
		throw new RequiredInputMissingException("Missing required graphite host");
	if(port < 0)
		throw new RequiredInputMissingException("Missing required graphite port");
	//////////////////////////////////////////////////////////////////////////
	
	final Graphite graphite = new Graphite(new InetSocketAddress(host, port));
	final GraphiteReporter reporter = GraphiteReporter.forRegistry(metricsHandler.getRegistry())
			.convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS)
			.filter(MetricFilter.ALL)
	        .build(graphite);
	reporter.start((period > 0 ? period : 1), TimeUnit.SECONDS);
	metricsHandler.addScheduledReporter(id, reporter);
}
 
開發者ID:ottogroup,項目名稱:SPQR,代碼行數:32,代碼來源:MetricsReporterFactory.java

示例13: getFilter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
/**
 * Gets a {@link MetricFilter} that specifically includes and excludes configured metrics. This method needs the
 * existing {@link MetricFilter} used to filter the disabled metrics. The includes and excludes will be checked
 * only for enabled metrics.
 *
 * @param enabledFilter The existing {@link MetricFilter} to filter disabled metrics.
 * @return the filter for selecting metrics based on the configured excludes/includes.
 * @throws ReporterBuildException if the pattern compilation failed for regular expressions.
 */
protected MetricFilter getFilter(MetricFilter enabledFilter) throws ReporterBuildException {
    if (includes.isEmpty() && excludes.isEmpty()) {
        return enabledFilter;
    }

    final StringMatchingStrategy stringMatchingStrategy;

    if (useRegexFilters) {
        stringMatchingStrategy = regexStringMatchingStrategy;
        compileAllRegex(getIncludes());
        compileAllRegex(getExcludes());
    } else {
        stringMatchingStrategy = defaultStringMatchingStrategy;
    }

    return (name, metric) -> {
        // Include the metric if its name is not excluded and its name is included
        // Where, by default, with no includes setting, all names are included.
        return enabledFilter.matches(name, metric) && !stringMatchingStrategy.containsMatch(getExcludes(), name) &&
                (getIncludes().isEmpty() || stringMatchingStrategy.containsMatch(getIncludes(), name));
    };
}
 
開發者ID:wso2,項目名稱:carbon-metrics,代碼行數:32,代碼來源:ReporterConfig.java

示例14: setupGraphiteReporter

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
private void setupGraphiteReporter(Configuration configuration) {
  boolean graphiteEnabled = configuration.getBoolean("graphite.enabled", false);

  if (graphiteEnabled) {
    String   host        = configuration.getString("graphite.host", "localhost");
    int      port        = configuration.getInt("graphite.port", 80);
    String   prefix      = configuration.getString("graphite.prefix", "");
    long     period      = configuration.getLong("graphite.period", 1l);
    TimeUnit periodUnit  = TimeUnit.valueOf(configuration.getString("graphite.periodUnit", "MINUTES"));

    final Graphite graphite = new Graphite(new InetSocketAddress(host, port));
    GraphiteReporter.Builder reportBuilder = GraphiteReporter.forRegistry(metricRegistry)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .filter(MetricFilter.ALL);

    if (prefix != null && !prefix.isEmpty()) {
      reportBuilder.prefixedWith(prefix);
    }

    graphiteReporter = reportBuilder.build(graphite);

    graphiteReporter.start(period, periodUnit);
  }
}
 
開發者ID:shelajev,項目名稱:cgif,代碼行數:26,代碼來源:Global.java

示例15: run

import com.codahale.metrics.MetricFilter; //導入依賴的package包/類
@Override
public void run(ExampleConfiguration configuration, Environment environment) throws Exception {

    if(configuration.metricsEnabled()) {


        final Graphite graphite = new Graphite(new InetSocketAddress("graphite.example.com", 2003));

        final GraphiteReporter reporter = GraphiteReporter.forRegistry(environment.metrics())
                .prefixedWith("prefix")
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .filter(MetricFilter.ALL)
                .build(graphite);
        reporter.start(5, TimeUnit.SECONDS);

        final ConsoleReporter consoleReporter = ConsoleReporter.forRegistry(environment.metrics()).build();
        consoleReporter.start(5, TimeUnit.SECONDS);
    }

    final ExampleResource exampleResource = new ExampleResource(environment.metrics());
    environment.jersey().register(exampleResource);
}
 
開發者ID:pims,項目名稱:dropwizard-metrics-example,代碼行數:24,代碼來源:ExampleApplication.java


注:本文中的com.codahale.metrics.MetricFilter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。