com.codahale.metrics.Clock.getTime()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中com.codahale.metrics.Clock.getTime()方法的一些代码示例,展示了Clock.getTime()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.getTime()方法的具体详情如下:
包路径:com.codahale.metrics.Clock
类名称:Clock
方法名:getTime

Clock.getTime介绍

[英]Returns the current time in milliseconds.
[中]以毫秒为单位返回当前时间。

代码示例

代码示例来源:origin: stagemonitor/stagemonitor

@Override
  public long getTime() {
    final long time = delegate.getTime();
    return time - (time % periodInMS);
  }
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public MonitorCallback onMessageIngested(Message<?> message) {
  final long start = clock.getTime();
  return new MonitorCallback() {
    @Override
    public void reportSuccess() {
      processedDurationHistogram.update(clock.getTime() - start);
    }
    @Override
    public void reportFailure(Throwable cause) {
      processedDurationHistogram.update(clock.getTime() - start);
    }
    @Override
    public void reportIgnored() {
      processedDurationHistogram.update(clock.getTime() - start);
    }
  };
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
  public void reportIgnored() {
    processedDurationHistogram.update(clock.getTime() - start);
  }
};

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public void reportFailure(Throwable cause) {
  processedDurationHistogram.update(clock.getTime() - start);
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public void reportSuccess() {
  processedDurationHistogram.update(clock.getTime() - start);
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

private long currentTimeInSeconds() {
  return TimeUnit.MILLISECONDS.toSeconds(clock.getTime());
}

代码示例来源:origin: stagemonitor/stagemonitor

private GregorianCalendar getNowUTC() {
  final GregorianCalendar now = new GregorianCalendar();
  now.setTimeZone(TimeZone.getTimeZone("UTC"));
  now.setTime(new Date(clock.getTime()));
  return now;
}

代码示例来源:origin: stagemonitor/stagemonitor

/**
 * Starts the reporter polling at the given period.
 *
 * @param period the amount of time between polls
 * @param unit   the unit for {@code period}
 */
public void start(long period, TimeUnit unit) {
  synchronized (this) {
    if (started) {
      throw new IllegalStateException("This reporter has already been started");
    }
    final long periodInMS = unit.toMillis(period);
    executor.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        try {
          report();
        } catch (RuntimeException ex) {
          logger.error("RuntimeException thrown from {}#report. Exception was suppressed.", ScheduledMetrics2Reporter.this.getClass().getSimpleName(), ex);
        }
      }
    }, getOffsetUntilTimestampIsDivisableByPeriod(clock.getTime(), periodInMS), periodInMS, TimeUnit.MILLISECONDS);
    this.clock = new QuantizedClock(clock, periodInMS);
    this.started = true;
  }
}

代码示例来源:origin: io.dropwizard.metrics/metrics-core

