如何使用 Prometheus 的 JMX 导出器 java 代理来收集自定义指标

How to use Prometheus' JMX exporter java agent to collect custom metrics

我想使用 Prometheus 的 JMX 导出器通过 Prometheus 收集自定义应用程序指标。我有一个已打包到 jar 文件中的应用程序 ApplicationToMonitor.jar-- 它公开了端口 8989 并声明了 Prometheus 指标,但没有公开供 prometheus 抓取的端点(根据我的阅读, prometheus javaagent 会处理这个)。

我不确定 configuration.yaml 文件应该是什么样子。此外,为什么建议使用 shaded.io.prometheus 库(并在默认注册表下注册新的度量变量)而不是常规的 io.prometheus 库并且根本不使用注册表?

我指的是 Prometheus JMX exporter documentation,只是不理解上述组件。

您只能将 JMX 导出器用于您无法控制的公开 JMX 指标的代码。在这种情况下,您需要根据 https://github.com/prometheus/client_java#http 添加一些说明。 HTTPServer最简单。