001package io.prometheus.metrics.exporter.httpserver;
002
003import com.sun.net.httpserver.HttpExchange;
004import com.sun.net.httpserver.HttpHandler;
005import io.prometheus.metrics.config.PrometheusProperties;
006import io.prometheus.metrics.exporter.common.PrometheusScrapeHandler;
007import io.prometheus.metrics.model.registry.PrometheusRegistry;
008import java.io.IOException;
009
010/** Handler for the /metrics endpoint */
011public class MetricsHandler implements HttpHandler {
012
013  private final PrometheusScrapeHandler prometheusScrapeHandler;
014
015  public MetricsHandler() {
016    prometheusScrapeHandler = new PrometheusScrapeHandler();
017  }
018
019  public MetricsHandler(PrometheusRegistry registry) {
020    prometheusScrapeHandler = new PrometheusScrapeHandler(registry);
021  }
022
023  public MetricsHandler(PrometheusProperties config) {
024    prometheusScrapeHandler = new PrometheusScrapeHandler(config);
025  }
026
027  public MetricsHandler(PrometheusProperties config, PrometheusRegistry registry) {
028    prometheusScrapeHandler = new PrometheusScrapeHandler(config, registry);
029  }
030
031  @Override
032  public void handle(HttpExchange t) throws IOException {
033    prometheusScrapeHandler.handleRequest(new HttpExchangeAdapter(t));
034  }
035}