java类com.codahale.metrics.ScheduledReporter的实例源码

InfluxDbMeasurementReporterFactory.java 文件源码 项目:dropwizard-influxdb-reporter 阅读 22 收藏 0 点赞 0 评论 0
@Override
public ScheduledReporter build(final MetricRegistry registry) {
  final Sender builtSender = new Sender(sender.build(registry));
  final DropwizardTransformer transformer = new DropwizardTransformer(
    globalTags,
    DropwizardMeasurementParser.withTemplates(metricTemplates),
    groupCounters,
    groupGauges,
    getRateUnit(),
    getDurationUnit()
  );

  return new InfluxDbMeasurementReporter(
    builtSender,
    registry,
    getFilter(),
    getRateUnit(),
    getDurationUnit(),
    Clock.systemUTC(),
    transformer
  );
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 22 收藏 0 点赞 0 评论 0
private ScheduledReporter createAndGetConfiguredCSVReporter(String prefix, String csvDir) throws IOException {
    // NOTE:
    // 1) metrics output files are exclusive to a given process
    // 2) the output directory must exist
    // 3) if output files already exist they are not overwritten and there is no metrics output
    File outputDir;
    if (Strings.isNullOrEmpty(prefix)) {
        outputDir = new File(csvDir, prefix);
    } else {
        outputDir = new File(csvDir);
    }
    FileUtils.forceMkdir(outputDir);
    LOG.info("Configuring stats with csv output to directory [{}]", outputDir.getAbsolutePath());
    return CsvReporter.forRegistry(metrics)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build(outputDir);
}
DatadogMetricFilterTest.java 文件源码 项目:emodb 阅读 29 收藏 0 点赞 0 评论 0
private ScheduledReporter createReporter(String json)
        throws Exception {
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    ReporterFactory reporterFactory = objectMapper.readValue(json, ReporterFactory.class);

    assertTrue(reporterFactory instanceof DatadogExpansionFilteredReporterFactory);
    DatadogExpansionFilteredReporterFactory datadogReporterFactory = (DatadogExpansionFilteredReporterFactory) reporterFactory;

    // Replace the transport with our own mock for testing

    Transport transport = mock(Transport.class);
    when(transport.prepare()).thenReturn(_request);

    AbstractTransportFactory transportFactory = mock(AbstractTransportFactory.class);
    when(transportFactory.build()).thenReturn(transport);

    datadogReporterFactory.setTransport(transportFactory);

    // Build the reporter
    return datadogReporterFactory.build(_metricRegistry);
}
GobblinMetrics.java 文件源码 项目:Gobblin 阅读 23 收藏 0 点赞 0 评论 0
/**
 * Start metric reporting.
 *
 * @param properties configuration properties
 */
public void startMetricReporting(Properties properties) {
  if (this.reportingStarted) {
    LOGGER.warn("Metric reporting has already started");
    return;
  }

  long reportInterval = Long.parseLong(properties.getProperty(ConfigurationKeys.METRICS_REPORT_INTERVAL_KEY,
      ConfigurationKeys.DEFAULT_METRICS_REPORT_INTERVAL));

  buildJmxMetricReporter(properties);
  if (this.jmxReporter.isPresent()) {
    this.jmxReporter.get().start();
  }

  buildFileMetricReporter(properties);
  buildKafkaMetricReporter(properties);
  buildCustomMetricReporters(properties);

  for (ScheduledReporter reporter : this.scheduledReporters) {
    reporter.start(reportInterval, TimeUnit.MILLISECONDS);
  }

  this.reportingStarted = true;
}
ParfaitReporterFactory.java 文件源码 项目:parfait 阅读 25 收藏 0 点赞 0 评论 0
@Override
public ScheduledReporter build(MetricRegistry metricRegistry) {
    MetricAdapterFactory metricAdapterFactory = new MetricAdapterFactoryImpl(
            new DefaultMetricDescriptorLookup(),
            new DefaultMetricNameTranslator(getReplacements()));

    MonitorableRegistry monitorableRegistry = MonitorableRegistry.getNamedInstance(getRegistryName());

    PcpMmvWriter pcpMmvWriter = new PcpMmvWriter(getPcpName(), IdentifierSourceSet.DEFAULT_SET);
    pcpMmvWriter.setClusterIdentifier(getClusterIdentifier());

    MonitoringView monitoringView = new PcpMonitorBridge(pcpMmvWriter);

    DynamicMonitoringView dynamicMonitoringView = new DynamicMonitoringView(monitorableRegistry, monitoringView, quietPeriod);

    return new ParfaitReporter(metricRegistry,
            monitorableRegistry,
            dynamicMonitoringView,
            metricAdapterFactory,
            getRateUnit(),
            getDurationUnit(),
            getFilter(),
            getPrefix());
}
ReporterUtils.java 文件源码 项目:baleen 阅读 44 收藏 0 点赞 0 评论 0
/**
 * Create a new ElasticSearch reporter.
 *
 * @param metricRegistry
 *            the registry to report on
 * @param config
 *            the configuration map (see {@link MetricsFactory})
 * @return the reporter instance
 */
public static ScheduledReporter createElasticSearchReporter(MetricRegistry metricRegistry,
        Map<String, Object> config) throws BaleenException {
    try {
        String server = (String) config.getOrDefault("server", "localhost:9200");
        String index = (String) config.getOrDefault("index", "metrics");
        int timeout = (int) config.getOrDefault("timeout", 1000);
        int bulkSize = (int) config.getOrDefault("bulkSize", 2500);

        return ElasticsearchReporter.forRegistry(metricRegistry).convertRatesTo(getRatesUnit(config))
                .convertDurationsTo(getDurationUnit(config)).bulkSize(bulkSize).hosts(server).index(index)
                .timeout(timeout).build();
    } catch (IOException e) {
        throw new BaleenException("Unable to create ElasticSearch reporter", e);
    }
}
MetricsPlugin.java 文件源码 项目:werval 阅读 24 收藏 0 点赞 0 评论 0
@Override
public void onPassivate( Application application )
{
    requestTimers.values().forEach( t -> t.stop() );
    requestTimers = null;
    reporters.forEach(
        r ->
        {
            if( r instanceof ScheduledReporter )
            {
                ( (ScheduledReporter) r ).stop();
            }
            else if( r instanceof JmxReporter )
            {
                ( (JmxReporter) r ).stop();
            }
        }
    );
    reporters = null;
    api = null;
    eventRegistration.unregister();
    eventRegistration = null;
    SharedMetricRegistries.clear();
    SharedHealthCheckRegistries.clear();
}
DatadogReporterFactory.java 文件源码 项目:metrics-datadog-factory 阅读 24 收藏 0 点赞 0 评论 0
@Override
public ScheduledReporter build(MetricRegistry registry) {

    final EnumSet<Expansions> expansions = EnumSet.of(COUNT, RATE_1_MINUTE,
            RATE_15_MINUTE, MEDIAN, P95, P99);
    final DatadogReporter reporter;
    try {
        reporter = new DatadogReporter.Builder(registry).withEC2Host()
                .withApiKey(apiKey).withExpansions(expansions).build();
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalStateException(
                "Unable to construct DataDog metrics reporter", e);
    }
    return reporter;
}
InfluxdbReporter.java 文件源码 项目:metrics-influxdb 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Builds a {@link ScheduledReporter} with the given properties, sending
 * metrics using the given InfluxDB.
 *
 * @return a {@link ScheduledReporter}
 */
public ScheduledReporter build() {
    ScheduledReporter reporter;

    switch (influxdbVersion) {
    case V08:
        Influxdb influxdb = buildInfluxdb();
        reporter = (executor == null)
                ? new ReporterV08(registry, influxdb, clock, prefix, rateUnit, durationUnit, filter, skipIdleMetrics)
                : new ReporterV08(registry, influxdb, clock, prefix, rateUnit, durationUnit, filter, skipIdleMetrics, executor)
                ;
        break;
    default:
        Sender s = buildSender();
        reporter = executor == null
                ? new MeasurementReporter(s, registry, filter, rateUnit, durationUnit, clock, tags, transformer)
                : new MeasurementReporter(s, registry, filter, rateUnit, durationUnit, clock, tags, transformer, executor)
                ;
    }
    return reporter;
}
InfluxdbReporterBuilderTest.java 文件源码 项目:metrics-influxdb 阅读 74 收藏 0 点赞 0 评论 0
@Test
public void builder_api_with_tags() {
    String tagKey = "tag-name";
    String tagValue = "tag-value";

    Builder builder = InfluxdbReporter
            .forRegistry(registry)
            .tag(tagKey, tagValue)
            .protocol(new HttpInfluxdbProtocol());

    assertThat(builder.tags, notNullValue());
    assertThat(builder.tags, hasEntry(tagKey, tagValue));

    ScheduledReporter reporter = builder.build();
    assertThat(reporter, notNullValue());
}
BasicJvmMetrisTest.java 文件源码 项目:signalfx-java 阅读 25 收藏 0 点赞 0 评论 0
@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();
}
NbdStatsReporter.java 文件源码 项目:minebox 阅读 23 收藏 0 点赞 0 评论 0
@Inject
public NbdStatsReporter(MetricRegistry metrics) {
    ScheduledReporter reporter = Slf4jReporter.forRegistry(metrics)
            .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG)
            .outputTo(LOGGER)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
    reporter.start(5, TimeUnit.SECONDS);
}
MetricService.java 文件源码 项目:Re-Collector 阅读 25 收藏 0 点赞 0 评论 0
@Override
protected void shutDown() throws Exception {
    for (ScheduledReporter entry : reporter.values()) {
        LOG.debug("Stopping metrics reporter: {}", entry);
        entry.stop();
    }
}
GraphiteScheduledReporterFactory.java 文件源码 项目:circus-train 阅读 24 收藏 0 点赞 0 评论 0
@Override
public ScheduledReporter newInstance(String qualifiedReplicaName) {
  InetSocketAddress address = new InetSocketAddressFactory().newInstance(graphiteHost);
  Graphite graphite = new Graphite(address);
  String prefix = DotJoiner.join(graphitePrefix, qualifiedReplicaName);
  return GraphiteReporter.forRegistry(runningMetricRegistry).prefixedWith(prefix).build(graphite);
}
ApptuitReporterFactory.java 文件源码 项目:JInsight 阅读 21 收藏 0 点赞 0 评论 0
public ScheduledReporter build(MetricRegistry registry) {
  try {
    return new ApptuitReporter(registry, getFilter(), getRateUnit(), getDurationUnit(),
        globalTags, apiKey, apiUrl != null ? new URL(apiUrl) : null, reportingMode);
  } catch (MalformedURLException e) {
    throw new IllegalArgumentException(e);
  }
}
RegistryService.java 文件源码 项目:JInsight 阅读 24 收藏 0 点赞 0 评论 0
private ScheduledReporter createReporter(ApptuitReporterFactory factory,
    Map<String, String> globalTags, String apiToken, String apiUrl, ReportingMode reportingMode) {
  factory.setRateUnit(TimeUnit.SECONDS);
  factory.setDurationUnit(TimeUnit.MILLISECONDS);
  globalTags.forEach(factory::addGlobalTag);
  factory.setApiKey(apiToken);
  factory.setApiUrl(apiUrl);
  factory.setReportingMode(reportingMode);

  return factory.build(registry);
}
RegistryServiceTest.java 文件源码 项目:JInsight 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() throws Exception {
  mockFactory = mock(ApptuitReporterFactory.class);
  when(mockFactory.build(any(MetricRegistry.class))).thenReturn(mock(ScheduledReporter.class));
  mockConfigService = mock(ConfigService.class);
  when(mockConfigService.getGlobalTags()).thenReturn(ConfigService.getInstance().getGlobalTags());
}
StatisticsCollector.java 文件源码 项目:Lagerta 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Will report to ignite that node is overloaded if the latency for requests from the given quantile will become
 * larger than a given threshold.
 *
 * @param ignite Local ignite instance to be used for overload reporting.
 * @param latencyThreshold Hard threshold after exceeding which node will report overload.
 * @param quantile A quantile in {@code [0..1]}.
 */
