PrometheusMeterRegistry 卡在抓取函数调用处

PrometheusMeterRegistry stuck at scrape function call

我在配置 PrometheusMeterRegistry 以从 Geode 集群获取指标时遇到问题。 配置端点后,如果我 运行 curl 命令检查指标在配置的端点是否可用,http 请求处理程序会卡在抓取函数中:


    public void start(MetricsSession session) {
        this.session = session;
        registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
        this.session.addSubregistry(registry);

        InetSocketAddress address = new InetSocketAddress(9000);
        httpServer = null;
        try {
            httpServer = HttpServer.create(address, 0);
        } catch (IOException e) {
            e.printStackTrace();
        }
        HttpContext context = httpServer.createContext("/metrics");
        context.setHandler(this::requestHandler);
        httpServer.start();
    }

    private void requestHandler(HttpExchange httpExchange) throws IOException {
        final byte[] scrapeBytes = registry.scrape().getBytes();
        httpExchange.sendResponseHeaders(200, scrapeBytes.length);
        final OutputStream responseBody = httpExchange.getResponseBody();
        responseBody.write(scrapeBytes);
        responseBody.close();
    }

如您所见,这段代码与https://micrometer.io/docs/registry/prometheus

中如何配置Prometheus registry的例子基本相同

但是如果我执行 curl http://localhost:9000/metrics/ 我得不到答案。我检查过问题来自 registry.scrape() 调用,它卡住了。

关于可能是什么问题的任何线索?谢谢

问题已解决。不确定原因,但是在将我的代码的依赖项打包到同一个 jar 中(而不是将所有 jar 都添加到类路径中)之后,我终于从端点得到了答案。