本文整理汇总了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);
}
示例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"));
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
}
示例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();
}
示例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));
}
示例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))));
}
示例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!");
}
示例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!");
}
示例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!");
}