Java Code Examples for com.codahale.metrics.Clock

The following examples show how to use com.codahale.metrics.Clock. These examples are extracted from open source projects. 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 Project: sofa-jraft   Source File: MetricReporter.java    License: Apache License 2.0 6 votes vote down vote up
private MetricReporter(MetricRegistry registry, //
                       PrintStream output, //
                       String prefix, //
                       Locale locale, //
                       Clock clock, //
                       TimeZone timeZone, //
                       TimeUnit rateUnit, //
                       TimeUnit durationUnit, //
                       MetricFilter filter, //
                       Set<MetricAttribute> disabledMetricAttributes) {
    this.registry = registry;
    this.output = output;
    this.prefix = prefix;
    this.locale = locale;
    this.clock = clock;
    this.dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM, locale);
    this.dateFormat.setTimeZone(timeZone);
    this.rateFactor = rateUnit.toSeconds(1);
    this.rateUnit = calculateRateUnit(rateUnit);
    this.durationFactor = durationUnit.toNanos(1);
    this.durationUnit = durationUnit.toString().toLowerCase(Locale.US);
    this.filter = filter;
    this.disabledMetricAttributes = disabledMetricAttributes != null ? disabledMetricAttributes : Collections
        .emptySet();
}
 
Example 2
Source Project: arcusplatform   Source File: IrisMetricsTopicReporter.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public IrisMetricsTopicReporter(
      MetricRegistry registry,
      IrisMetricsReporterConfig reporterConfig,
      KafkaOpsConfig config
) {
   this.registry = registry;

   this.metrics = new IrisTopicReporterMetrics(IrisMetrics.metrics("metrics.kafkareporter"));
   this.clock = Clock.defaultClock();
   this.kafkaProducer = new KafkaProducer<String, String>(config.toNuProducerProperties(), new StringSerializer(), new StringSerializer());
   this.executor = ThreadPoolBuilder.newSingleThreadedScheduler("metrics-" + config.getTopicMetrics() + "-reporter");
   this.kafkaTopic = config.getTopicMetrics();

   this.reporting = reporterConfig.getEnabled();
   this.filter = reporterConfig.getTopicFilter();
   this.reportingIntervalMs = TimeUnit.MILLISECONDS.convert(reporterConfig.getReportingUnit(), reporterConfig.getReportingUnitType());
   this.counterBatchSize = reporterConfig.getBatchSize();
   this.rateFactor = reporterConfig.getTopicRateUnit().toSeconds(1);
   this.durationFactor = 1.0 / reporterConfig.getTopicDurationUnit().toNanos(1);
}
 
Example 3
Source Project: styx   Source File: GraphiteReporterTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setUp() {
    Clock clock = mock(Clock.class);
    graphite = mock(Graphite.class);

    MetricRegistry registry = mock(MetricRegistry.class);

    when(clock.getTime()).thenReturn(TIMESTAMP * 1000);
    reporter = forRegistry(registry)
            .withClock(clock)
            .prefixedWith("prefix")
            .convertRatesTo(SECONDS)
            .convertDurationsTo(MILLISECONDS)
            .filter(MetricFilter.ALL)
            .build(graphite);

    logging = new LoggingTestSupport(GraphiteReporter.class);
}
 
Example 4
Source Project: lucene-solr   Source File: MetricSuppliers.java    License: Apache License 2.0 6 votes vote down vote up
private static Clock getClock(PluginInfo info, String param) {
  if (info == null) {
    return Clock.defaultClock();
  }
  String clock = null;
  if (info.attributes != null) {
    clock = info.attributes.get(param);
  }
  if (clock == null && info.initArgs != null) {
    clock = (String)info.initArgs.get(param);
  }
  Clock clk = Clock.defaultClock();
  if (clock != null) {
    if (clock.equalsIgnoreCase(CLOCK_USER)) {
      clk = USER_CLOCK;
    } else if (clock.equalsIgnoreCase(CLOCK_CPU)) {
      clk = CPU_CLOCK;
    }
  }
  return clk;
}
 
Example 5
Source Project: hudi   Source File: DatadogReporter.java    License: Apache License 2.0 6 votes vote down vote up
protected DatadogReporter(
    MetricRegistry registry,
    DatadogHttpClient client,
    String prefix,
    Option<String> host,
    Option<List<String>> tags,
    MetricFilter filter,
    TimeUnit rateUnit,
    TimeUnit durationUnit) {
  super(registry, "hudi-datadog-reporter", filter, rateUnit, durationUnit);
  this.client = client;
  this.prefix = prefix;
  this.host = host;
  this.tags = tags;
  this.clock = Clock.defaultClock();
}
 
Example 6
Source Project: sofa-jraft   Source File: MetricReporter.java    License: Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.prefix = "";
    this.output = System.out;
    this.locale = Locale.getDefault();
    this.clock = Clock.defaultClock();
    this.timeZone = TimeZone.getDefault();
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.filter = MetricFilter.ALL;
    this.disabledMetricAttributes = Collections.emptySet();
}
 
