当前位置: 首页>>代码示例>>Java>>正文


Java SharedMetricRegistries类代码示例

本文整理汇总了Java中com.codahale.metrics.SharedMetricRegistries的典型用法代码示例。如果您正苦于以下问题:Java SharedMetricRegistries类的具体用法?Java SharedMetricRegistries怎么用?Java SharedMetricRegistries使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SharedMetricRegistries类属于com.codahale.metrics包,在下文中一共展示了SharedMetricRegistries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: config

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
public static void config(String graphiteHost, int port, TimeUnit tu,
        int period, VertxOptions vopt, String hostName) {
  final String registryName = "okapi";
  MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);

  DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions();
  metricsOpt.setEnabled(true).setRegistryName(registryName);
  vopt.setMetricsOptions(metricsOpt);
  Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, port));
  final String prefix = "folio.okapi." + hostName ;
  GraphiteReporter reporter = GraphiteReporter.forRegistry(registry)
          .prefixedWith(prefix)
          .build(graphite);
  reporter.start(period, tu);

  logger.info("Metrics remote:" + graphiteHost + ":"
          + port + " this:" + prefix);
}
 
开发者ID:folio-org,项目名称:okapi,代码行数:19,代码来源:DropwizardHelper.java

示例2: S3ProgressListener

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param key
 *            S3 key
 * @param start
 *            Start time in nanoseconds
 * @param count
 *            Number of events in the upload
 * @param size
 *            Size of the upload
 */
public S3ProgressListener(@Nonnull final String key, final long start,
        final int count, final int size) {
    this.key = Objects.requireNonNull(key);
    this.start = start;
    this.count = count;
    this.size = size;

    final MetricRegistry registry = SharedMetricRegistries.getDefault();
    this.uploadTime = registry
            .timer(name(S3ProgressListener.class, "upload-time"));
    this.successCounter = registry
            .counter(name(S3ProgressListener.class, "upload-success"));
    this.failedCounter = registry
            .counter(name(S3ProgressListener.class, "upload-failed"));
}
 
开发者ID:smoketurner,项目名称:uploader,代码行数:28,代码来源:S3ProgressListener.java

示例3: testMetricChange

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void testMetricChange() throws Exception {
    Metrics metrics = new Metrics();
    DropwizardReporter reporter = new DropwizardReporter();
    reporter.configure(new HashMap<String, Object>());
    metrics.addReporter(reporter);
    Sensor sensor = metrics.sensor("kafka.requests");
    sensor.add(new MetricName("pack.bean1.avg", "grp1"), new Avg());

    Map<String, Gauge> gauges = SharedMetricRegistries.getOrCreate("default").getGauges();
    String expectedName = "org.apache.kafka.common.metrics.grp1.pack.bean1.avg";
    Assert.assertEquals(1, gauges.size());
    Assert.assertEquals(expectedName, gauges.keySet().toArray()[0]);

    sensor.record(2.1);
    sensor.record(2.2);
    sensor.record(2.6);
    Assert.assertEquals(2.3, (Double)gauges.get(expectedName).getValue(), 0.001);
}
 
开发者ID:SimpleFinance,项目名称:kafka-dropwizard-reporter,代码行数:20,代码来源:DropwizardReporterTest.java

示例4: EventSchedulerService

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Inject
public EventSchedulerService(EventSchedulerDao eventSchedulerDao, EventSchedulerRegistry eventSchedulerRegistry,
                             @Named("eventScheduler.batchRead.intervalms") Integer batchReadInterval,
                             @Named("eventScheduler.batchRead.batchSize") Integer batchSize,
                             ObjectMapper objectMapper) {
    this.eventSchedulerDao = eventSchedulerDao;
    this.eventSchedulerRegistry = eventSchedulerRegistry;
    this.batchReadInterval = batchReadInterval;
    this.batchSize = batchSize;
    this.objectMapper = objectMapper;

    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    // remove the task from scheduler on cancel
    executor.setRemoveOnCancelPolicy(true);
    scheduledExecutorService =
            new InstrumentedScheduledExecutorService(Executors.unconfigurableScheduledExecutorService(executor),
                    SharedMetricRegistries.getOrCreate(METRIC_REGISTRY_NAME), scheduledExectorSvcName);
}
 
