コード例 #1
0
  private void collectTimerReports(
      List<DBObject> docs, SortedMap<String, Timer> timers, Date timestamp) {
    if (timers.isEmpty()) return;
    for (Map.Entry<String, Timer> entry : timers.entrySet()) {
      final BasicDBObject report = getBasicDBObject(timestamp, entry.getKey(), "timer");
      final Timer v = entry.getValue();
      final Snapshot s = v.getSnapshot();
      // meter part
      report.put("count", v.getCount());
      report.put("rate-unit", getRateUnit());
      report.put("1-minute-rate", convertRate(v.getOneMinuteRate()));
      report.put("5-minute-rate", convertRate(v.getFiveMinuteRate()));
      report.put("15-minute-rate", convertRate(v.getFifteenMinuteRate()));
      report.put("mean-rate", convertRate(v.getMeanRate()));

      // histogram part
      report.put("duration-unit", getDurationUnit());
      report.put("75-percentile", convertDuration(s.get75thPercentile()));
      report.put("95-percentile", convertDuration(s.get95thPercentile()));
      report.put("98-percentile", convertDuration(s.get98thPercentile()));
      report.put("99-percentile", convertDuration(s.get99thPercentile()));
      report.put("999-percentile", convertDuration(s.get999thPercentile()));
      report.put("max", convertDuration(s.getMax()));
      report.put("min", convertDuration(s.getMin()));
      report.put("mean", convertDuration(s.getMean()));
      report.put("median", convertDuration(s.getMedian()));
      report.put("stddev", convertDuration(s.getStdDev()));
      docs.add(report);
    }
  }
  @Test
  public void callLambdaExpressionTimedStaticMethodOnce() {
    // Call the timed static method and assert it's been timed once
    TimedStaticMethodWithNameFromElExpression.lambdaExpressionStaticTimedMethod();

    assertThat(
        "Shared metric registry is not created",
        SharedMetricRegistries.names(),
        hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);

    assertThat("Timer is not registered correctly", registry.getTimers(), hasKey(TIMER_NAME));
    Timer timer = registry.getTimers().get(TIMER_NAME);

    assertThat(
        "Timer count is incorrect", timer.getCount(), is(equalTo(TIMER_COUNT.incrementAndGet())));
  }
コード例 #3
0
  protected Map<String, Object> buildTimerMap(Timer t) {
    Map<String, Object> metrics = Maps.newHashMap();

    if (t == null) {
      return metrics;
    }

    TimeUnit timeUnit = TimeUnit.MICROSECONDS;

    Map<String, Object> time = Maps.newHashMap();
    time.put("max", TimeUnit.MICROSECONDS.convert(t.getSnapshot().getMax(), TimeUnit.NANOSECONDS));
    time.put("min", TimeUnit.MICROSECONDS.convert(t.getSnapshot().getMin(), TimeUnit.NANOSECONDS));
    time.put(
        "mean",
        TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().getMean(), TimeUnit.NANOSECONDS));
    time.put(
        "95th_percentile",
        TimeUnit.MICROSECONDS.convert(
            (long) t.getSnapshot().get95thPercentile(), TimeUnit.NANOSECONDS));
    time.put(
        "98th_percentile",
        TimeUnit.MICROSECONDS.convert(
            (long) t.getSnapshot().get98thPercentile(), TimeUnit.NANOSECONDS));
    time.put(
        "99th_percentile",
        TimeUnit.MICROSECONDS.convert(
            (long) t.getSnapshot().get99thPercentile(), TimeUnit.NANOSECONDS));
    time.put(
        "std_dev",
        TimeUnit.MICROSECONDS.convert((long) t.getSnapshot().getStdDev(), TimeUnit.NANOSECONDS));

    Map<String, Object> rate = Maps.newHashMap();
    rate.put("one_minute", t.getOneMinuteRate());
    rate.put("five_minute", t.getFiveMinuteRate());
    rate.put("fifteen_minute", t.getFifteenMinuteRate());
    rate.put("total", t.getCount());
    rate.put("mean", t.getMeanRate());

    metrics.put("rate_unit", "events/second");
    metrics.put("duration_unit", timeUnit.toString().toLowerCase());
    metrics.put("time", time);
    metrics.put("rate", rate);

    return metrics;
  }
 public void printMetrics() {
   logger.info("Metrics");
   Metrics metrics = session.getCluster().getMetrics();
   Gauge<Integer> gauge = metrics.getConnectedToHosts();
   Integer numberOfHosts = gauge.getValue();
   logger.info("Number of hosts: " + numberOfHosts);
   Metrics.Errors errors = metrics.getErrorMetrics();
   Counter counter = errors.getReadTimeouts();
   logger.info("Number of read timeouts:" + counter.getCount());
   com.codahale.metrics.Timer timer = metrics.getRequestsTimer();
   Timer.Context context = timer.time();
   try {
     long numberUserRequests = timer.getCount();
     logger.info("Number of user requests:" + numberUserRequests);
   } finally {
     context.stop();
   }
 }
