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


Java DropwizardExports类代码示例

本文整理汇总了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);
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:34,代码来源:WorkerServiceApplication.java

示例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");
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:20,代码来源:HelloWorldMonolithApp.java

示例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");
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:31,代码来源:TweetsServiceApplication.java

示例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();
}
 
开发者ID:RobustPerception,项目名称:java_examples,代码行数:22,代码来源:JavaDropwizard.java

示例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);
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:29,代码来源:SearchServiceApplication.java

示例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);
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:37,代码来源:IndexerServiceApplication.java

示例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);
    }
}
 
开发者ID:Dualion,项目名称:jhipster-ng-admin,代码行数:13,代码来源:MetricsConfiguration.java

示例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));
}
 
开发者ID:graknlabs,项目名称:grakn,代码行数:33,代码来源:SystemController.java

示例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);
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:19,代码来源:Metrics.java

示例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);
    }
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:13,代码来源:PrometheusRegistry.java

示例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);
}
 
开发者ID:jhipster,项目名称:jhipster,代码行数:29,代码来源:PrometheusRegistryTest.java

示例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);
    }
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:15,代码来源:MetricsConfig.java


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