@Override
@SuppressWarnings("rawtypes")
public void report(SortedMap<String, Gauge> gauges,
          SortedMap<String, Counter> counters,
          SortedMap<String, Histogram> histograms,
          SortedMap<String, Meter> meters,
          SortedMap<String, Timer> timers) {
  final long timestamp = TimeUnit.MILLISECONDS.toSeconds(clock.getTime());
  for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
    reportGauge(timestamp, entry.getKey(), entry.getValue());
  }
  for (Map.Entry<String, Counter> entry : counters.entrySet()) {
    reportCounter(timestamp, entry.getKey(), entry.getValue());
  }
  for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
    reportHistogram(timestamp, entry.getKey(), entry.getValue());
  }
  for (Map.Entry<String, Meter> entry : meters.entrySet()) {
    reportMeter(timestamp, entry.getKey(), entry.getValue());
  }
  for (Map.Entry<String, Timer> entry : timers.entrySet()) {
    reportTimer(timestamp, entry.getKey(), entry.getValue());
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

private void setTime(long time) {
  Clock clock = Mockito.mock(Clock.class);
  when(clock.getTime()).thenReturn(time);
  indexSelector = new IndexSelector(clock);
}

代码示例来源:origin: stagemonitor/stagemonitor

@Before
public void setUp() throws Exception {
  clock = Mockito.mock(Clock.class);
  when(clock.getTime()).thenReturn(0L);
  indexSelector = new IndexSelector(clock);
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public void reportMetrics(final Map<MetricName, Gauge> gauges,
             final Map<MetricName, Counter> counters,
             final Map<MetricName, Histogram> histograms,
             final Map<MetricName, Meter> meters,
             final Map<MetricName, Timer> timers) {
  if (!corePlugin.isStagemonitorActive()) {
    return;
  }
  long timestamp = clock.getTime();
  final Timer.Context time = registry.timer(reportingTimeMetricName).time();
  final MetricsOutputStreamHandler metricsOutputStreamHandler = new MetricsOutputStreamHandler(gauges, counters, histograms, meters, timers, timestamp);
  if (!corePlugin.isOnlyLogElasticsearchMetricReports()) {
    if (!elasticsearchClient.isElasticsearchAvailable()) {
      return;
    }
    final String url = corePlugin.getElasticsearchUrl() + "/" + getTodaysIndexName() + "/" + METRICS_TYPE + "/_bulk";
    httpClient.send("POST", url, CONTENT_TYPE_JSON,
        metricsOutputStreamHandler, NoopResponseHandler.INSTANCE);
  } else {
    try {
      final ByteArrayOutputStream os = new ByteArrayOutputStream();
      metricsOutputStreamHandler.withHttpURLConnection(os);
      elasticsearchMetricsLogger.info(os.toString("UTF-8"));
    } catch (IOException e) {
      logger.warn(e.getMessage(), e);
    }
  }
  time.stop();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Override
public void reportMetrics(Map<MetricName, Gauge> gauges,
             Map<MetricName, Counter> counters,
             Map<MetricName, Histogram> histograms,
             Map<MetricName, Meter> meters,
             Map<MetricName, Timer> timers) {
  final Timer.Context time = registry.timer(reportingTimeMetricName).time();
  long timestamp = clock.getTime();
  reportGauges(gauges, timestamp);
  reportCounter(counters, timestamp);
  reportHistograms(histograms, timestamp);
  reportMeters(meters, timestamp);
  reportTimers(timers, timestamp);
  flush();
  time.stop();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void getTime1() throws Exception {
  when(delegate.getTime()).thenReturn(1001L);
  assertEquals(1000, new QuantizedClock(delegate, 100).getTime());
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
  public void getTime3() throws Exception {
    when(delegate.getTime()).thenReturn(1000L);
    assertEquals(1000, new QuantizedClock(delegate, 100).getTime());
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
  public void testSelectIndexIntraMonth() throws Exception {
    when(clock.getTime()).thenReturn(DateUtils.getDayInMillis() * 7);
    final String indexPattern = indexSelector.getIndexPatternOlderThanDays("metrics-", 2);
    assertEquals("metrics-*,-metrics-1970.01.08,-metrics-1970.01.07,-metrics-1970.01.06", indexPattern);
  }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void getTime2() throws Exception {
  when(delegate.getTime()).thenReturn(1999L);
  assertEquals(1900, new QuantizedClock(delegate, 100).getTime());
}

代码示例来源:origin: stagemonitor/stagemonitor

@Before
public void setUp() throws Exception {
  httpClient = mock(HttpClient.class);
  Clock clock = mock(Clock.class);
  timestamp = System.currentTimeMillis();
  when(clock.getTime()).thenReturn(timestamp);
  final CorePlugin corePlugin = mock(CorePlugin.class);
  when(corePlugin.getInfluxDbUrl()).thenReturn(new URL("http://localhost:8086"));
  when(corePlugin.getInfluxDbDb()).thenReturn("stm");
  influxDbReporter = InfluxDbReporter.forRegistry(new Metric2Registry(), corePlugin)
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(DURATION_UNIT)
      .globalTags(singletonMap("app", "test"))
      .httpClient(httpClient)
      .clock(clock)
      .build();
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void testSchedule() throws Exception {
  when(corePlugin.isOnlyLogElasticsearchMetricReports()).thenReturn(true);
  // this clock starts at 0 and then progresses normally
  when(clock.getTime()).then(new Answer<Long>() {
    long firstTimestamp;
    @Override
    public Long answer(InvocationOnMock invocation) throws Throwable {
      final long time = System.currentTimeMillis();
      if (firstTimestamp == 0) {
        firstTimestamp = time;
      }
      return (time - firstTimestamp);
    }
  });
  registry.register(name("test").build(), new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return 1;
    }
  });
  elasticsearchReporter.start(100, TimeUnit.MILLISECONDS);
  Thread.sleep(300);
  verify(metricsLogger).info(eq(String.format("{\"index\":{\"_index\":\"stagemonitor-metrics-%s\",\"_type\":\"metrics\"}}\n" +
      "{\"@timestamp\":100,\"name\":\"test\",\"app\":\"test\",\"value\":1.0}\n", StringUtils.getLogstashStyleDate())));
  verify(metricsLogger).info(eq(String.format("{\"index\":{\"_index\":\"stagemonitor-metrics-%s\",\"_type\":\"metrics\"}}\n" +
      "{\"@timestamp\":200,\"name\":\"test\",\"app\":\"test\",\"value\":1.0}\n", StringUtils.getLogstashStyleDate())));
}

代码示例来源:origin: stagemonitor/stagemonitor

this.clock = mock(Clock.class);
timestamp = System.currentTimeMillis();
when(clock.getTime()).thenReturn(timestamp);
final HttpClient httpClient = mock(HttpClient.class);
when(httpClient.send(any(), any(), any(), any(), any())).thenAnswer(new Answer<Integer>() {

相关文章

微信公众号

最新文章

更多