com.codahale.metrics.RatioGauge Java Examples

The following examples show how to use com.codahale.metrics.RatioGauge. 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 File: PoolMetricsImpl.java    From vertx-dropwizard-metrics with Apache License 2.0 6 votes vote down vote up
public PoolMetricsImpl(MetricRegistry registry, String baseName, int maxSize) {
  super(registry, baseName);
  this.queueSize = counter("queue-size");
  this.queueDelay = timer("queue-delay");
  this.usage = timer("usage");
  this.inUse = counter("in-use");
  if (maxSize > 0) {
    RatioGauge gauge = new RatioGauge() {
      @Override
      protected Ratio getRatio() {
        return Ratio.of(inUse.getCount(), maxSize);
      }
    };
    gauge(gauge, "pool-ratio");
    gauge(() -> maxSize, "max-pool-size");
  }
}
 
Example #2
Source File: TestIrisMetrics.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleRatio() throws Exception {
   final IrisMetricSet MS = IrisMetrics.metrics(TestIrisMetrics.class, "test-ratio");
   RatioGauge ratio1 = MS.ratio1("test1", MS.meter(), MS.meter());
   assertNotNull(ratio1);

   RatioGauge ratio5 = MS.ratio5("test5", MS.meter(), MS.meter());
   assertNotNull(ratio5);

   RatioGauge ratio15 = MS.ratio15("test15", MS.meter(), MS.meter());
   assertNotNull(ratio15);
}
 
Example #3
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio1(Metered numerator, Metered denominator) {
   Preconditions.checkNotNull(numerator, "Numerator cannot be null.");
   Preconditions.checkNotNull(denominator, "Denominator cannot be null.");
   return new MeteredRatio1(numerator, denominator);
}
 
Example #4
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio5(Metered numerator, Metered denominator) {
   Preconditions.checkNotNull(numerator, "Numerator cannot be null.");
   Preconditions.checkNotNull(denominator, "Denominator cannot be null.");
   return new MeteredRatio5(numerator, denominator);
}
 
Example #5
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio15(Metered numerator, Metered denominator) {
   Preconditions.checkNotNull(numerator, "Numerator cannot be null.");
   Preconditions.checkNotNull(denominator, "Denominator cannot be null.");
   return new MeteredRatio15(numerator, denominator);
}
 
Example #6
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio(String name, RatioGauge gauge) {
   return register(name, gauge);
}
 
Example #7
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio1(String name, Metered numerator, Metered denominator) {
   return register(name, ratio1(numerator, denominator));
}
 
Example #8
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio5(String name, Metered numerator, Metered denominator) {
   return register(name, ratio5(numerator, denominator));
}
 
Example #9
Source File: IrisMetricSet.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
public RatioGauge ratio15(String name, Metered numerator, Metered denominator) {
   return register(name, ratio15(numerator, denominator));
}
 
Example #10
Source File: TestMetricsConnection.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testStaticMetrics() throws IOException {
  final byte[] foo = Bytes.toBytes("foo");
  final RegionSpecifier region = RegionSpecifier.newBuilder()
      .setValue(ByteString.EMPTY)
      .setType(RegionSpecifierType.REGION_NAME)
      .build();
  final int loop = 5;

  for (int i = 0; i < loop; i++) {
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Get"),
        GetRequest.getDefaultInstance(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Scan"),
        ScanRequest.getDefaultInstance(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Multi"),
        MultiRequest.getDefaultInstance(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Mutate"),
        MutateRequest.newBuilder()
            .setMutation(ProtobufUtil.toMutation(MutationType.APPEND, new Append(foo)))
            .setRegion(region)
            .build(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Mutate"),
        MutateRequest.newBuilder()
            .setMutation(ProtobufUtil.toMutation(MutationType.DELETE, new Delete(foo)))
            .setRegion(region)
            .build(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Mutate"),
        MutateRequest.newBuilder()
            .setMutation(ProtobufUtil.toMutation(MutationType.INCREMENT, new Increment(foo)))
            .setRegion(region)
            .build(),
        MetricsConnection.newCallStats());
    METRICS.updateRpc(
        ClientService.getDescriptor().findMethodByName("Mutate"),
        MutateRequest.newBuilder()
            .setMutation(ProtobufUtil.toMutation(MutationType.PUT, new Put(foo)))
            .setRegion(region)
            .build(),
        MetricsConnection.newCallStats());
  }
  for (MetricsConnection.CallTracker t : new MetricsConnection.CallTracker[] {
    METRICS.getTracker, METRICS.scanTracker, METRICS.multiTracker, METRICS.appendTracker,
    METRICS.deleteTracker, METRICS.incrementTracker, METRICS.putTracker
  }) {
    assertEquals("Failed to invoke callTimer on " + t, loop, t.callTimer.getCount());
    assertEquals("Failed to invoke reqHist on " + t, loop, t.reqHist.getCount());
    assertEquals("Failed to invoke respHist on " + t, loop, t.respHist.getCount());
  }
  RatioGauge executorMetrics = (RatioGauge) METRICS.getMetricRegistry()
          .getMetrics().get(METRICS.getExecutorPoolName());
  RatioGauge metaMetrics = (RatioGauge) METRICS.getMetricRegistry()
          .getMetrics().get(METRICS.getMetaPoolName());
  assertEquals(Ratio.of(0, 3).getValue(), executorMetrics.getValue(), 0);
  assertEquals(Double.NaN, metaMetrics.getValue(), 0);
}
 
Example #11
Source File: InstrumentedThreadPoolExecutor.java    From monasca-common with Apache License 2.0 4 votes vote down vote up
InstrumentedThreadPoolExecutor(MetricRegistry metricRegistry, String name, int corePoolSize,
    int maximumPoolSize, long keepAliveTime, TimeUnit unit,
    final BlockingQueue<Runnable> workQueue, ThreadFactory factory) {
  super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, factory);
  this.name = name;
  requestRate = metricRegistry.meter(MetricRegistry.name(getClass(), name, "request"));
  rejectedRate = metricRegistry.meter(MetricRegistry.name(getClass(), name, "rejected"));
  executionTimer = metricRegistry.timer(MetricRegistry.name(getClass(), name, "execution"));
  metricRegistry.register(MetricRegistry.name(getClass(), name, "queue.size"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getQueue().size();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.count"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getPoolSize();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.active"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getActiveCount();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.idle"),
      new Gauge<Integer>() {
        @Override
        public Integer getValue() {
          return getPoolSize() - getActiveCount();
        }
      });
  metricRegistry.register(MetricRegistry.name(getClass(), name, "threads.percent-active"),
      new RatioGauge() {
        @Override
        protected Ratio getRatio() {
          return Ratio.of(getPoolSize(), getActiveCount());
        }
      });

  setRejectedExecutionHandler(new RejectedExecutionHandler() {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
      rejectedRate.mark();
      if (!workQueue.offer(r))
        log.warn("Thread pool {} rejected work.", InstrumentedThreadPoolExecutor.this.name);
      throw new RejectedExecutionException();
    }
  });
}