java - 格拉法纳中的"t.data.data is undefined"

标签 java grafana metrics prometheus micrometer

我是 micrometer、prometheus 和 grafana 的新手。我正在尝试将这三件事一起运行来运行我的第一个示例。但我很难弄清楚我做错了什么。

我正在使用 micrometer 的 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);
    }

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

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中得到的错误截图: enter image description here

有什么我可能缺少的建议吗?

注意:我可以使用 URL localhost:8080/prometheus 看到计时器在 native prometheus 上发布。

最佳答案

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

关于java - 格拉法纳中的"t.data.data is undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54011331/

相关文章:

java - 如何将 url 作为路径参数传递?在 JAX-RS @Path 中

java - Hibernate OneToMany 关系中的循环

docker - 如何将 Mysql docker 容器连接到 Grafana

prometheus - Prometheus 可以管理多少个标签值?

complexity-theory - 用于计算 Java 文件的 Halstead 复杂度指标的开源工具

scikit-learn - 如何在 scikit-learn 中为最近邻居使用用户定义的度量?

java - 如何转义 XML 的字符串?

java - 模拟父类(super class)构造函数

influxdb - 在 grafana 仪表板中如何设置警报邮件配置?

java - 绘制应用程序内存和 CPU 性能指标 Java Netbeans