コード例 #5
0
ファイル: BenchmarkResults.java プロジェクト: indraj/luwak
 @Override
 public String toString() {
   StringWriter sw = new StringWriter();
   Locale locale = Locale.ROOT;
   try (PrintWriter output = new PrintWriter(sw)) {
     final Snapshot snapshot = timer.getSnapshot();
     output.printf(locale, "Benchmark Results%n");
     output.printf(locale, "             count = %d%n", timer.getCount());
     output.printf(locale, "         mean rate = %2.2f calls/%s%n", timer.getMeanRate(), "s");
     output.printf(
         locale,
         "               min = %d %s%n",
         TimeUnit.NANOSECONDS.toMillis(snapshot.getMin()),
         "ms");
     output.printf(
         locale,
         "               max = %d %s%n",
         TimeUnit.NANOSECONDS.toMillis(snapshot.getMax()),
         "ms");
     output.printf(locale, "              mean = %2.2f %s%n", snapshot.getMean() / 1000000, "ms");
     output.printf(
         locale, "            stddev = %2.2f %s%n", snapshot.getStdDev() / 1000000, "ms");
     output.printf(
         locale, "            median = %2.2f %s%n", snapshot.getMedian() / 1000000, "ms");
     output.printf(
         locale, "              75%% <= %2.2f %s%n", snapshot.get75thPercentile() / 1000000, "ms");
     output.printf(
         locale, "              95%% <= %2.2f %s%n", snapshot.get95thPercentile() / 1000000, "ms");
     output.printf(
         locale,
         "            99.9%% <= %2.2f %s%n",
         snapshot.get999thPercentile() / 1000000,
         "ms");
   }
   return sw.toString();
 }
コード例 #6
0
    @Override
    public boolean matchesSafely(JsonObject jsonObject) {

      JsonObject jsonMetric = jsonObject.get("metric").asObject();
      JsonObject jsonCounter;
      JsonObject jsonMeter;
      JsonObject jsonTimer;
      Counter counter;
      Meter meter;
      Timer timer;

      // check counter metric
      if (jsonMetric.get("counter") != null) {
        jsonCounter = jsonMetric.get("counter").asObject();
        counter = (Counter) metric;
        if (jsonCounter.get("counter").asLong() != counter.getCount()) {
          reason = "counter " + counter.getCount();
          return false;
        }
      }

      // check meter metric
      if (jsonMetric.get("meter") != null) {
        jsonMeter = jsonMetric.get("meter").asObject();
        meter = (Meter) metric;

        if (jsonMeter.get("counter").asLong() != meter.getCount()) {
          reason = "counter " + meter.getCount();
          return false;
        }

        if (jsonMeter.get("1_min_rate").asDouble() != meter.getOneMinuteRate()) {
          reason = "1 minute rate " + meter.getOneMinuteRate();
          return false;
        }

        if (jsonMeter.get("5_min_rate").asDouble() != meter.getOneMinuteRate()) {
          reason = "5 minute rate " + meter.getFiveMinuteRate();
          return false;
        }

        if (jsonMeter.get("15_min_rate").asDouble() != meter.getFifteenMinuteRate()) {
          reason = "15 minute rate " + meter.getFifteenMinuteRate();
          return false;
        }
      }

      if (jsonMetric.get("timer") != null) {
        jsonTimer = jsonMetric.get("timer").asObject();
        timer = (Timer) metric;

        if (jsonTimer.get("counter").asLong() != timer.getCount()) {
          reason = "counter " + timer.getCount();
          return false;
        }

        if (jsonTimer.get("1_min_rate").asDouble() != timer.getOneMinuteRate()) {
          reason = "1 minute rate " + timer.getOneMinuteRate();
          return false;
        }

        if (jsonTimer.get("5_min_rate").asDouble() != timer.getOneMinuteRate()) {
          reason = "5 minute rate " + timer.getFiveMinuteRate();
          return false;
        }

        if (jsonTimer.get("15_min_rate").asDouble() != timer.getFifteenMinuteRate()) {
          reason = "15 minute rate " + timer.getFifteenMinuteRate();
          return false;
        }

        if (jsonTimer.get("mean").asDouble() != nanoToMs(timer.getSnapshot().getMean())) {
          reason = "mean " + timer.getSnapshot().getMean();
          return false;
        }

        if (jsonTimer.get("min").asDouble() != nanoToMs(timer.getSnapshot().getMin())) {
          reason = "min " + timer.getSnapshot().getMin();
          return false;
        }

        if (jsonTimer.get("max").asDouble() != nanoToMs(timer.getSnapshot().getMax())) {
          reason = "max " + timer.getSnapshot().getMax();
          return false;
        }

        if (jsonTimer.get("stddev").asDouble() != nanoToMs(timer.getSnapshot().getStdDev())) {
          reason = "stddev " + timer.getSnapshot().getStdDev();
          return false;
        }
      }

      return true;
    }