本文整理汇总了Java中io.prometheus.client.exporter.MetricsServlet类的典型用法代码示例。如果您正苦于以下问题:Java MetricsServlet类的具体用法?Java MetricsServlet怎么用?Java MetricsServlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MetricsServlet类属于io.prometheus.client.exporter包,在下文中一共展示了MetricsServlet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
示例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");
}
示例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");
}
示例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());
}
}
示例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();
}
示例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();
}
示例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();
}
示例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("");
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}