本文整理汇总了Java中io.prometheus.client.dropwizard.DropwizardExports类的典型用法代码示例。如果您正苦于以下问题:Java DropwizardExports类的具体用法?Java DropwizardExports怎么用?Java DropwizardExports使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DropwizardExports类属于io.prometheus.client.dropwizard包,在下文中一共展示了DropwizardExports类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) throws Exception {
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
environment.jersey().register(tracing);
final Properties producerConfigs = new Properties();
producerConfigs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "tweets-kafka:9092");
producerConfigs.put(ProducerConfig.ACKS_CONFIG, "all");
producerConfigs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
final KafkaProducer<Long, String> kafkaProducer =
new KafkaProducer<>(producerConfigs, new LongSerializer(), new StringSerializer());
final Producer<Long, String> tracingKafkaProducer =
new TracingKafkaProducer<>(kafkaProducer, metricsTracer);
final ObjectMapper objectMapper = environment.getObjectMapper();
final TweetEventRepository tweetRepository = new KafkaTweetEventRepository(tracingKafkaProducer, objectMapper);
final TweetsService tweetsService = new TweetsService(tweetRepository);
final TweetsResource tweetsResource = new TweetsResource(tweetsService);
environment.jersey().register(tweetsResource);
}
示例2: run
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
// Preparing Translation Service
final TranslationService translationService = new TranslationService();
// Preparing Greeting Service and inject Translation
final GreetingResource greetingService = new GreetingResource(translationService);
// Register Greeting Service
environment.jersey().register(greetingService);
// Add Metrics Instrumentation to count requests
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
// Register Metrics Servlet
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
}
示例3: run
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) {
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
final PrometheusMetricsReporter reporter =
PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final String jdbcUrl = "jdbc:tracing:postgresql://tweets-db/postgres";
final String jdbcUsername = "postgres";
final String jdbcPassword = "example";
final TweetsRepository tweetsRepository = new JooqPostgresTweetsRepository(jdbcUrl, jdbcUsername, jdbcPassword);
final TweetsService tweetsService = new TweetsService(tweetsRepository);
final TweetsResource tweetsResource = new TweetsResource(tweetsService);
environment.jersey().register(tweetsResource);
final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
environment.jersey().register(tracing);
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
}
示例4: main
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public static void main( String[] args ) throws Exception {
// Increment the counter.
counter.inc();
// Hook the Dropwizard registry into the Prometheus registry
// via the DropwizardExports collector.
CollectorRegistry.defaultRegistry.register(new DropwizardExports(metrics));
// Expose Prometheus metrics.
Server server = new Server(1234);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
// Add metrics about CPU, JVM memory etc.
DefaultExports.initialize();
// Start the webserver.
server.start();
server.join();
}
示例5: configure
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Override
protected void configure() {
addConfigBeans();
bind(DropwizardExports.class).toProvider(DropwizardExportsProvider.class);
bind(CollectorRegistry.class).toProvider(CollectorRegistryProvider.class);
bind(PushGateway.class).toProvider(PushGatewayProvider.class);
addPeriodical(PushGatewayPeriodical.class);
addRestResource(MetricsResource.class);
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:12,代码来源:MetricsPrometheusReporterModule.java
示例6: run
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) throws Exception {
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
environment.jersey().register(tracing);
final HttpHost httpHost = new HttpHost("tweets-elasticsearch", 9200);
final RestClientBuilder restClientBuilder =
RestClient.builder(httpHost).setHttpClientConfigCallback(new TracingHttpClientConfigCallback(metricsTracer));
final RestClient restClient = restClientBuilder.build();
final RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClient);
final TweetRepository tweetRepository = new ElasticsearchTweetRepository(restHighLevelClient);
final TweetsResource tweetsResource = new TweetsResource(tweetRepository);
environment.jersey().register(tweetsResource);
}
示例7: run
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) throws Exception {
// INSTRUMENTATION
// Metrics Instrumentation
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
// Tracing Instrumentation
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final HttpHost httpHost = new HttpHost("tweets-elasticsearch", 9200);
final RestClientBuilder restClientBuilder =
RestClient.builder(httpHost).setHttpClientConfigCallback(new TracingHttpClientConfigCallback(metricsTracer));
final RestClient restClient = restClientBuilder.build();
final ElasticsearchTweetRepository elasticsearchRepository = new ElasticsearchTweetRepository(restClient);
final Properties consumerConfigs = new Properties();
consumerConfigs.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "tweets-kafka:9092");
consumerConfigs.put(ConsumerConfig.GROUP_ID_CONFIG, getName());
consumerConfigs.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
consumerConfigs.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
final KafkaConsumer<Long, String> kafkaConsumer = new KafkaConsumer<>(consumerConfigs, new LongDeserializer(), new StringDeserializer());
final TracingKafkaConsumer<Long, String> tracingKafkaConsumer = new TracingKafkaConsumer<>(kafkaConsumer, metricsTracer);
final Runnable kafkaTweetEventConsumer = new KafkaTweetEventConsumer(tracingKafkaConsumer, elasticsearchRepository);
final ExecutorService executorService = environment.lifecycle().executorService("kafka-consumer").build();
executorService.submit(kafkaTweetEventConsumer);
}
示例8: onStartup
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
if(jHipsterProperties.getMetrics().getPrometheus().isEnabled()) {
String endpoint = jHipsterProperties.getMetrics().getPrometheus().getEndpoint();
log.info("Initializing Metrics Prometheus endpoint at {}", endpoint);
CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(metricRegistry));
servletContext
.addServlet("prometheusMetrics", new MetricsServlet(collectorRegistry))
.addMapping(endpoint);
}
}
示例9: SystemController
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
public SystemController(Service spark, GraknConfig config, SystemKeyspace systemKeyspace,
GraknEngineStatus graknEngineStatus, MetricRegistry metricRegistry) {
this.systemKeyspace = systemKeyspace;
this.config = config;
this.graknEngineStatus = graknEngineStatus;
this.metricRegistry = metricRegistry;
DropwizardExports prometheusMetricWrapper = new DropwizardExports(metricRegistry);
this.prometheusRegistry = new CollectorRegistry();
prometheusRegistry.register(prometheusMetricWrapper);
spark.get(REST.WebPath.ROOT, this::getRoot);
spark.get(REST.WebPath.KB, (req, res) -> getKeyspaces(res));
spark.get(REST.WebPath.KB_KEYSPACE, this::getKeyspace);
spark.put(REST.WebPath.KB_KEYSPACE, this::putKeyspace);
spark.delete(REST.WebPath.KB_KEYSPACE, this::deleteKeyspace);
spark.get(REST.WebPath.METRICS, this::getMetrics);
spark.get(REST.WebPath.STATUS, (req, res) -> getStatus());
spark.get(REST.WebPath.VERSION, (req, res) -> getVersion());
final TimeUnit rateUnit = TimeUnit.SECONDS;
final TimeUnit durationUnit = TimeUnit.SECONDS;
final boolean showSamples = false;
MetricFilter filter = MetricFilter.ALL;
this.mapper = new ObjectMapper().registerModule(
new MetricsModule(rateUnit,
durationUnit,
showSamples,
filter));
}
示例10: configureMetricsEndpoints
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
/**
* Appends endpoint servlets to the provided {@code context} which will serve codahale-style and prometheus-style
* metrics.
*/
public static void configureMetricsEndpoints(
ServletContextHandler context, String codahaleMetricsEndpoint, String prometheusEndpoint) {
// Metrics
ServletHolder codahaleMetricsServlet = new ServletHolder("default",
new com.codahale.metrics.servlets.MetricsServlet(metrics));
context.addServlet(codahaleMetricsServlet, codahaleMetricsEndpoint);
// Prometheus
CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(metrics));
ServletHolder prometheusServlet = new ServletHolder("prometheus",
new io.prometheus.client.exporter.MetricsServlet(collectorRegistry));
context.addServlet(prometheusServlet, prometheusEndpoint);
}
示例11: getReturnsDropwizardExportsWithDropwizardMetrics
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Test
public void getReturnsDropwizardExportsWithDropwizardMetrics() throws Exception {
final MetricRegistry registry = new MetricRegistry();
registry.histogram("test.histogram");
final DropwizardExports dropwizardExports = new DropwizardExports(registry);
final List<Collector.MetricFamilySamples> samples = dropwizardExports.collect();
assertEquals(1, samples.size());
final Collector.MetricFamilySamples element = samples.get(0);
assertEquals("test_histogram", element.name);
assertEquals(Collector.Type.SUMMARY, element.type);
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:13,代码来源:DropwizardExportsProviderTest.java
示例12: getReturnsCollectorRegistryWithDropwizardMetrics
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Test
public void getReturnsCollectorRegistryWithDropwizardMetrics() throws Exception {
final MetricRegistry registry = new MetricRegistry();
final Counter counter = registry.counter("test.counter");
counter.inc(42L);
final DropwizardExports dropwizardExports = new DropwizardExports(registry);
final CollectorRegistryProvider provider = new CollectorRegistryProvider(dropwizardExports);
final CollectorRegistry collectorRegistry = provider.get();
assertEquals(new Double(42.0d), collectorRegistry.getSampleValue("test_counter"));
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:12,代码来源:CollectorRegistryProviderTest.java
示例13: onStartup
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
if (jHipsterProperties.getMetrics().getPrometheus().isEnabled()) {
String endpoint = jHipsterProperties.getMetrics().getPrometheus().getEndpoint();
log.info(INITIALIZING_MESSAGE, endpoint);
CollectorRegistry collectorRegistry = getCollector();
collectorRegistry.register(new DropwizardExports(metricRegistry));
servletContext
.addServlet(SERVLET_NAME, new MetricsServlet(collectorRegistry))
.addMapping(endpoint);
}
}
示例14: testEnabled
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
@Test
public void testEnabled() {
PrometheusRegistry prometheus = spy(new PrometheusRegistry(registry, properties));
CollectorRegistry collector = spy(prometheus.getCollector());
when(prometheus.getCollector()).thenReturn(collector);
Dynamic dynamic = spy(Dynamic.class);
MockServletContext context = spy(new MockServletContext() {
@Override
public Dynamic addServlet(String name, Servlet servlet) {
return dynamic;
}
});
Throwable caught = catchThrowable(() -> prometheus.onStartup(context));
assertThat(caught).isNull();
verify(collector).register(isA(DropwizardExports.class));
verify(context).addServlet(eq(PrometheusRegistry.SERVLET_NAME), isA(MetricsServlet.class));
verify(dynamic).addMapping(METRICS_ENDPOINT);
List<Event> events = recorder.play();
assertThat(events).hasSize(1);
Event event = events.get(0);
assertThat(event.getLevel()).isEqualTo("INFO");
assertThat(event.getMessage()).isEqualTo(PrometheusRegistry.INITIALIZING_MESSAGE);
}
示例15: createMetricsServlet
import io.prometheus.client.dropwizard.DropwizardExports; //导入依赖的package包/类
private MetricsServlet createMetricsServlet(PublicMetrics publicMetrics) {
CollectorRegistry collectorRegistry = CollectorRegistry.defaultRegistry;
MetricRegistry metricRegistry = new MetricRegistry();
for (Metric<?> metric : publicMetrics.metrics()) {
Counter counter = metricRegistry.counter(metric.getName());
counter.dec(counter.getCount());
counter.inc(Double.valueOf(metric.getValue().toString()).longValue());
}
DropwizardExports dropwizardExports = new DropwizardExports(metricRegistry);
// List<Collector.MetricFamilySamples> metricFamilySamples = dropwizardExports.collect();
collectorRegistry.register(dropwizardExports);
return new MetricsServlet(collectorRegistry);
}