本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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()));
}
}
示例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());
}
示例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));
}
示例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);
}
示例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));
};
}
示例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);
}
}
示例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);
}