开发者ID:flipkart-incubator,项目名称:flux,代码行数:19,代码来源:EventSchedulerService.java

示例5: RedriverService

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Inject
public RedriverService(MessageManagerService messageService,
                       RedriverRegistry redriverRegistry,
                       @Named("redriver.batchRead.intervalms") Integer batchReadInterval,
                       @Named("redriver.batchRead.batchSize") Integer batchSize) {
    this.redriverRegistry = redriverRegistry;
    this.batchReadInterval = batchReadInterval;
    this.batchSize = batchSize;
    this.messageService = messageService;
    asyncRedriveService = Executors.newFixedThreadPool(10);

    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    // remove the task from scheduler on cancel
    executor.setRemoveOnCancelPolicy(true);
    scheduledExecutorService =
            new InstrumentedScheduledExecutorService(Executors.unconfigurableScheduledExecutorService(executor),
                    SharedMetricRegistries.getOrCreate(METRIC_REGISTRY_NAME), scheduledExectorSvcName);
}
 
开发者ID:flipkart-incubator,项目名称:flux,代码行数:19,代码来源:RedriverService.java

示例6: test_eventBus_GetVerticleDeployments

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void test_eventBus_GetVerticleDeployments() throws InterruptedException, ExecutionException, TimeoutException {
    log.info("test_eventBus_GetVerticleDeployments");
    final Vertx vertx = vertxService.getVertx();

    final RunRightFastVerticleId verticleManagerId = RunRightFastVerticleManager.VERTICLE_ID;
    final CompletableFuture<GetVerticleDeployments.Response> future = new CompletableFuture<>();
    final String address = EventBusAddress.eventBusAddress(verticleManagerId, "get-verticle-deployments");
    vertx.eventBus().send(
            address,
            GetVerticleDeployments.Request.newBuilder().build(),
            new DeliveryOptions().setSendTimeout(2000L),
            responseHandler(future, GetVerticleDeployments.Response.class)
    );
    final GetVerticleDeployments.Response result = future.get(2000L, TimeUnit.MILLISECONDS);
    assertThat(result.getDeploymentsCount(), is(2));

    final MetricRegistry metricRegistryTestVerticle1 = SharedMetricRegistries.getOrCreate(TestVerticle.VERTICLE_ID.toString());
    assertThat(metricRegistryTestVerticle1.getCounters().get(RunRightFastVerticleMetrics.Counters.INSTANCE_STARTED.metricName).getCount(), is(1L));

    final MetricRegistry metricRegistryTestVerticle2 = SharedMetricRegistries.getOrCreate(TestVerticle2.VERTICLE_ID.toString());
    assertThat(metricRegistryTestVerticle2.getCounters().get(RunRightFastVerticleMetrics.Counters.INSTANCE_STARTED.metricName).getCount(), is(5L));
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:24,代码来源:RunRightFastVertxApplicationTest.java

示例7: test_eventBus_GetVerticleDeployments_usingProtobufMessageProducer

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void test_eventBus_GetVerticleDeployments_usingProtobufMessageProducer() throws InterruptedException, ExecutionException, TimeoutException {
    log.info("test_eventBus_GetVerticleDeployments");
    final Vertx vertx = vertxService.getVertx();

    final RunRightFastVerticleId verticleManagerId = RunRightFastVerticleManager.VERTICLE_ID;
    final CompletableFuture future = new CompletableFuture();
    final String address = EventBusAddress.eventBusAddress(verticleManagerId, "get-verticle-deployments");

    final ProtobufMessageProducer producer = new ProtobufMessageProducer(
            vertx.eventBus(),
            address,
            getVerticleDeploymentsResponseCodec,
            SharedMetricRegistries.getOrCreate(getClass().getSimpleName())
    );
    producer.send(
            GetVerticleDeployments.Request.newBuilder().build(),
            new DeliveryOptions().setSendTimeout(2000L),
            responseHandler(future, GetVerticleDeployments.Response.class)
    );
    final Object result = future.get(2000L, TimeUnit.MILLISECONDS);
}
 
开发者ID:runrightfast,项目名称:runrightfast-vertx,代码行数:23,代码来源:RunRightFastVertxApplicationTest.java

示例8: forTestSetMetricsRegistryName

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@VisibleForTesting
@SuppressWarnings("unused")
public static void forTestSetMetricsRegistryName(String metricsRegistryName) {
  if (imStarted) {
    throw new IllegalStateException("Unit tests only!!!");
  }
  MetricRegistry metrics = SharedMetricRegistries.getOrCreate(metricsRegistryName);
  bambooReadTimer = new Timer();
  metrics.register("bambooReadTimer", bambooReadTimer);
  bambooParseTimer = new Timer();
  metrics.register("bambooParseTimer", bambooParseTimer);
  warcDocCountHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcDocCountHistogram", warcDocCountHistogram);
  warcSizeHistogram = new Histogram(new UniformReservoir());
  metrics.register("warcSizeHistogram", warcSizeHistogram);
}
 
开发者ID:nla,项目名称:bamboo,代码行数:17,代码来源:BaseWarcDomainManager.java

示例9: close

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Override
public void close() {
  if (shutdown) {
    RegistryHelper.shutdown(registry);
    if (options.getRegistryName() != null) {
      SharedMetricRegistries.remove(options.getRegistryName());
    }
  }
  List<HttpClientReporter> reporters;
  synchronized (this) {
    reporters = new ArrayList<>(clientReporters.values());
  }
  for (HttpClientReporter reporter : reporters) {
    reporter.close();
  }
  if (doneHandler != null) {
    doneHandler.handle(null);
  }
}
 
开发者ID:vert-x3,项目名称:vertx-dropwizard-metrics,代码行数:20,代码来源:VertxMetricsImpl.java

示例10: onPassivate

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Override
public void onPassivate( Application application )
{
    requestTimers.values().forEach( t -> t.stop() );
    requestTimers = null;
    reporters.forEach(
        r ->
        {
            if( r instanceof ScheduledReporter )
            {
                ( (ScheduledReporter) r ).stop();
            }
            else if( r instanceof JmxReporter )
            {
                ( (JmxReporter) r ).stop();
            }
        }
    );
    reporters = null;
    api = null;
    eventRegistration.unregister();
    eventRegistration = null;
    SharedMetricRegistries.clear();
    SharedHealthCheckRegistries.clear();
}
 
开发者ID:werval,项目名称:werval,代码行数:26,代码来源:MetricsPlugin.java

示例11: testConnectionLife

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void testConnectionLife() throws SQLException {
    // Act
    Connection connection = DriverManager.getConnection(URL + ";metrics_registry=life", H2DbUtil.USERNAME, H2DbUtil.PASSWORD);
    Statement statement = connection.createStatement();
    H2DbUtil.close(statement, connection);
    // Assert
    assertNotNull(connection);
    assertTrue(Proxy.isProxyClass(connection.getClass()));
    MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate("life");
    Timer lifeTimer = metricRegistry.timer("java.sql.Connection");
    assertNotNull(lifeTimer);
    assertThat(lifeTimer.getCount(), equalTo(1L));
    Timer getTimer = metricRegistry.timer("java.sql.Connection.get");
    assertNotNull(getTimer);
    assertThat(getTimer.getCount(), equalTo(1L));
}
 
开发者ID:gquintana,项目名称:metrics-sql,代码行数:18,代码来源:DriverTest.java

示例12: callExceptionMeteredMethodsOnceWithoutThrowing

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void callExceptionMeteredMethodsOnceWithoutThrowing() {
    assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);
    assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames())));

    Runnable runnableThatDoesNoThrowExceptions = new Runnable() {
        @Override
        public void run() {
        }
    };

    // Call the metered methods and assert they haven't been marked
    instance.illegalArgumentExceptionMeteredMethod(runnableThatDoesNoThrowExceptions);
    instance.exceptionMeteredMethod(runnableThatDoesNoThrowExceptions);
    assertThat("Meter counts are incorrect", registry.getMeters().values(), everyItem(Matchers.<Meter>hasProperty("count", equalTo(0L))));
}
 