Example 7
Source Project: oneops   Source File: ElasticsearchReporter.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source Project: oneops   Source File: ElasticsearchReporter.java    License: Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 9
Source Project: styx   Source File: GraphiteReporter.java    License: Apache License 2.0 5 votes vote down vote up
private GraphiteReporter(MetricRegistry registry,
                         GraphiteSender graphite,
                         Clock clock,
                         String prefix,
                         TimeUnit rateUnit,
                         TimeUnit durationUnit,
                         MetricFilter filter) {
    super(registry, "graphite-reporter", filter, rateUnit, durationUnit);
    this.graphite = graphite;
    this.clock = clock;
    this.prefix = prefix;
}
 
Example 10
private void setupRateTest() throws InterruptedException {
    Clock clock = mock(Clock.class);

    meter = new DelegatingDerivingMeter(new Meter(clock));

    when(clock.getTick()).thenReturn(0L);
    meter.mark(0);
    meter.mark(2000);
    // need to 'wait' more than 5 seconds for the Codahale metrics meter to 'tick'.
    when(clock.getTick()).thenReturn(TimeUnit.NANOSECONDS.convert(6, TimeUnit.SECONDS));
}
 
Example 11
private Builder(final MetricRegistry metricRegistry, final CloudWatchAsyncClient cloudWatchAsyncClient, final String namespace) {
    this.metricRegistry = metricRegistry;
    this.cloudWatchAsyncClient = cloudWatchAsyncClient;
    this.namespace = namespace;
    this.percentiles = new Percentile[]{Percentile.P75, Percentile.P95, Percentile.P999};
    this.metricFilter = MetricFilter.ALL;
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.globalDimensions = new LinkedHashSet<>();
    this.cwMeterUnit = Optional.empty();
    this.cwRateUnit = toStandardUnit(rateUnit);
    this.cwDurationUnit = toStandardUnit(durationUnit);
    this.clock = Clock.defaultClock();
}
 
Example 12
Source Project: lucene-solr   Source File: MetricsConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaults() throws Exception {
  NodeConfig cfg = loadNodeConfig();
  SolrMetricManager mgr = new SolrMetricManager(cfg.getSolrResourceLoader(), cfg.getMetricsConfig());
  assertTrue(mgr.getCounterSupplier() instanceof MetricSuppliers.DefaultCounterSupplier);
  assertTrue(mgr.getMeterSupplier() instanceof MetricSuppliers.DefaultMeterSupplier);
  assertTrue(mgr.getTimerSupplier() instanceof MetricSuppliers.DefaultTimerSupplier);
  assertTrue(mgr.getHistogramSupplier() instanceof MetricSuppliers.DefaultHistogramSupplier);
  Clock clk = ((MetricSuppliers.DefaultTimerSupplier)mgr.getTimerSupplier()).clk;
  assertTrue(clk instanceof Clock.UserTimeClock);
  Reservoir rsv = ((MetricSuppliers.DefaultTimerSupplier)mgr.getTimerSupplier()).getReservoir();
  assertTrue(rsv instanceof ExponentiallyDecayingReservoir);
}
 
Example 13
Source Project: micro-server   Source File: TestReporter.java    License: Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.output = System.out;
    this.locale = Locale.getDefault();
    this.clock = Clock.defaultClock();
    this.timeZone = TimeZone.getDefault();
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.filter = MetricFilter.ALL;
}
 
Example 14
Source Project: micro-server   Source File: TestReporter.java    License: Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.output = System.out;
    this.locale = Locale.getDefault();
    this.clock = Clock.defaultClock();
    this.timeZone = TimeZone.getDefault();
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.filter = MetricFilter.ALL;
}
 
Example 15
Source Project: datacollector   Source File: ExtendedMeter.java    License: Apache License 2.0 5 votes vote down vote up
public ExtendedMeter(Clock clock) {
  super(clock);
  this.clock = clock;
  this.lastTick = new AtomicLong(this.clock.getTick());
  m30Rate = new EWMA(M30_ALPHA, INTERVAL, TimeUnit.SECONDS);
  h1Rate = new EWMA(H1_ALPHA, INTERVAL, TimeUnit.SECONDS);
  h6Rate = new EWMA(H6_ALPHA, INTERVAL, TimeUnit.SECONDS);
  h12Rate = new EWMA(H12_ALPHA, INTERVAL, TimeUnit.SECONDS);
  h24Rate = new EWMA(H24_ALPHA, INTERVAL, TimeUnit.SECONDS);
}
 
Example 16
Source Project: incubator-gobblin   Source File: OutputStreamReporter.java    License: Apache License 2.0 5 votes vote down vote up
protected Builder() {
  this.name = "OutputStreamReporter";
  this.output = System.out;
  this.locale = Locale.getDefault();
  this.clock = Clock.defaultClock();
  this.timeZone = TimeZone.getDefault();
}
 