public void enableIgniteNodeOverloadStop(Ignite ignite, long latencyThreshold, double quantile) {
    ScheduledReporter reporter = IgniteNodeOverloadReporter.forRegistry(registry)
        .setIgnite(ignite)
        .setLatencyThreshold(latencyThreshold)
        .setQuantile(quantile)
        .build();
    reporter.start(reportFrequency, TimeUnit.MILLISECONDS);
}
IgniteNodeOverloadReporterProvider.java 文件源码 项目:Lagerta 阅读 26 收藏 0 点赞 0 评论 0
@Override public ScheduledReporter getIfEnabled() {
    if (!config.isNodeOverloadStopEnabled()) {
        return null;
    }
    return new IgniteNodeOverloadReporter(
        registry,
        config.getWarmupDuration(),
        config.getLatencyThreshold(),
        config.getQuantile(),
        ignite
    );
}
GangliaReporterProvider.java 文件源码 项目:Lagerta 阅读 24 收藏 0 点赞 0 评论 0
@Override public ScheduledReporter getIfEnabled() {
    if (!config.isGangliaReportingEnabled()) {
        return null;
    }
    try {
        InetSocketAddress gangliaAddress = config.getGangliaAddress();
        GMetric ganglia = new GMetric(gangliaAddress.getHostString(), gangliaAddress.getPort(),
            GMetric.UDPAddressingMode.UNICAST, 1);
        return GangliaReporter.forRegistry(registry)
            .prefixedWith(StatisticsCollector.GANGLIA_METRICS_PREFIX)
            .build(ganglia);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
DebugReporterProvider.java 文件源码 项目:Lagerta 阅读 18 收藏 0 点赞 0 评论 0
@Override public ScheduledReporter getIfEnabled() {
    if (!config.isDebugReportingEnabled()) {
        return null;
    }
    return ConsoleReporter.forRegistry(registry)
        .build();
}
HumanReadableCsvReporterProvider.java 文件源码 项目:Lagerta 阅读 21 收藏 0 点赞 0 评论 0
@Override public ScheduledReporter getIfEnabled() {
    if (!config.isCsvReportingEnabled()) {
        return null;
    }
    return new HumanReadableCsvReporter(
        registry,
        config.getWarmupDuration(),
        new File(config.getCsvReportDirectory())
    );
}
ReportersManager.java 文件源码 项目:Lagerta 阅读 28 收藏 0 点赞 0 评论 0
public void startReporters() {
    for (ReporterProvider provider : reporterProviders) {
        ScheduledReporter reporter = provider.getIfEnabled();

        if (reporter != null) {
            reporters.add(reporter);
            reporter.start(config.getReportFrequency(), TimeUnit.MILLISECONDS);
        }
    }
}
NbdStatsReporter.java 文件源码 项目:tools 阅读 25 收藏 0 点赞 0 评论 0
@Inject
public NbdStatsReporter(MetricRegistry metrics) {
    ScheduledReporter reporter = Slf4jReporter.forRegistry(metrics)
            .withLoggingLevel(Slf4jReporter.LoggingLevel.DEBUG)
            .outputTo(LOGGER)
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
    reporter.start(5, TimeUnit.SECONDS);
}
StatsDReporterFactory.java 文件源码 项目:statsd-reporter-example 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Configures and builds a {@link ScheduledReporter} instance for the given registry.
 *
 * @param registry the metrics registry to report metrics from.
 * @return a reporter configured for the given metrics registry.
 */
@Override
public ScheduledReporter build(MetricRegistry registry) {

    StatsDReporter.Builder builder
            = StatsDReporter.forRegistry(registry)
                            .convertDurationsTo(getDurationUnit())
                            .convertRatesTo(getRateUnit())
                            .filter(getFilter());

    LOG.info("StatsDReporterFactory built with host: {}, port: {}", getHost(), getPort());

    return builder.build(getHost(), getPort());
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 24 收藏 0 点赞 0 评论 0
public CodahaleMetricsProvider(CodahaleMetricsConfig conf) throws IOException {
    metricsOutputFrequencyInSecs = conf.getOutputFreqInSecs();
    int reporterCount = 0;
    for (Reporter reporter : conf.getReporters()) {
        ScheduledReporter codahaleReporter = null;
        switch (reporter) {
            case CONSOLE:
                codahaleReporter = createAndGetConfiguredConsoleReporter();
                break;
            case GRAPHITE:
                codahaleReporter = createAndGetConfiguredGraphiteReporter(conf.getPrefix(),
                                                                          conf.getGraphiteHostConfig());
                break;
            case CSV:
                codahaleReporter = createAndGetConfiguredCSVReporter(conf.getPrefix(),
                                                                     conf.getCsvDir());
                break;
            case SLF4J:
                codahaleReporter = createAndGetConfiguredSlf4jReporter(conf.getSlf4jLogger());
                break;
        }
        if (codahaleReporter != null) {
            reporters.add(codahaleReporter);
            reporterCount++;
        }
    }
    if (reporterCount == 0) {
        LOG.warn("No metric reporters found, so metrics won't be available");
    }
    startMetrics();
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 22 收藏 0 点赞 0 评论 0
@Override
public void startMetrics() {
    for (ScheduledReporter r : reporters) {
        LOG.info("Starting metrics reporter {} reporting every {} Secs",
                 r.getClass().getCanonicalName(), metricsOutputFrequencyInSecs);
        r.start(metricsOutputFrequencyInSecs, TimeUnit.SECONDS);
    }
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void stopMetrics() {
    for (ScheduledReporter r : reporters) {
        r.report();
        LOG.info("Stopping reporter {}", r.toString());
        r.stop();
    }
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 24 收藏 0 点赞 0 评论 0
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);
}
CodahaleMetricsProvider.java 文件源码 项目:incubator-omid 阅读 24 收藏 0 点赞 0 评论 0
private ScheduledReporter createAndGetConfiguredSlf4jReporter(String slf4jLogger) {
    LOG.info("Configuring stats with SLF4J with logger {}", slf4jLogger);
    return Slf4jReporter.forRegistry(metrics)
            .outputTo(LoggerFactory.getLogger(slf4jLogger))
            .convertRatesTo(TimeUnit.SECONDS)
            .convertDurationsTo(TimeUnit.MILLISECONDS)
            .build();
}


问题


面经


文章

微信
公众号

扫码关注公众号