Package com.yammer.metrics.stats

Examples of com.yammer.metrics.stats.Snapshot


  @Test
  public void testSnapshotPercentiles() {
    final MetricsHistogram h = new MetricsHistogram("testHistogram", null);
    final long[] data = genRandomData(h);

    final Snapshot s = h.getSnapshot();

    assertPercentile(data, 50, s.getMedian());
    assertPercentile(data, 75, s.get75thPercentile());
    assertPercentile(data, 95, s.get95thPercentile());
    assertPercentile(data, 98, s.get98thPercentile());
    assertPercentile(data, 99, s.get99thPercentile());
    assertPercentile(data, 99.9, s.get999thPercentile());
  }
View Full Code Here


          } else if (name.endsWith(MetricsHistogram.MEAN_METRIC_NAME)) {
            return (float) hist.getMean();
          } else if (name.endsWith(MetricsHistogram.STD_DEV_METRIC_NAME)) {
            return (float) hist.getStdDev();
          } else if (name.endsWith(MetricsHistogram.MEDIAN_METRIC_NAME)) {
            Snapshot s = hist.getSnapshot();
            return (float) s.getMedian();
          } else if (name.endsWith(MetricsHistogram.SEVENTY_FIFTH_PERCENTILE_METRIC_NAME)) {
            Snapshot s = hist.getSnapshot();
            return (float) s.get75thPercentile();
          } else if (name.endsWith(MetricsHistogram.NINETY_FIFTH_PERCENTILE_METRIC_NAME)) {
            Snapshot s = hist.getSnapshot();
            return (float) s.get95thPercentile();
          } else if (name.endsWith(MetricsHistogram.NINETY_NINETH_PERCENTILE_METRIC_NAME)) {
            Snapshot s = hist.getSnapshot();
            return (float) s.get99thPercentile();
          }

        } else {
          LOG.warn( String.format("unknown metrics type %s for attribute %s",
                        metric.getClass().getName(), name) );
View Full Code Here

    return variance.get()[1] / (getCount() - 1);
  }

  @Override
  public void pushMetric(MetricsRecord mr) {
    final Snapshot s = this.getSnapshot();
    mr.setMetric(getName() + NUM_OPS_METRIC_NAME, this.getCount());
    mr.setMetric(getName() + MIN_METRIC_NAME, this.getMin());
    mr.setMetric(getName() + MAX_METRIC_NAME, this.getMax());

    mr.setMetric(getName() + MEAN_METRIC_NAME, (float) this.getMean());
    mr.setMetric(getName() + STD_DEV_METRIC_NAME, (float) this.getStdDev());

    mr.setMetric(getName() + MEDIAN_METRIC_NAME, (float) s.getMedian());
    mr.setMetric(getName() + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME,
        (float) s.get75thPercentile());
    mr.setMetric(getName() + NINETY_FIFTH_PERCENTILE_METRIC_NAME,
        (float) s.get95thPercentile());
    mr.setMetric(getName() + NINETY_NINETH_PERCENTILE_METRIC_NAME,
        (float) s.get99thPercentile());
  }
View Full Code Here

  public void testMetricsMBeanBaseHistogram()
      throws ReflectionException, AttributeNotFoundException, MBeanException {
    MetricsRegistry mr = new MetricsRegistry();
    MetricsHistogram histo = mock(MetricsHistogram.class);
    Snapshot snap = mock(Snapshot.class);

    //Set up the mocks
    String histoName = "MockHisto";
    when(histo.getName()).thenReturn(histoName);
    when(histo.getCount()).thenReturn(20l);
    when(histo.getMin()).thenReturn(1l);
    when(histo.getMax()).thenReturn(999l);
    when(histo.getMean()).thenReturn(500.2);
    when(histo.getStdDev()).thenReturn(1.2);
    when(histo.getSnapshot()).thenReturn(snap);

    when(snap.getMedian()).thenReturn(490.0);
    when(snap.get75thPercentile()).thenReturn(550.0);
    when(snap.get95thPercentile()).thenReturn(900.0);
    when(snap.get99thPercentile()).thenReturn(990.0);

    mr.add("myTestHisto", histo);

    MetricsMBeanBase mBeanBase = new MetricsMBeanBase(mr, "test");
View Full Code Here

      for (int i = 0; i < 1000; i++) {
          sample.update(i);
      }
      Assert.assertEquals(100, sample.size());
     
      final Snapshot snapshot = sample.getSnapshot();
      Assert.assertEquals(100, snapshot.size());

      for (double i : snapshot.getValues()) {
        Assert.assertTrue(i >= 0.0 && i < 1000.0);
      }
  }
View Full Code Here

      for (int i = 0; i < 10; i++) {
          sample.update(i);
      }
      Assert.assertEquals(10, sample.size());

      final Snapshot snapshot = sample.getSnapshot();
      Assert.assertEquals(10, sample.size());

      for (double i : snapshot.getValues()) {
        Assert.assertTrue(i >= 0.0 && i < 1000.0);
      }
  }
