"t.data.data is undefined" 在 grafana 中

"t.data.data is undefined" in grafana

我是千分尺、普罗米修斯和格拉法纳的新手。我正在尝试 运行 我的第一个例子,这三件事一起工作。但是我很难弄清楚我做错了什么。

我正在使用千分尺 API 创建一个 PrometheusMeterRegistry 像这样:

new PrometheusMeterRegistry(new PrometheusConfig() {
        @Override
        public Duration step() {
            return Duration.ofSeconds(10);
        }

        @Override
        @Nullable
        public String get(String k) {
            return null;
        }
    });

我正在使用以下代码创建一个 HttpServer,如下所述:

try {
            HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
            server.createContext("/prometheus", httpExchange -> {
                String response = prometheusMeterRegistry.scrape();
                httpExchange.sendResponseHeaders(200, response.getBytes().length);
                try (OutputStream os = httpExchange.getResponseBody()) {
                    os.write(response.getBytes());
                }
            });

            new Thread(server::start).start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

我在 grafana 中将 Prometheus 配置为我的数据源,并将 URL 设置为 http://localhost:8080/prometheus。但是当我尝试创建一个新的仪表板并向其添加图表时,我得到一个红色感叹号 t.data.data is undefined。因此,我无法查看图表。完整的堆栈跟踪如下:

kr</t.prototype.transform@http://localhost:3000/public/build/app.dfabdd44b3be44288eac.js:22:723420
jr</t.prototype.query/</<@http://localhost:3000/public/build/app.dfabdd44b3be44288eac.js:22:736135
qt@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:9:5239
Wa@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:9:40274
jr</t.prototype.query/<@http://localhost:3000/public/build/app.dfabdd44b3be44288eac.js:22:735858
c/</<@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:92198
c/<@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:92043
$digest@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:97575
$apply@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:99590
$applyAsync/r<@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:99735
h@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:33036
ln/this.$get</</i.defer/n<@http://localhost:3000/public/build/vendor.dfabdd44b3be44288eac.js:130:34396

下面是我在grafana中获取错误的截图:

有什么我可能遗漏的建议吗?

注意:我可以使用 URL localhost:8080/prometheus.

看到计时器在本机 prometheus 上发布

8080 是您的应用服务器。您需要 运行 一个抓取此应用程序的 Prometheus 服务器,然后您可以使用 localhost:9090 作为数据源。