Search in sources :

Example 1 with PrometheusMetricsProvider

use of org.apache.bookkeeper.stats.prometheus.PrometheusMetricsProvider in project herddb by diennea.

the class ServerMain method start.

public void start() throws Exception {
    pidFileLocker.lock();
    PrometheusMetricsProvider statsProvider = new PrometheusMetricsProvider();
    PropertiesConfiguration statsProviderConfig = new PropertiesConfiguration();
    statsProviderConfig.setProperty(PrometheusMetricsProvider.PROMETHEUS_STATS_HTTP_ENABLE, false);
    configuration.forEach((key, value) -> {
        statsProviderConfig.setProperty(key + "", value);
    });
    statsProvider.start(statsProviderConfig);
    ServerConfiguration config = new ServerConfiguration(this.configuration);
    StatsLogger statsLogger = statsProvider.getStatsLogger("");
    server = new Server(config, statsLogger);
    server.start();
    boolean httpEnabled = config.getBoolean("http.enable", true);
    if (httpEnabled) {
        String httphost = config.getString("http.host", server.getNetworkServer().getHost());
        String httpadvertisedhost = config.getString("http.advertised.host", server.getServerHostData().getHost());
        int httpport = config.getInt("http.port", 9845);
        int httpadvertisedport = config.getInt("http.advertised.port", httpport);
        httpserver = new org.eclipse.jetty.server.Server(new InetSocketAddress(httphost, httpport));
        ContextHandlerCollection contexts = new ContextHandlerCollection();
        httpserver.setHandler(contexts);
        ServletContextHandler contextRoot = new ServletContextHandler(ServletContextHandler.GZIP);
        contextRoot.setContextPath("/");
        contextRoot.addServlet(new ServletHolder(new PrometheusServlet(statsProvider)), "/metrics");
        contexts.addHandler(contextRoot);
        File webUi = new File("web/ui");
        if (webUi.isDirectory()) {
            WebAppContext webApp = new WebAppContext(new File("web/ui").getAbsolutePath(), "/ui");
            contexts.addHandler(webApp);
        } else {
            LOGGER.info("Cannot find " + webUi.getAbsolutePath() + " directory. Web UI will not be deployed");
        }
        uiurl = "http://" + httpadvertisedhost + ":" + httpadvertisedport + "/ui/#/login?url=" + server.getJdbcUrl();
        metricsUrl = "http://" + httpadvertisedhost + ":" + httpadvertisedport + "/metrics";
        LOGGER.info("Listening for client (http) connections on " + httphost + ":" + httpport);
        httpserver.start();
    }
    LOGGER.info("HerdDB server starter. Node id " + server.getNodeId());
    LOGGER.info("JDBC URL: " + server.getJdbcUrl());
    LOGGER.info("Web Interface: " + uiurl);
    LOGGER.info("Metrics: " + metricsUrl);
    started = true;
}
Also used : StatsLogger(org.apache.bookkeeper.stats.StatsLogger) PrometheusServlet(org.apache.bookkeeper.stats.prometheus.PrometheusServlet) InetSocketAddress(java.net.InetSocketAddress) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) PrometheusMetricsProvider(org.apache.bookkeeper.stats.prometheus.PrometheusMetricsProvider) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Aggregations

File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 StatsLogger (org.apache.bookkeeper.stats.StatsLogger)1 PrometheusMetricsProvider (org.apache.bookkeeper.stats.prometheus.PrometheusMetricsProvider)1 PrometheusServlet (org.apache.bookkeeper.stats.prometheus.PrometheusServlet)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1