开发者ID:astefanutti,项目名称:metrics-aspectj,代码行数:18,代码来源:MeteredMethodWithExceptionsTest.java

示例13: callExceptionMeteredMethodOnceWithThrowingExpectedException

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void callExceptionMeteredMethodOnceWithThrowingExpectedException() {
    assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);
    assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames())));

    final RuntimeException exception = new IllegalArgumentException("message");
    Runnable runnableThatThrowsIllegalArgumentException = new Runnable() {
        @Override
        public void run() {
            throw exception;
        }
    };

    // Call the metered method and assert it's been marked and that the original exception has been rethrown
    try {
        instance.illegalArgumentExceptionMeteredMethod(runnableThatThrowsIllegalArgumentException);
    } catch (RuntimeException cause) {
        assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(1L)));
        assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(0L)));
        assertSame("Exception thrown is incorrect", cause, exception);
        return;
    }

    fail("No exception has been re-thrown!");
}
 
开发者ID:astefanutti,项目名称:metrics-aspectj,代码行数:27,代码来源:MeteredMethodWithExceptionsTest.java

示例14: callExceptionMeteredMethodOnceWithThrowingNonExpectedException

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void callExceptionMeteredMethodOnceWithThrowingNonExpectedException() {
    assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);
    assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames())));

    final RuntimeException exception = new IllegalStateException("message");
    Runnable runnableThatThrowsIllegalStateException = new Runnable() {
        @Override
        public void run() {
            throw exception;
        }
    };

    // Call the metered method and assert it hasn't been marked and that the original exception has been rethrown
    try {
        instance.illegalArgumentExceptionMeteredMethod(runnableThatThrowsIllegalStateException);
    } catch (RuntimeException cause) {
        assertThat("Meter counts are incorrect", registry.getMeters().values(), everyItem(Matchers.<Meter>hasProperty("count", equalTo(0L))));
        assertSame("Exception thrown is incorrect", cause, exception);
        return;
    }

    fail("No exception has been re-thrown!");
}
 
