Zeinab Abbasimazar
Zeinab Abbasimazar

Reputation: 10439

get jmx attributes with jolokia telegraf

I have a JAVA application which I want to monitor its JMX attributes using telegraf tool.

The tool provides jolikia plugin to monitor JMX attributes. I have added following dependencies to my app's pom.xml file regarding Maven section of Jolokia documentation:

<dependency>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-core</artifactId>
    <version>1.3.7</version>
</dependency>
<dependency>
    <groupId>org.jolokia</groupId>
    <artifactId>jolokia-client-java</artifactId>
    <version>1.3.7</version>
</dependency>

This is my /etc/telegraf/telegraf.conf file:

[[inputs.jolokia]]

   context = "/jolokia/"
   [[inputs.jolokia.servers]]
       name = "wr-core"
       host = "192.168.100.175"
       port = "1998"

   [[inputs.jolokia.metrics]]
       name = "send_success"
       mbean  = "wr-core:type=monitor,name=execution"
       attribute = "MessageSendSuccessCount"

The application is up in the provided IP/port (I can connect to it with jconsole). The application has a monitoring section which its object name (as shown in jconsole) is wr-core:type=monitor,name=execution and has the attribute MessageSendSuccessCount. But when I start telegraf service, following error occurs:

Jan 14 14:30:32 ZiZi telegraf[17258]: 2018-01-14T11:00:32Z E! Error in plugin [inputs.jolokia]: error performing request: Error decoding JSON response: invalid character '\x00' looking for beginning of value:

Note that 1998 is my app's jmx port. I also tried using 8778 which is jolokia-agent port; got:

Jan 14 14:40:03 ZiZi telegraf[9150]: 2018-01-14T11:10:03Z E! Error in plugin [inputs.jolokia]: error performing request: Post http://192.168.100.175:8778/jolokia/: dial tcp 192.168.100.175:8778: getsockopt: connection refused

EDIT 1:

I have checked my CLASSPATH and both jolokia-client and jolokia-core were listed: ../lib/jolokia-client-java-1.3.7.jar:../lib/jolokia-core-1.3.7.jar.

EDIT 2:

I have put following lines into my app's execution file:

JOLOKIA_OPTS=-javaagent:$LIB_PATH/jolokia-core-java-1.3.7.jar=port=8778,host=0.0.0.0

JAVA_OPTS="-mx4096M $JAVA_OPTS $JACOCO_OPTS $JOLOKIA_OPTS"

But when I run the file, I get this error (even though ../lib/jolokia-core-java-1.3.7.jar has been listed in the CLASSPATH):

Error opening zip file or JAR manifest missing : ../lib/jolokia-core-java-1.3.7.jar
Error occurred during initialization of VM
agent library failed to init: instrument

Upvotes: 0

Views: 5432

Answers (1)

Zeinab Abbasimazar
Zeinab Abbasimazar

Reputation: 10439

Found the solution.

I have skipped maven solution and tried the javaagent approach, but I had misunderstood the usage of javaagent previously; I should address jolokia jvm agent (this helped):

JOLOKIA_OPTS=-javaagent:/root/jolokia-jvm-1.3.7-agent.jar=port=8778,host=0.0.0.0
JAVA_OPTS="-mx4096M $JAVA_OPTS $JACOCO_OPTS $JOLOKIA_OPTS"

Now, my app starts with this log (successfully):

I> No access restrictor found, access to any MBean is allowed
Jolokia: Agent started with URL http://192.168.100.175:8778/jolokia/

In the other side there is no error in the telegraf console for jolokia anymore.

All the observation are implying the jolokia jvm library has been started and works successfully.

I have also found jolokia jmx documentation for using it as dependencies in the project; but since I'm not a JAVA expert (I'm testing the app), I prefer to currently use the javaagent approach and leave it for future study/experience. BTW, it may help the others.

EDIT 1:

I have found and deployed jolokia jvm agent using its spring support.

Configuring it in the spring XML file, I can now have jolokia jvm agent start listening at my app's startup.

Upvotes: 1

Related Questions