【问题标题】:Can't scrape metrics from activemq by jmx-exporterjmx-exporter 无法从 activemq 中抓取指标
【发布时间】:2019-08-26 16:36:38
【问题描述】:

无法通过 jmx-exporter 从 activemq 中抓取指标

我将 jmx 导出器下载到我的虚拟机,然后按照说明运行命令,如下所示: java -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8980:config.yaml -jar /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/bin/activemq.jar

我得到了一些关于 activemq 的输出信息。 然后我尝试卷曲它: curl http://localhost:8980/metrics.

并得到错误:curl: (7) couldn't connect to host

我检查了这个过程。发现没有jvm-exporter的java进程。

为什么?我做错了什么?

这是我的 config.yaml

[root@sz-7-centos162 test]# cat config.yaml 
{
        startDelaySeconds: 0,
        username: admin,
        password: admin,
        jmxUrl: "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi",
        ssl: false,
        lowercaseOutputName: false,
        lowercaseOutputLabelNames: false
}

我希望 curl http://localhost:8980/metrics 获得指标,但实际上它只是向我显示一些有关 activemq 的信息,但什么也不做。 所有输出信息和我的操作都粘贴在下面:

[root@sz-7-centos162 test]# java -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8980:config.yaml -jar /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/bin/activemq.jar
Java Runtime: Oracle Corporation 1.8.0_51 /usr/jdk1.8.0_51/jre
  Heap sizes: current=243712k  free=233469k  max=3608576k
    JVM args: -javaagent:./jmx_prometheus_javaagent-0.12.0.jar=8980:config.yaml
Extensions classpath:
  [/usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/lib,/usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/lib/camel,/usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/lib/optional,/usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/lib/web,/usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/lib/extra]
ACTIVEMQ_HOME: /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56
ACTIVEMQ_BASE: /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56
ACTIVEMQ_CONF: /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/conf
ACTIVEMQ_DATA: /usr/local/tomcat/apache-activemq/apache-activemq-5.8.0_56/data
Usage: Main [--extdir <dir>] [task] [task-options] [task data]

Tasks:
    browse                   - Display selected messages in a specified destination.
    bstat                    - Performs a predefined query that displays useful statistics regarding the specified broker
    create                   - Creates a runnable broker instance in the specified path.
    decrypt                  - Decrypts given text
    encrypt                  - Encrypts given text
    export                   - Exports a stopped brokers data files to an archive file
    list                     - Lists all available brokers in the specified JMX context
    purge                    - Delete selected destination's messages that matches the message selector
    query                    - Display selected broker component's attributes and statistics.
    start                    - Creates and starts a broker using a configuration file, or a broker URI.
    stop                     - Stops a running broker specified by the broker name.

Task Options (Options specific to each task):
    --extdir <dir>  - Add the jar files in the directory to the classpath.
    --version       - Display the version information.
    -h,-?,--help    - Display this help information. To display task specific help, use Main [task] -h,-?,--help

Task Data:
    - Information needed by each specific task.

JMX system property options:
    -Dactivemq.jmx.url=<jmx service uri> (default is: 'service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi')
    -Dactivemq.jmx.user=<user name>
    -Dactivemq.jmx.password=<password>


[root@sz-7-centos162 test]# curl http://localhost:8980/metrics
curl: (7) couldn't connect to host
[root@sz-7-centos162 test]# ps -ef|grep javaagent
root     23739 21179  0 23:46 pts/0    00:00:00 grep javaagent
[root@sz-7-centos162 test]# cat config.yaml 
{
        startDelaySeconds: 0,
        username: admin,
        password: admin,
        jmxUrl: "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi",
        ssl: false,
        lowercaseOutputName: false,
        lowercaseOutputLabelNames: false
}
[root@sz-7-centos162 test]# ll
total 368
-rw-r--r-- 1 root root    252 Aug 26 23:19 config.yaml
-rw-r--r-- 1 root root 370075 Aug 26 17:45 jmx_prometheus_javaagent-0.12.0.jar
[root@sz-7-centos162 test]# 

【问题讨论】:

  • 我的回答是否解决了您的问题?如果是这样,请将其标记为正确,以帮助将来可能有同样问题的其他人。如果不是,请详细说明原因。谢谢!

标签: java activemq jmx-exporter


【解决方案1】:

您实际上并未启动 ActiveMQ 代理。这就是为什么它会打印有关可用命令的所有信息,例如:

Usage: Main [--extdir <dir>] [task] [task-options] [task data]

Tasks:
    browse                   - Display selected messages in a specified destination.
    bstat                    - Performs a predefined query that displays useful statistics regarding the specified broker
    create                   - Creates a runnable broker instance in the specified path.
    decrypt                  - Decrypts given text
    encrypt                  - Encrypts given text
    export                   - Exports a stopped brokers data files to an archive file
    list                     - Lists all available brokers in the specified JMX context
    purge                    - Delete selected destination's messages that matches the message selector
    query                    - Display selected broker component's attributes and statistics.
    start                    - Creates and starts a broker using a configuration file, or a broker URI.
    stop                     - Stops a running broker specified by the broker name.

Task Options (Options specific to each task):
    --extdir <dir>  - Add the jar files in the directory to the classpath.
    --version       - Display the version information.
    -h,-?,--help    - Display this help information. To display task specific help, use Main [task] -h,-?,--help

Task Data:
    - Information needed by each specific task.

您会注意到其中一个命令是start。这是实际启动代理所需运行的命令。

除此之外,您的config.yaml 没有定义任何rules 来告诉导出器要抓取和导出的MBean。您可以找到各种应用程序here 的示例规则。不幸的是,ActiveMQ 5.x 没有一个,所以你需要做一个。

除此之外,您还可以考虑ActiveMQ Artemis(下一代 ActiveMQ 代理)。它具有plugin architecture to export metricsPrometheus plugin 实现,因此无需使用JMX 导出器和配置规则。

【讨论】:

  • 嗨,@JustinBertram 在我运行启动命令之前。我的经纪人正在运行。另外,我们的生产使用这个版本。因此,它不能暂时更换。关于config.yaml,官网解释说,如果不配置,默认会收集所有的metrics。我认为首先收集了所有指标,然后我将编写规则以过滤掉我不需要的东西
  • 如果代理已经在运行,你为什么要有效地运行java -jar activemq.jarjavaagent 需要在 ActiveMQ 代理进程上设置,而不是在其他一些随机进程上。
  • 关于不是必要需要规则的观点,但你最终会想要它们,所以值得指出。
猜你喜欢
  • 2021-08-26
  • 1970-01-01
  • 2022-11-21
  • 2020-09-13
  • 1970-01-01
  • 2019-08-23
  • 2020-11-04
  • 2020-05-09
  • 2020-08-15
相关资源
最近更新 更多