本文整理汇总了Java中com.codahale.metrics.SharedMetricRegistries.add方法的典型用法代码示例。如果您正苦于以下问题:Java SharedMetricRegistries.add方法的具体用法?Java SharedMetricRegistries.add怎么用?Java SharedMetricRegistries.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.codahale.metrics.SharedMetricRegistries
的用法示例。
在下文中一共展示了SharedMetricRegistries.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: vertxMetricsOptions
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Bean
@ConditionalOnProperty(prefix = "hono.metric", name = "vertx", havingValue = "true")
public MetricsOptions vertxMetricsOptions() {
LOG.info("metrics - vertx activated");
SharedMetricRegistries.add(HONO, metricRegistry);
SharedMetricRegistries.setDefault(HONO, metricRegistry);
return new DropwizardMetricsOptions().setEnabled(true).setRegistryName(HONO)
.setBaseName(prefix + ".vertx").setJmxEnabled(true);
}
示例2: run
import com.codahale.metrics.SharedMetricRegistries; //导入方法依赖的package包/类
@Override
public void run(final DropwizardReporterExampleConfiguration configuration,
final Environment environment) {
// The default shared registry will be pre-registered in Dropwizard 1.0+
SharedMetricRegistries.add("default", environment.metrics());
final ExecutorService executorService = environment
.lifecycle()
.executorService("kafka-threads")
.minThreads(2)
.maxThreads(10)
.build();
executorService.execute(new Runnable() {
@Override
public void run() {
final Producer<String, String> producer = new KafkaProducer<>(configuration.getProducer());
int i = 0;
try {
while (true) {
String s = Integer.toString(i);
producer.send(new ProducerRecord<String, String>("my-topic", s, s));
i++;
Thread.sleep(500);
}
} catch (InterruptedException e) {
LOGGER.info("Producer interrupted");
producer.close();
}
}
});
executorService.execute(new Runnable() {
@Override
public void run() {
final Consumer<String, String> consumer = new KafkaConsumer<>(configuration.getConsumer());
consumer.subscribe(Arrays.asList("my-topic"));
while (true) {
ConsumerRecords<String, String> records = consumer.poll(2000);
for (ConsumerRecord<String, String> record : records)
LOGGER.info("offset = {}, key = {}, value = {}", record.offset(), record.key(), record.value());
}
}
});
}
开发者ID:SimpleFinance,项目名称:kafka-dropwizard-reporter,代码行数:48,代码来源:DropwizardReporterExampleApplication.java