• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MetricsServlet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.prometheus.client.exporter.MetricsServlet的典型用法代码示例。如果您正苦于以下问题:Java MetricsServlet类的具体用法?Java MetricsServlet怎么用?Java MetricsServlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MetricsServlet类属于io.prometheus.client.exporter包,在下文中一共展示了MetricsServlet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testStarted

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public void testStarted() {
	// update the configuration
	this.reconfigure();
	this.server = new Server(this.getSaveConfig().getPort());

	ServletContextHandler context = new ServletContextHandler();
	context.setContextPath("/");
	server.setHandler(context);
	context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");

	try {
		server.start();
	} catch (Exception e) {
		log.error("Couldn't start http server", e);
	}

}
 
开发者ID:johrstrom,项目名称:jmeter-prometheus-plugin,代码行数:18,代码来源:PrometheusListener.java


示例2: run

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例3: run

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例4: run

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例5: PrometheusExporter

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public PrometheusExporter(int port, String path) {
    
    QueuedThreadPool threadPool = new QueuedThreadPool(25);
    server = new Server(threadPool);

    ServerConnector connector = new ServerConnector(server);
    connector.setPort(port);
    server.addConnector(connector);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);

    CollectorRegistry collectorRegistry = new CollectorRegistry();
    
    collectorRegistry.register(new PrometheusExports(CassandraMetricsRegistry.Metrics));

    MetricsServlet metricsServlet = new MetricsServlet(collectorRegistry);

    context.addServlet(new ServletHolder(metricsServlet), "/" + path);
    try {
        server.start();
    } catch (Exception e) {
        System.err.println("cannot start metrics http server " + e.getMessage());
    }
}
 
开发者ID:nabto,项目名称:cassandra-prometheus,代码行数:27,代码来源:PrometheusExporter.java


示例6: main

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public static void main( String[] args ) throws Exception {
    Server server = new Server(1234);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    // Expose our example servlet.
    context.addServlet(new ServletHolder(new ExampleServlet()), "/");
    // Expose Promtheus metrics.
    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,代码行数:18,代码来源:JavaSimple.java


示例7: main

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例8: main

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.err.println("Usage: WebServer <port> <yml configuration file>");
        System.exit(1);
    }

    configFilePath = args[1];
    CloudWatchCollector collector = new CloudWatchCollector(new FileReader(configFilePath)).register();

    ReloadSignalHandler.start(collector);

    int port = Integer.parseInt(args[0]);
    Server server = new Server(port);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    context.addServlet(new ServletHolder(new DynamicReloadServlet(collector)), "/-/reload");
    context.addServlet(new ServletHolder(new HomePageServlet()), "/");
    server.start();
    server.join();
}
 
开发者ID:prometheus,项目名称:cloudwatch_exporter,代码行数:23,代码来源:WebServer.java


示例9: contextInitialized

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent event) {
    // Uncomment the next line to enable the default hotspot events.
    // DefaultExports.initialize();

    metrics = new Metrics();
    ServletContext context = event.getServletContext();
    context.addServlet("Metrics", new MetricsServlet()).addMapping("");
}
 
开发者ID:RuntimeTools,项目名称:javametrics,代码行数:10,代码来源:MetricsContextListener.java


示例10: main

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (args.length < 0) {
        System.err.println("Usage: jar [host] [port] [exporter_port]");
        System.exit(1);
    }

    String host = "localhost";
    int port = 9990;
    if (args.length == 1) {
    	host = args[0];
    }
    if (args.length == 2) {
    	host = args[0];
    	port = Integer.parseInt(args[1]);
    }
    FinagleCollector collector = new FinagleCollector(host, port).register();
    
    int exporterPort = 9991;
    if (args.length == 3) {
    	host = args[0];
    	port = Integer.parseInt(args[1]);
    	exporterPort = Integer.parseInt(args[2]);
    }
    
    Server server = new Server(exporterPort);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/_metrics");
    context.addServlet(new ServletHolder(new HomePageServlet()), "/");
    server.start();
    server.join();
}
 
开发者ID:utkarshcmu,项目名称:finagle_exporter,代码行数:34,代码来源:WebServer.java


示例11: run

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例12: run

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例13: configure

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
WebServer configure(Config config, String address, int port) {
    // Metrics
    final FsImageCollector fsImageCollector = new FsImageCollector(config);
    fsImageCollector.register();

    new MemoryPoolsExports().register();

    final BuildInfoExporter buildInfo = new BuildInfoExporter("fsimage_exporter_",
            "fsimage_exporter").register();

    // Jetty
    InetSocketAddress inetAddress = new InetSocketAddress(address, port);
    server = new Server(inetAddress);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet(){
        @Override
        public void destroy() {
            super.destroy();
            fsImageCollector.shutdown();
        }
    }), "/metrics");
    context.addServlet(new ServletHolder(new HomePageServlet(config, buildInfo)), "/");

    return this;
}
 
开发者ID:marcelmay,项目名称:hadoop-hdfs-fsimage-exporter,代码行数:28,代码来源:WebServer.java


示例14: prometheusMetricsServletRegistrationBean

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "prometheusMetricsServletRegistrationBean")
ServletRegistrationBean prometheusMetricsServletRegistrationBean(@Value("${prometheus.metrics" +
        ".path:/metrics}") String metricsPath) {
    DefaultExports.initialize();
    return new ServletRegistrationBean(new MetricsServlet(), metricsPath);
}
 
开发者ID:microservices-demo,项目名称:shipping,代码行数:8,代码来源:PrometheusAutoConfiguration.java


示例15: onStartup

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例16: start

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
protected static void start(String[] args, String defaultStatsPort) throws Exception {
    // Register basic JVM metrics
    DefaultExports.initialize();

    // load aspectj-weaver agent for instrumentation
    AgentLoader.loadAgentClass(Agent.class.getName(), null);

    // Start Jetty to serve stats
    int port = Integer.parseInt(System.getProperties().getProperty("stats_server_port", defaultStatsPort));

    log.info("Starting ZK stats HTTP server at port {}", port);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", port);

    Server server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        log.error("Failed to start HTTP server at port {}. Use \"-Dstats_server_port=1234\" to change port number",
                port, e);
        throw e;
    }

    // Start the regular ZooKeeper server
    QuorumPeerMain.main(args);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:30,代码来源:ZooKeeperStarter.java


示例17: onStartup

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例18: testEnabled

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例19: createMetricsServlet

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的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


示例20: main

import io.prometheus.client.exporter.MetricsServlet; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  DefaultExports.initialize();
  Server server = new Server(1234);
  ServletContextHandler context = new ServletContextHandler();
  context.setContextPath("/");
  server.setHandler(context);
  context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
  server.start();
  server.join();
}
 
开发者ID:prometheus,项目名称:client_java,代码行数:11,代码来源:ExampleExporter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AnnotationConfigUtils类代码示例发布时间:2022-05-21
下一篇:
Java BlockStateMeta类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap