【问题标题】:Monitor the Jetty-based Java application using Prometheus and Grafana使用 Prometheus 和 Grafana 监控基于 Jetty 的 Java 应用程序
【发布时间】:2017-11-06 10:49:12
【问题描述】:

我已经使用nohup 和 Jetty 在服务器(在 8091 中)部署了一个 Java 应用程序。

我需要使用 Prometheus 和 Grafana 监控该应用程序。

所以下载了 JMX 导出器。

需要获取该应用程序监控的所有可用指标(JMX 导出器)。

下载以下jar文件:

 https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.1.0/jmx_prometheus_javaagent-0.1.0.jar

Config.yaml

[root@localhost software]# cat config.yaml
---
startDelaySeconds: 0
hostPort: 127.0.0.1:7101
jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:7101/jmxrmi
ssl: false
lowercaseOutputName: true
lowercaseOutputLabelNames: true
rules:
- pattern: ".*"

我用于常规部署的部署命令:(在此目录中,存在 Jetty)

nohup  -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1 &

它工作正常..

当我尝试使用 JMX 导出器监控应用程序时,我使用了以下命令:

nohup java -javaagent:./jmx_prometheus_javaagent-0.1.0.jar=7101:config.yaml -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=epoch_temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1 &

它报告为:[1]+ 中止(核心转储)nohup java -javaagent:./jmx_prometheus_javaagent-0.1.0.jar=7101:config.yaml -Dorg.eclipse.jetty.server.Request.maxFormContentSize=10000000 -Xms256m -Xmx256m -Djava.io.tmpdir=epoch_temp_dir -jar jetty-runner-9.0.7.v20131107.jar --log yyyy_mm_dd-java-application-1-request.log --out yyyy_mm_dd-java-application-1-output.log --port 8091 --path /java-application-1 hotfix.war >> java-application-1.log 2>&1

在日志文件中: 它报告为:

nohup: ignoring input
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.IllegalArgumentException: At most one of hostPort and jmxUrl must be provided
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector.loadConfig(JmxCollector.java:120)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JmxCollector.<init>(JmxCollector.java:74)
        at io.prometheus.jmx.shaded.io.prometheus.jmx.JavaAgent.premain(JavaAgent.java:36)
        ... 6 more
FATAL ERROR in native method: processing of -javaagent failed

我不确定config.yaml 和我用于监控已部署Java 应用程序的命令是否正确。

如何使用 Prometheus 和 Grafana 监控这个基于 Jetty 的 java 应用程序?

【问题讨论】:

    标签: java jetty prometheus grafana jmx


    【解决方案1】:

    您在config.yaml 中同时指定了hostPortjmxUrl 键。但必须提供最多一个。删除其中一个。

    【讨论】:

    • 现在运行正常;我已经在 prometheus 服务器的 prometheus.yml 的 target 部分下添加了 IP:port 并重新启动了 Prometheus。但是 Prometheus 状态页面显示此服务器“关闭”。所以 Grafana 没有加载数据。原因:超时;进程正在服务器netstat 中运行。 curl localhost:port在java应用部署的服务器也等待了很长时间
    • Caused by: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: java.net.SocketTimeoutException: Read timed out] Caused by: java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is: java.net.SocketTimeoutException: Read timed out --- 错误日志
    • 我已经在客户端服务器中打开了 7101(JMX) 端口。授予对 Prometheus 服务器的访问权限以访问客户端服务器中的端口
    【解决方案2】:

    删除 config.yaml 中的 Hostport and JMXURL 对我有用..

     [root@localhost software]# cat config.yaml
        ---
        startDelaySeconds: 0
        ssl: false
        lowercaseOutputName: true
        lowercaseOutputLabelNames: true
        rules:
        - pattern: ".*"
    

    【讨论】:

      猜你喜欢
      • 2020-07-03
      • 2022-01-13
      • 2020-09-08
      • 1970-01-01
      • 2021-06-17
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      相关资源
      最近更新 更多