com.yammer.metrics.core.MetricPredicate Java Examples
The following examples show how to use
com.yammer.metrics.core.MetricPredicate.
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: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 6 votes |
/** * get Metrics by class and predicate * * @param klass * @param filter * @return */ @SuppressWarnings("unchecked") private <T extends Metric> SortedMap<MetricName, T> getMetrics(Class<T> klass, MetricPredicate filter) { Map<MetricName, Metric> allMetrics = registry.allMetrics(); final TreeMap<MetricName, T> timers = new TreeMap<MetricName, T>(); for (Map.Entry<MetricName, Metric> entry : allMetrics.entrySet()) { if (klass.isInstance(entry.getValue()) && filter.matches(entry.getKey(), entry.getValue())) { timers.put(entry.getKey(), (T) entry.getValue()); } } return Collections.unmodifiableSortedMap(timers); }
Example #2
Source File: StatsdMetricsReporter.java From kafka-statsd-metrics2 with Apache License 2.0 | 6 votes |
private void loadConfig(VerifiableProperties props) { enabled = props.getBoolean("external.kafka.statsd.reporter.enabled", false); host = props.getString("external.kafka.statsd.host", "localhost"); port = props.getInt("external.kafka.statsd.port", 8125); prefix = props.getString("external.kafka.statsd.metrics.prefix", ""); pollingPeriodInSeconds = props.getInt("kafka.metrics.polling.interval.secs", 10); metricDimensions = Dimension.fromProperties(props.props(), "external.kafka.statsd.dimension.enabled."); String excludeRegex = props.getString("external.kafka.statsd.metrics.exclude_regex", DEFAULT_EXCLUDE_REGEX); if (excludeRegex != null && excludeRegex.length() != 0) { metricPredicate = new ExcludeMetricPredicate(excludeRegex); } else { metricPredicate = MetricPredicate.ALL; } this.isTagEnabled = props.getBoolean("external.kafka.statsd.tag.enabled", true); }
Example #3
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 6 votes |
@Test public void keepGaugesIfTheyThrowRuntimeExceptions() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricName = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gauge = Metrics.newGauge(metricName, new Gauge<Long>() { @Override public Long value() { throw new RuntimeException("catch me if you can"); } }); assertTrue(predicate.matches(metricName, gauge)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricName)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricName), gauge); }
Example #4
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Enables the console reporter for the given metrics registry, and causes * it to print to STDOUT with the specified period and unrestricted output. */ public static void enable(final MetricsRegistry metricsRegistry, final long period, final TimeUnit unit) { final CustomReporter reporter = new CustomReporter( metricsRegistry, System.out, MetricPredicate.ALL); reporter.start(period, unit); }
Example #5
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
public SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata, boolean useLocalTime, boolean sendExtraMetricDimensions, Map<String, String> defaultDimensions) { super(registry, name, filter, rateUnit, durationUnit); this.aggregateMetricSender = aggregateMetricSender; this.useLocalTime = useLocalTime; this.detailsToAdd = detailsToAdd; this.metricMetadata = metricMetadata; this.sendExtraMetricDimensions = sendExtraMetricDimensions; this.defaultDimensions = ImmutableMap.copyOf(defaultDimensions); }
Example #6
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 5 votes |
protected SignalFxReporter(MetricsRegistry registry, String name, MetricPredicate filter, TimeUnit rateUnit, TimeUnit durationUnit, AggregateMetricSender aggregateMetricSender, Set<MetricDetails> detailsToAdd, MetricMetadata metricMetadata) { this(registry, name, filter, rateUnit, durationUnit, aggregateMetricSender, detailsToAdd, metricMetadata, false, false, Collections.<String, String> emptyMap()); }
Example #7
Source File: ReporterSetup.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private static void setupGangliaReporter(BlurConfiguration configuration) { long period = configuration.getLong(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "period", 5l); TimeUnit unit = TimeUnit.valueOf(configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "unit", "SECONDS").toUpperCase()); String host = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "host", "localhost"); int port = configuration.getInt(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "port", -1); String prefix = configuration.get(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "prefix", ""); boolean compressPackageNames = configuration.getBoolean(BLUR_SHARD_METRICS_REPORTER_PREFIX + "ganglia." + "compressPackageNames", false); GangliaReporter.enable(Metrics.defaultRegistry(), period, unit, host, port, prefix, MetricPredicate.ALL, compressPackageNames); }
Example #8
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void matches() { MetricPredicate predicate = new FilterMetricPredicate("group.type.scope.foobar.*"); assertFalse(predicate.matches(buildMetricName("foobar.count"), metricMock)); assertFalse(predicate.matches(buildMetricName("foobar.rate"), metricMock)); assertFalse(predicate.matches(buildMetricName("foobarbar"), metricMock)); assertTrue(predicate.matches(buildMetricName("foo"), metricMock)); assertTrue(predicate.matches(buildMetricName("bar"), metricMock)); assertTrue(predicate.matches(buildMetricName("foo.bar"), metricMock)); }
Example #9
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void deleteGaugesIfTheyThrowNoSuchElementException() throws Exception { MetricPredicate predicate = new FilterMetricPredicate(); MetricName metricNameToBeDeleted = new MetricName("test", "test", "delete", "scope", "mBeanName"); Metric gaugeToBeDeleted = Metrics.newGauge(metricNameToBeDeleted, new Gauge<Long>() { @Override public Long value() { throw new NoSuchElementException("catch me if you can - i'm the the same as in KAFKA-1866"); } }); MetricName metricNameToStay = new MetricName("stay", "stay", "stay", "scope", "stay:mBeanName"); Metric gaugeToStay = Metrics.newGauge(metricNameToStay, new Gauge<Long>() { @Override public Long value() { return 42L; } }); assertFalse(predicate.matches(metricNameToBeDeleted, gaugeToBeDeleted)); assertTrue(predicate.matches(metricNameToStay, gaugeToStay)); assertFalse("The gauge should be deleted", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToBeDeleted)); assertTrue("The gauge should be there", Metrics.defaultRegistry().allMetrics().containsKey(metricNameToStay)); assertEquals(Metrics.defaultRegistry().allMetrics().get(metricNameToStay), gaugeToStay); }
Example #10
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void alwaysExcludeAppVersion_WithRegEx() { MetricPredicate predicate = new FilterMetricPredicate("group.type.foobar.*"); assertFalse(predicate.matches(new MetricName("kafka.common", "AppInfo", "Version", null, "mBeanName"), metricMock)); assertTrue(predicate.matches(new MetricName("kafka.common", "AppInfo", "SomethingElse", null, "mBeanName"), metricMock)); }
Example #11
Source File: FilterMetricPredicateTest.java From kafka-graphite with Apache License 2.0 | 5 votes |
@Test public void alwaysExcludeAppVersion_NoRegEx() { MetricPredicate predicate = new FilterMetricPredicate(); assertFalse(predicate.matches(new MetricName("kafka.common", "AppInfo", "Version", null, "mBeanName"), metricMock)); assertTrue(predicate.matches(new MetricName("kafka.common", "AppInfo", "SomethingElse", null, "mBeanName"), metricMock)); }
Example #12
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone) { this(metricsRegistry, out, predicate, clock, timeZone, Locale .getDefault()); }
Example #13
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone, final Locale locale) { super(metricsRegistry, "console-reporter"); this.out = out; this.predicate = predicate; this.clock = clock; this.timeZone = timeZone; this.locale = locale; }
Example #14
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone) { this(metricsRegistry, out, predicate, clock, timeZone, Locale .getDefault()); }
Example #15
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * Enables the console reporter for the given metrics registry, and causes * it to print to STDOUT with the specified period and unrestricted output. */ public static void enable(final MetricsRegistry metricsRegistry, final long period, final TimeUnit unit) { final CustomReporter reporter = new CustomReporter( metricsRegistry, System.out, MetricPredicate.ALL); reporter.start(period, unit); }
Example #16
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate, final Clock clock, final TimeZone timeZone, final Locale locale) { super(metricsRegistry, "console-reporter"); this.out = out; this.predicate = predicate; this.clock = clock; this.timeZone = timeZone; this.locale = locale; }
Example #17
Source File: SignalFxReporter.java From signalfx-java with Apache License 2.0 | 4 votes |
public Builder setFilter(MetricPredicate filter) { this.filter = filter; return this; }
Example #18
Source File: StatsdReporter.java From kafka-statsd-reporter with MIT License | 4 votes |
/** * Creates a new {@link StatsdReporter}. * * @param metricsRegistry * the metrics registry * @param prefix * is prepended to all names reported to statsd * @param predicate * filters metrics to be reported * @param host * is the host of statsd server * @param port * is the port of statsd server * @param clock * a {@link Clock} instance * @param vm * a {@link VirtualMachineMetrics} instance * @throws IOException * if there is an error connecting to the statsd server */ public StatsdReporter(MetricsRegistry metricsRegistry, String prefix, MetricPredicate predicate, String host, int port, Clock clock, VirtualMachineMetrics vm, String name) throws IOException { super(metricsRegistry, name); this.host = host; this.port = port; this.vm = vm; this.clock = clock; if (prefix != null) { // Pre-append the "." so that we don't need to make anything // conditional later. this.prefix = prefix + "."; } else { this.prefix = ""; } this.predicate = predicate; }
Example #19
Source File: CustomReporter.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate) { this(metricsRegistry, out, predicate, Clock.defaultClock(), TimeZone .getDefault()); }
Example #20
Source File: CustomReporter.java From netty4.0.27Learn with Apache License 2.0 | 4 votes |
/** * Creates a new {@link CustomReporter} for a given metrics registry. */ public CustomReporter(final MetricsRegistry metricsRegistry, final PrintStream out, final MetricPredicate predicate) { this(metricsRegistry, out, predicate, Clock.defaultClock(), TimeZone .getDefault()); }
Example #21
Source File: SignalFxReporterTest.java From signalfx-java with Apache License 2.0 | 4 votes |
private void testReporterWithDetails(){ StoredDataPointReceiver dbank = new StoredDataPointReceiver(); assertEquals(0, dbank.addDataPoints.size()); Set<SignalFxReporter.MetricDetails> detailsToAdd = new HashSet<SignalFxReporter.MetricDetails>(); detailsToAdd.add(SignalFxReporter.MetricDetails.STD_DEV); detailsToAdd.add(SignalFxReporter.MetricDetails.MEAN); MetricsRegistry metricRegistery = new MetricsRegistry(); SignalFxReporter reporter = new SignalFxReporter.Builder(metricRegistery, new StaticAuthToken(""), "myserver") .setDataPointReceiverFactory(new StaticDataPointReceiverFactory(dbank)) .setDetailsToAdd( ImmutableSet.of( SignalFxReporter.MetricDetails.COUNT, SignalFxReporter.MetricDetails.MIN, SignalFxReporter.MetricDetails.MAX ) ) .setName("testReporter") .setDefaultSourceName("defaultSource") .useLocalTime(false) .setOnSendErrorHandlerCollection( Collections.<OnSendErrorHandler>singleton(new OnSendErrorHandler(){ public void handleError(MetricError error){ System.out.println("" + error.getMessage()); } }) ) .setFilter(MetricPredicate.ALL) .setRateUnit(TimeUnit.SECONDS) .setDetailsToAdd(detailsToAdd) .build(); final MetricMetadata metricMetadata = reporter.getMetricMetadata(); MetricName histogramName = new MetricName("group1", "type1", "histogram"); Histogram histogram = metricRegistery.newHistogram(histogramName, true); histogram.update(10); histogram.update(14); histogram.update(7); metricMetadata.forMetric(histogram) .withMetricName("histogram") .withSourceName("histogram_source") .withMetricType(SignalFxProtocolBuffers.MetricType.GAUGE) .withDimension("key", "value"); reporter.report(); assertEquals(2, dbank.addDataPoints.size()); }
Example #22
Source File: StatsdReporter.java From kafka-statsd-reporter with MIT License | 3 votes |
/** * Enables the statsd reporter to send data to statsd server with the * specified period. * * @param metricsRegistry * the metrics registry * @param period * the period between successive outputs * @param unit * the time unit of {@code period} * @param host * the host name of statsd server * @param port * the port number on which the statsd server is listening * @param prefix * the string which is prepended to all metric names * @param predicate * filters metrics to be reported */ public static void enable(MetricsRegistry metricsRegistry, long period, TimeUnit unit, String host, int port, String prefix, MetricPredicate predicate) { try { final StatsdReporter reporter = new StatsdReporter(metricsRegistry, prefix, predicate, host, port, Clock.defaultClock()); reporter.start(period, unit); } catch (Exception e) { LOG.error("Error creating/starting statsd reporter:", e); } }
Example #23
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 3 votes |
/** * Creates a new {@link CustomScheduledReporter} instance. * * @param registry the MetricsRegistry containing the metrics this * reporter will report * @param name the reporter's name * @param filter the filter for which metrics to report * @param rateUnit * @param durationUnit */ protected CustomScheduledReporter(MetricsRegistry registry, String name, MetricPredicate filter, TimeUnit rateUnit, TimeUnit durationUnit) { this.registry = registry; this.filter = filter; this.executor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(name)); }
Example #24
Source File: BcryptCommandTest.java From usergrid with Apache License 2.0 | 2 votes |
/** * Tests bcrypt hashing with a default number of rounds. Note that via the console output, this test should take * about 5 seconds to run since we want to force 500 ms per authentication attempt with bcrypt */ @Test public void testHashRoundSpeed() throws UnsupportedEncodingException { int cryptIterations = 2 ^ 11; int numberOfTests = 10; BcryptCommand command = new BcryptCommand(); command.setDefaultIterations( cryptIterations ); String baseString = "I am a test password for hashing"; CredentialsInfo info = new CredentialsInfo(); UUID user = UUID.randomUUID(); UUID applicationId = UUID.randomUUID(); byte[] result = command.hash( baseString.getBytes( "UTF-8" ), info, user, applicationId ); String stringResults = encodeBase64URLSafeString( result ); info.setSecret( stringResults ); Timer timer = Metrics.newTimer( BcryptCommandTest.class, "hashtimer" ); for ( int i = 0; i < numberOfTests; i++ ) { TimerContext timerCtx = timer.time(); //now check we can auth with the same phrase byte[] authed = command.auth( baseString.getBytes( "UTF-8" ), info, user, applicationId ); timerCtx.stop(); assertArrayEquals( result, authed ); } /** * Print out the data */ ConsoleReporter reporter = new ConsoleReporter( Metrics.defaultRegistry(), System.out, MetricPredicate.ALL ); reporter.run(); }
Example #25
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Timers metrics * @param filter * @return */ private SortedMap<MetricName, Timer> getTimers(MetricPredicate filter) { return getMetrics(Timer.class, filter); }
Example #26
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Gauge metrics * @param filter * @return */ private SortedMap<MetricName, Gauge> getGauges(MetricPredicate filter) { return getMetrics(Gauge.class, filter); }
Example #27
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Counter metrics * @param filter * @return */ private SortedMap<MetricName, Counter> getCounters(MetricPredicate filter) { return getMetrics(Counter.class, filter); }
Example #28
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Histogram metrics * @param filter * @return */ private SortedMap<MetricName, Histogram> getHistograms(MetricPredicate filter) { return getMetrics(Histogram.class, filter); }
Example #29
Source File: CustomScheduledReporter.java From signalfx-java with Apache License 2.0 | 2 votes |
/** * get all Meters metrics * @param filter * @return */ private SortedMap<MetricName, Meter> getMeters(MetricPredicate filter) { return getMetrics(Meter.class, filter); }
Example #30
Source File: FilteredGraphiteReporter.java From kafka-graphite with Apache License 2.0 | 2 votes |
/** * Creates a new {@link GraphiteReporter}. * * @param metricsRegistry the metrics registry * @param prefix is prepended to all names reported to graphite * @param predicate filters metrics to be reported * @param dimensions enum of enabled dimensions to include * @param socketProvider a {@link SocketProvider} instance * @param clock a {@link Clock} instance * @throws IOException if there is an error connecting to the Graphite server */ public FilteredGraphiteReporter(MetricsRegistry metricsRegistry, String prefix, MetricPredicate predicate, EnumSet<Dimension> dimensions, SocketProvider socketProvider, Clock clock) throws IOException { super(metricsRegistry, prefix, predicate, socketProvider, clock); this.dimensions = dimensions; LOGGER.debug("The following Metrics Dimensions will be sent {}", dimensions); }