Java 类com.codahale.metrics.RatioGauge.Ratio 实例源码

项目:Camel    文件:Application.java   
@Produces
@Metric(name = "success-ratio")
// Register a custom gauge that's the ratio of the 'success' meter on the 'generated' meter
Gauge<Double> successRatio(Meter success, Meter generated) {
    return () -> Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate()).getValue();
}
项目:hbase    文件:TestMetricsConnection.java   
@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);
}
项目:camel-cdi    文件:Application.java   
@Produces
@Metric(name = "success-ratio")
Gauge<Double> successRatio(Meter generated, Meter success) {
    return () -> Ratio.of(success.getOneMinuteRate(), generated.getOneMinuteRate()).getValue();
}
项目:metrics-cdi    文件:MetricProducerMethodBeanJava8.java   
@Produces
@Metric(name = "cache-hits")
Gauge<Double> cacheHitRatioGauge(Meter hits, Timer calls) {
    return () -> Ratio.of(hits.getCount(), calls.getCount()).getValue();
}