View Full Code Here

    for (int i = 0; i < data.length; i++) {
      data[i] = (long) (r.nextGaussian() * 10000.0);
      h.update(data[i]);
    }

    final Snapshot s = h.getSnapshot();
    Arrays.sort(data);

    // as long as the histogram chooses an item with index N+/-slop, accept it
    final int slop = 20;

    // make sure the median, 75th percentile and 95th percentile are good
    final int medianIndex = data.length / 2;
    final long minAcceptableMedian = data[safeIndex(medianIndex - slop,
        data.length)];
    final long maxAcceptableMedian = data[safeIndex(medianIndex + slop,
        data.length)];
    Assert.assertTrue(s.getMedian() >= minAcceptableMedian
        && s.getMedian() <= maxAcceptableMedian);

    final int seventyFifthIndex = (int) (data.length * 0.75);
    final long minAcceptableseventyFifth = data[safeIndex(seventyFifthIndex
        - slop, data.length)];
    final long maxAcceptableseventyFifth = data[safeIndex(seventyFifthIndex
        + slop, data.length)];
    Assert.assertTrue(s.get75thPercentile() >= minAcceptableseventyFifth
        && s.get75thPercentile() <= maxAcceptableseventyFifth);

    final int ninetyFifthIndex = (int) (data.length * 0.95);
    final long minAcceptableninetyFifth = data[safeIndex(ninetyFifthIndex
        - slop, data.length)];
    final long maxAcceptableninetyFifth = data[safeIndex(ninetyFifthIndex
        + slop, data.length)];
    Assert.assertTrue(s.get95thPercentile() >= minAcceptableninetyFifth
        && s.get95thPercentile() <= maxAcceptableninetyFifth);

  }
View Full Code Here

                    lastReportAt = complete;
                }
            }
            Futures.allAsList(inner).get();
        }
        Snapshot snap = BTREE_TIMER.getSnapshot();
        System.out.println(String.format("btree   : %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile()));
        snap = TREE_TIMER.getSnapshot();
        System.out.println(String.format("snaptree: %.2fns, %.2fns, %.2fns", snap.getMedian(), snap.get95thPercentile(), snap.get999thPercentile()));
        System.out.println("Done");
    }
View Full Code Here

  @Override
  public void snapshot(MetricsRecordBuilder metricsRecordBuilder, boolean all) {
    if (all || changed()) {
      clearChanged();
      final Snapshot s = sample.getSnapshot();
      metricsRecordBuilder.addCounter(Interns.info(name + NUM_OPS_METRIC_NAME, desc), count.get());

      metricsRecordBuilder.addGauge(Interns.info(name + MIN_METRIC_NAME, desc), getMin());
      metricsRecordBuilder.addGauge(Interns.info(name + MAX_METRIC_NAME, desc), getMax());
      metricsRecordBuilder.addGauge(Interns.info(name + MEAN_METRIC_NAME, desc), getMean());

      metricsRecordBuilder.addGauge(Interns.info(name + MEDIAN_METRIC_NAME, desc), s.getMedian());
      metricsRecordBuilder.addGauge(Interns.info(name + SEVENTY_FIFTH_PERCENTILE_METRIC_NAME, desc),
          s.get75thPercentile());
      metricsRecordBuilder.addGauge(Interns.info(name + NINETY_FIFTH_PERCENTILE_METRIC_NAME, desc),
          s.get95thPercentile());
      metricsRecordBuilder.addGauge(Interns.info(name + NINETY_NINETH_PERCENTILE_METRIC_NAME, desc),
          s.get99thPercentile());
    }
  }
View Full Code Here

        output = out;
    }

    public void run()
    {
        Snapshot latency;
        long oldLatency;
        int epoch, total, oldTotal, keyCount, oldKeyCount;

        // creating keyspace and column families
        if (client.getOperation() == Stress.Operations.INSERT || client.getOperation() == Stress.Operations.COUNTER_ADD)
            client.createKeySpaces();

        int threadCount = client.getThreads();
        Consumer[] consumers = new Consumer[threadCount];

        output.println("total,interval_op_rate,interval_key_rate,latency,95th,99th,elapsed_time");

        int itemsPerThread = client.getKeysPerThread();
        int modulo = client.getNumKeys() % threadCount;
        RateLimiter rateLimiter = RateLimiter.create(client.getMaxOpsPerSecond());

        // creating required type of the threads for the test
        for (int i = 0; i < threadCount; i++) {
            if (i == threadCount - 1)
                itemsPerThread += modulo; // last one is going to handle N + modulo items

            consumers[i] = new Consumer(itemsPerThread, rateLimiter);
        }

        Producer producer = new Producer();
        producer.start();

        // starting worker threads
        for (int i = 0; i < threadCount; i++)
            consumers[i].start();

        // initialization of the values
        boolean terminate = false;
        epoch = total = keyCount = 0;

        int interval = client.getProgressInterval();
        int epochIntervals = client.getProgressInterval() * 10;
        long testStartTime = System.nanoTime();
       
        StressStatistics stats = new StressStatistics(client, output);

        while (!terminate)
        {
            if (stop)
            {
                producer.stopProducer();

                for (Consumer consumer : consumers)
                    consumer.stopConsume();

                break;
            }

            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);

            int alive = 0;
            for (Thread thread : consumers)
                if (thread.isAlive()) alive++;

            if (alive == 0)
                terminate = true;

            epoch++;

            if (terminate || epoch > epochIntervals)
            {
                epoch = 0;

                oldTotal = total;
                oldKeyCount = keyCount;

                total = client.operations.get();
                keyCount = client.keys.get();
                latency = client.latency.getSnapshot();

                int opDelta = total - oldTotal;
                int keyDelta = keyCount - oldKeyCount;

                long currentTimeInSeconds = TimeUnit.NANOSECONDS.toSeconds(System.nanoTime() - testStartTime);

                output.println(String.format("%d,%d,%d,%.1f,%.1f,%.1f,%d",
                                             total,
                                             opDelta / interval,
                                             keyDelta / interval,
                                             latency.getMedian(), latency.get95thPercentile(), latency.get999thPercentile(),
                                             currentTimeInSeconds));

                if (client.outputStatistics()) {
                    stats.addIntervalStats(total,
                                           opDelta / interval,
View Full Code Here

TOP

Related Classes of com.yammer.metrics.stats.Snapshot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.