开发者ID:astefanutti,项目名称:metrics-aspectj,代码行数:26,代码来源:MeteredMethodWithExceptionsTest.java

示例15: callExceptionMeteredMethodOnceWithThrowingInstanceOfExpectedException

import com.codahale.metrics.SharedMetricRegistries; //导入依赖的package包/类
@Test
public void callExceptionMeteredMethodOnceWithThrowingInstanceOfExpectedException() {
    assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME));
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);
    assertThat("Meters are not registered correctly", registry.getMeters().keySet(), is(equalTo(absoluteMetricNames())));

    final RuntimeException exception = new IllegalStateException("message");
    Runnable runnableThatThrowsIllegalStateException = new Runnable() {
        @Override
        public void run() {
            throw exception;
        }
    };

    // Call the metered method and assert it's been marked and that the original exception has been rethrown
    try {
        instance.exceptionMeteredMethod(runnableThatThrowsIllegalStateException);
    } catch (RuntimeException cause) {
        assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(0L)));
        assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(1L)));
        assertSame("Exception thrown is incorrect", cause, exception);
        return;
    }

    fail("No exception has been re-thrown!");
}
 
开发者ID:astefanutti,项目名称:metrics-aspectj,代码行数:27,代码来源:MeteredMethodWithExceptionsTest.java


注:本文中的com.codahale.metrics.SharedMetricRegistries类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。