Example 17
Source Project: newts   Source File: NewtsReporter.java    License: Apache License 2.0 5 votes vote down vote up
private Builder(MetricRegistry registry) {
    this.registry = registry;
    this.rateUnit = TimeUnit.SECONDS;
    this.durationUnit = TimeUnit.MILLISECONDS;
    this.clock = Clock.defaultClock();
    this.filter = MetricFilter.ALL;
}
 
Example 18
Source Project: newts   Source File: NewtsReporter.java    License: Apache License 2.0 5 votes vote down vote up
private NewtsReporter(MetricRegistry registry,
                    SampleRepository repository,
                    String name,
                    TimeUnit rateUnit,
                    TimeUnit durationUnit,
                    Clock clock,
                    MetricFilter filter) {
    super(registry, "newts-reporter", filter, rateUnit, durationUnit);
    this.repository = repository;
    this.name = name;
    this.clock = clock;
}
 
Example 19
Source Project: ambry   Source File: QuotaManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * A helper function to create quotaMap with controllable clock.
 */
private Map<RestMethod, RejectThrottler> createQuotaMock(FrontendConfig frontendConfig, Clock clock) {
  JSONObject quota = new JSONObject(frontendConfig.restRequestQuota);
  Map<RestMethod, RejectThrottler> quotaMap = new HashMap<>();
  for (RestMethod restMethod : RestMethod.values()) {
    int restMethodQuota = quota.optInt(restMethod.name(), -1);
    quotaMap.put(restMethod, new RejectThrottler(restMethodQuota, new Meter(clock)));
  }
  return quotaMap;
}
 
Example 20
Source Project: ambry   Source File: CachedHistogram.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Exposed for testing.
 * @param clock the {@link Clock} to use for the {@link CachedGauge}.
 * @param reservoir the {@link Reservoir} to use for the histogram.
 * @param timeoutMs the timeout for the value stored in the cache in milliseconds. After this time has passed, a new
 *                  value of the histogram at {@code quantile} will be calculated.
 * @param quantile the quantile of the histogram to cache.
 */
CachedHistogram(Clock clock, Reservoir reservoir, long timeoutMs, double quantile) {
  super(reservoir);
  cache = new CachedGauge<Double>(clock, timeoutMs, TimeUnit.MILLISECONDS) {
    @Override
    protected Double loadValue() {
      return getSnapshot().getValue(quantile);
    }
  };
}
 
Example 21
Source Project: bistoury   Source File: ResettableTimer.java    License: GNU General Public License v3.0 4 votes vote down vote up
public ResettableTimer() {
    this(Clock.defaultClock(), DEFAULT_PER, DEFAULT_TIMER_SIZE);
}
 
Example 22
Source Project: bistoury   Source File: ResettableTimer.java    License: GNU General Public License v3.0 4 votes vote down vote up
public ResettableTimer(Clock clock, double[] percentiles, int timerSize) {
    this.meter = new Meter(clock);
    this.timer = new StatsBuffer(timerSize, percentiles);
}
 
Example 23
Source Project: Flink-CEPplus   Source File: FlinkMeterWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public FlinkMeterWrapper(Meter meter, Clock clock) {
	super(clock);
	this.meter = meter;
}
 
Example 24
Source Project: flink   Source File: FlinkMeterWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public FlinkMeterWrapper(Meter meter, Clock clock) {
	super(clock);
	this.meter = meter;
}
 
Example 25
Source Project: arcusplatform   Source File: IrisMetricSet.java    License: Apache License 2.0 4 votes vote down vote up
public Meter meter(Clock clock) {
   return new Meter(clock);
}
 
Example 26
Source Project: arcusplatform   Source File: IrisMetricSet.java    License: Apache License 2.0 4 votes vote down vote up
public Meter meter(String name, Clock clock) {
   return register(name, meter(clock));
}
 
Example 27
Source Project: arcusplatform   Source File: IrisMetricSet.java    License: Apache License 2.0 4 votes vote down vote up
public Timer timer(Reservoir reservoir, Clock clock) {
   return new Timer(reservoir, clock);
}
 
Example 28
Source Project: arcusplatform   Source File: IrisMetricSet.java    License: Apache License 2.0 4 votes vote down vote up
public Timer timer(String name, Reservoir reservoir, Clock clock) {
   return register(name, timer(reservoir, clock));
}
 
Example 29
Source Project: arcusplatform   Source File: AsyncTimer.java    License: Apache License 2.0 4 votes vote down vote up
private Context()
{
   clock = Clock.defaultClock();

   startTimeNanos = clock.getTick();
}
 
Example 30
Source Project: SpinalTap   Source File: Timer.java    License: Apache License 2.0 4 votes vote down vote up
public Timer(Clock clock, com.codahale.metrics.Timer... timers) {
  this.timers = timers;
  this.clock = clock;
}