本文整理汇总了Java中com.codahale.metrics.SharedMetricRegistries.getOrCreate方法的典型用法代码示例。如果您正苦于以下问题:Java SharedMetricRegistries.getOrCreate方法的具体用法?Java SharedMetricRegistries.getOrCreate怎么用?Java SharedMetricRegistries.getOrCreate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codahale.metrics.SharedMetricRegistries
的用法示例。
在下文中一共展示了SharedMetricRegistries.getOrCreate方法的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: 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);
}
示例3: 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);
}
示例4: 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));
}
示例5: 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);
}
示例6: 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);
}
示例7: 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));
}
示例8: 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!");
}
示例9: callExceptionMeteredStaticMethodsOnceWithoutThrowing
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Test
public void callExceptionMeteredStaticMethodsOnceWithoutThrowing() {
Runnable runnableThatDoesNoThrowExceptions = new Runnable() {
@Override
public void run() {
}
};
// Call the metered methods and assert they haven't been marked
MeteredStaticMethodWithExceptions.illegalArgumentExceptionMeteredStaticMethod(runnableThatDoesNoThrowExceptions);
MeteredStaticMethodWithExceptions.exceptionMeteredStaticMethod(runnableThatDoesNoThrowExceptions);
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())));
assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(0)).getCount(), is(equalTo(METER_COUNTS[0].get())));
assertThat("Meter count is incorrect", registry.getMeters().get(absoluteMetricName(1)).getCount(), is(equalTo(METER_COUNTS[1].get())));
}
示例10: resolveMetricRegistry
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Override
public MetricRegistry resolveMetricRegistry(String registry) {
Matcher matcher = EL_PATTERN.matcher(registry);
if (matcher.matches()) {
Object evaluation = processor.eval(matcher.group(1));
if (evaluation instanceof String)
return SharedMetricRegistries.getOrCreate((String) evaluation);
else if (evaluation instanceof MetricRegistry)
return (MetricRegistry) evaluation;
else
throw new IllegalStateException("Unable to resolve metrics registry from expression [" + registry + "]");
} else if (!matcher.find()) {
return SharedMetricRegistries.getOrCreate(registry);
} else {
return SharedMetricRegistries.getOrCreate(evaluateCompositeExpression(matcher));
}
}
示例11: callGaugesAfterSetterCalls
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Test
public void callGaugesAfterSetterCalls() {
assertThat("Shared metric registry is not created", SharedMetricRegistries.names(), hasItem(REGISTRY_NAME));
MetricRegistry registry = SharedMetricRegistries.getOrCreate(REGISTRY_NAME);
assertThat("Gauges are not registered correctly", registry.getGauges().keySet(), is(equalTo(absoluteMetricNames())));
long value = Math.round(Math.random() * Long.MAX_VALUE);
// Call the setter methods
instance.setPublicGauge(value);
instance.setPackagePrivateGauge(value);
instance.setProtectedGauge(value);
method("setPrivateGauge").withParameterTypes(long.class).in(instance).invoke(value);
// And assert the gauges are up-to-date
assertThat("Gauge values are incorrect", registry.getGauges().values(), everyItem(Matchers.<Gauge>hasProperty("value", equalTo(value))));
}
示例12: MetricHandler
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
/**
* Constructor
*
* @param store
* Metric store
*/
public MetricHandler(@Nonnull final MetricStore store) {
this.store = Objects.requireNonNull(store);
final MetricRegistry registry = SharedMetricRegistries
.getOrCreate("default");
this.metricMeter = registry
.meter(MetricRegistry.name(MetricHandler.class, "metric-rate"));
}
示例13: MetricStore
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
/**
* Constructor
*
* @param client
* Riak client
*/
public MetricStore(@Nonnull final RiakClient client) {
this.client = Objects.requireNonNull(client);
final MetricRegistry registry = SharedMetricRegistries
.getOrCreate("default");
this.queryTimer = registry
.timer(MetricRegistry.name(MetricStore.class, "query"));
this.storeTimer = registry
.timer(MetricRegistry.name(MetricStore.class, "store"));
this.deleteTimer = registry
.timer(MetricRegistry.name(MetricStore.class, "delete"));
}
示例14: getMetricRegistry
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
private MetricRegistry getMetricRegistry() {
MetricRegistry registry = environment.metrics();
if (registry == null) {
LOG.warn("No environment metrics found!");
registry = SharedMetricRegistries.getOrCreate("com.hubspot");
}
return registry;
}
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:11,代码来源:GuicePropertyFilteringMessageBodyWriter.java
示例15: setUp
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Before
public void setUp(TestContext context) {
String graphiteHost = System.getProperty("graphiteHost");
final String registryName = "okapi";
MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);
// Note the setEnabled (true or false)
DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions().
setEnabled(false).setRegistryName(registryName);
vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(metricsOpt));
reporter1 = ConsoleReporter.forRegistry(registry).build();
reporter1.start(1, TimeUnit.SECONDS);
if (graphiteHost != null) {
Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, 2003));
reporter2 = GraphiteReporter.forRegistry(registry)
.prefixedWith("okapiserver")
.build(graphite);
reporter2.start(1, TimeUnit.MILLISECONDS);
}
DeploymentOptions opt = new DeploymentOptions()
.setConfig(new JsonObject().put("port", Integer.toString(port)));
vertx.deployVerticle(MainVerticle.class.getName(),
opt, context.asyncAssertSuccess());
httpClient = vertx.createHttpClient();
}