@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); }
@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); }
/** * 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); }
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); } }
/** * 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); }
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; }
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); }
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); } }
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())); } }
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()); }
@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)); }
/** * 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); }
/** * 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)); }; }
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); } }
@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); }
/** * Build the JMX Reporter * * @param metricRegistry The {@link MetricRegistry} for the reporter * @param metricFilter The {@link MetricFilter} for the reporter * @return an {@link Optional} with {@link JmxReporter}, if the reporter is built successfully, otherwise an empty * {@code Optional} * @throws ReporterBuildException when there was a failure in constructing the reporter */ @Override public Optional<JmxReporter> build(MetricRegistry metricRegistry, MetricFilter metricFilter) throws ReporterBuildException { if (!isEnabled()) { return Optional.empty(); } if (domain == null || domain.trim().isEmpty()) { throw new ReporterBuildException("Domain is not specified for JMX Reporting."); } if (logger.isInfoEnabled()) { logger.info(String.format("Creating JMX reporter for Metrics with domain '%s'", domain)); } return Optional.of(new JmxReporter(getName(), metricRegistry, getFilter(metricFilter), domain)); }
@BeforeMethod private void setUp() throws Exception { when(clock.getTime()).thenReturn(19910191000L); this.reporter = JdbcReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.NANOSECONDS).withClock(clock).filter(MetricFilter.ALL) .build(SOURCE, dataSource); transactionTemplate.execute(status -> { template.execute("DELETE FROM METRIC_GAUGE;"); template.execute("DELETE FROM METRIC_TIMER;"); template.execute("DELETE FROM METRIC_METER;"); template.execute("DELETE FROM METRIC_HISTOGRAM;"); template.execute("DELETE FROM METRIC_COUNTER;"); return null; }); }
/** * Build the SLF4J Reporter * * @param metricRegistry The {@link MetricRegistry} for the reporter * @param metricFilter The {@link MetricFilter} for the reporter * @return an {@link Optional} with {@link Slf4jReporter}, if the reporter is built successfully, otherwise an empty * {@code Optional} * @throws ReporterBuildException when there was a failure in constructing the reporter */ @Override public Optional<Slf4jReporter> build(MetricRegistry metricRegistry, MetricFilter metricFilter) throws ReporterBuildException { if (!isEnabled()) { return Optional.empty(); } if (loggerName == null || loggerName.trim().isEmpty()) { throw new ReporterBuildException("Logger Name is not specified for SLF4J Reporting."); } if (logger.isInfoEnabled()) { logger.info(String.format( "Creating SLF4J reporter for Metrics with logger name '%s' and %d seconds polling period", loggerName, getPollingPeriod())); } return Optional.of(new Slf4jReporter(getName(), metricRegistry, getFilter(metricFilter), loggerName, markerName, getPollingPeriod())); }
public MetricFilter getFilter() { final StringMatchingStrategy stringMatchingStrategy = getUseRegexFilters() ? REGEX_STRING_MATCHING_STRATEGY : DEFAULT_STRING_MATCHING_STRATEGY; 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 !stringMatchingStrategy.containsMatch(getExcludes(), name) && (getIncludes().isEmpty() || stringMatchingStrategy.containsMatch(getIncludes(), name)); }; }
protected ApptuitReporter(MetricRegistry registry, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, Map<String, String> globalTags, String key, URL apiUrl, ReportingMode reportingMode) { super(registry, REPORTER_NAME, filter, rateUnit, durationUnit); this.buildReportTimer = registry.timer("apptuit.reporter.report.build"); this.sendReportTimer = registry.timer("apptuit.reporter.report.send"); if (reportingMode == null) { reportingMode = DEFAULT_REPORTING_MODE; } switch (reportingMode) { case NO_OP: this.dataPointsReporter = dataPoints -> { }; break; case SYS_OUT: this.dataPointsReporter = dataPoints -> { dataPoints.forEach(dp -> dp.toTextLine(System.out, globalTags)); }; break; case API_PUT: default: ApptuitPutClient putClient = new ApptuitPutClient(key, globalTags, apiUrl); this.dataPointsReporter = putClient::put; break; } }
public InfluxDbMeasurementReporter(final Sender sender, final MetricRegistry registry, final MetricFilter filter, final TimeUnit rateUnit, final TimeUnit durationUnit, final Clock clock, final DropwizardTransformer transformer, final ScheduledExecutorService executor) { super(registry, "influxdb-measurement-reporter", filter, rateUnit, durationUnit, executor); this.clock = clock; this.sender = sender; this.transformer = transformer; }
public InfluxDbMeasurementReporter(final Sender sender, final MetricRegistry registry, final MetricFilter filter, final TimeUnit rateUnit, final TimeUnit durationUnit, final Clock clock, final DropwizardTransformer transformer) { super(registry, "influxdb-measurement-reporter", filter, rateUnit, durationUnit); this.clock = clock; this.sender = sender; this.transformer = transformer; }
private Builder(MetricRegistry registry) { this.registry = registry; this.clock = Clock.defaultClock(); this.prefix = null; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; }
public ElasticsearchReporter(MetricRegistry registry, String[] hosts, int timeout, String index, String indexDateFormat, int bulkSize, Clock clock, String prefix, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, MetricFilter percolationFilter, Notifier percolationNotifier, String timestampFieldname,Map<String,String> context) throws MalformedURLException { super(registry, "elasticsearch-reporter", filter, rateUnit, durationUnit); this.hosts = hosts; this.index = index; this.bulkSize = bulkSize; this.clock = clock; this.prefix = prefix; this.timeout = timeout; if (indexDateFormat != null && indexDateFormat.length() > 0) { this.indexDateFormat = new SimpleDateFormat(indexDateFormat); } if (percolationNotifier != null && percolationFilter != null) { this.percolationFilter = percolationFilter; this.notifier = percolationNotifier; } if (timestampFieldname == null || timestampFieldname.trim().length() == 0) { LOGGER.error("Timestampfieldname {} is not valid, using default @timestamp", timestampFieldname); timestampFieldname = "@timestamp"; } objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); objectMapper.configure(SerializationFeature.CLOSE_CLOSEABLE, false); // auto closing means, that the objectmapper is closing after the first write call, which does not work for bulk requests objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); objectMapper.registerModule(new MetricsElasticsearchModule(rateUnit, durationUnit, timestampFieldname)); writer = objectMapper.writer(); checkForIndexTemplate(); }
public static void resetMetrics(){ RegistryHolder.REGISTRY.removeMatching(new MetricFilter(){ @Override public boolean matches(String name, Metric metric) { return true; }}); RegistryHolder.registerSysStats(); }
private synchronized void removeOldMetrics() { registry.removeMatching(new MetricFilter() { @Override public boolean matches(String name, Metric metric) { return name.startsWith("drill.allocator."); } }); }
/** */ private IgniteNodeOverloadReporter(MetricRegistry registry, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, long latencyThreshold, double quantile, Ignite ignite ) { super(registry, "ignite-overload-reporter", filter, rateUnit, durationUnit); this.latencyThreshold = latencyThreshold; this.quantile = quantile; this.ignite = ignite; }
/** */ private Builder(MetricRegistry registry) { this.registry = registry; this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.filter = MetricFilter.ALL; }
private Builder(MetricRegistry registry) { this.registry = registry; this.locale = Locale.getDefault(); this.rateUnit = TimeUnit.SECONDS; this.durationUnit = TimeUnit.MILLISECONDS; this.clock = Clock.defaultClock(); this.filter = MetricFilter.ALL; }
/** */ private HumanReadableCsvReporter(MetricRegistry registry, File directory, Locale locale, TimeUnit rateUnit, TimeUnit durationUnit, Clock clock, MetricFilter filter) { super(registry, "human-readable-csv-reporter", filter, rateUnit, durationUnit); this.directory = directory; this.locale = locale; this.clock = clock; }
public GraphiteReporter(String host, int port, String fluxCapacitorUrl) { super(fluxCapacitorUrl); this.metrics = new MetricRegistry(); this.reporter = com.codahale.metrics.graphite.GraphiteReporter.forRegistry(metrics) .prefixedWith("fluxCapacitorClient") .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(new Graphite(new InetSocketAddress(host, port))); }
private Builder(MetricRegistry registry) { this.registry = registry; this.prefix = null; this.filter = MetricFilter.ALL; this.executor = null; this.shutdownExecutorOnStop = true; }
/** * Gets stats information of a metric. Returns array of all information for the * specified metric. * * @param metricName metric name * @return 200 OK with metric information as array * @onos.rsModel Metric */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("{metricName}") public Response getMetricByName(@PathParam("metricName") String metricName) { ObjectNode metricNode = root.putObject("metric"); MetricFilter filter = metricName != null ? (name, metric) -> name.equals(metricName) : MetricFilter.ALL; TreeMultimap<String, Metric> matched = listMetrics(service, filter); matched.asMap().get(metricName).forEach(m -> { metricNode.set(metricName, codec(Metric.class).encode(m, this)); }); return ok(root).build(); }
@Override protected void execute() { MetricsService metricsService = get(MetricsService.class); MetricFilter filter = metricName != null ? (name, metric) -> name.equals(metricName) : MetricFilter.ALL; TreeMultimap<String, Metric> matched = listMetrics(metricsService, filter); matched.asMap().forEach((name, metrics) -> { if (outputJson()) { metrics.forEach(metric -> print("%s", json(metric))); } else { metrics.forEach(metric -> printMetric(name, metric)); } }); }
private GraphiteReporter.Builder graphiteReporterBuilder() { return GraphiteReporter .forRegistry(metricRegistry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .prefixedWith(graphiteConfiguration.getPrefix()); }
@Test public void shouldBeAbleToCreateAGraphiteReporter() throws Exception { final Graphite graphite = new Graphite(new InetSocketAddress("graphite.example.com", 2003)); final MetricRegistry registry = new MetricRegistry(); final GraphiteReporter reporter = GraphiteReporter .forRegistry(registry) .prefixedWith("web1.example.com") .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .build(graphite); reporter.start(1, TimeUnit.MINUTES); }
@Override public void start() throws Exception { if (!graphiteConfiguration.isEnabled()) { LOG.info("Not reporting data points to graphite."); return; } final String prefix = buildGraphitePrefix(); LOG.info("Reporting data points to graphite server {}:{} every {} seconds with prefix '{}' and predicates '{}'.", graphiteConfiguration.getHostname(), graphiteConfiguration.getPort(), graphiteConfiguration.getPeriodSeconds(), prefix, 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(prefix)) { reporterBuilder.prefixedWith(prefix); } 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); }
@Test public void testSetMetrics() { RedisFacade facade = mock(RedisFacade.class); SessionManager sm = mock(SessionManager.class); MetricRegistry metrics = spy(new MetricRegistry()); when(sm.getMetrics()).thenReturn(metrics); metrics.meter("com.amadeus.session.myapp.redis.sample"); try (RedisSessionRepository rsr = new RedisSessionRepository(facade, "myapp", "localhost", ExpirationStrategy.NOTIF, false)) { rsr.setSessionManager(sm); verify(metrics).removeMatching(any(MetricFilter.class)); verify(metrics, never()).meter("com.amadeus.session.myapp.redis.failover"); } }
ReportingApp() { this.metricRegistry = new MetricRegistry(); this.theTimer = metricRegistry.timer("TheTimer"); final AmazonCloudWatchAsync amazonCloudWatchAsync = AmazonCloudWatchAsyncClientBuilder .standard() .withRegion(Regions.US_WEST_2) .build(); final CloudWatchReporter cloudWatchReporter = CloudWatchReporter.forRegistry(metricRegistry, amazonCloudWatchAsync, Main.class.getName()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .withPercentiles(Percentile.P75, Percentile.P99) .withOneMinuteMeanRate() .withFiveMinuteMeanRate() .withFifteenMinuteMeanRate() .withMeanRate() .withArithmeticMean() .withStdDev() .withStatisticSet() .withJvmMetrics() .withGlobalDimensions("Region=us-west-2", "Instance=stage") .withDryRun() .build(); cloudWatchReporter.start(10, TimeUnit.SECONDS); }