APM agent telling jps is not installed, though it is

Hello,

I am trying to run the APM agent 1.17.0-standalone.jar on an Ubuntu 16.04.7 LTS machine with OpenJDK version 1.8.0_265. When I execute the command
java -jar apm-agent-attach-1.17.0-standalone.jar -i '/opt/application/cl0501/*/*.jar' --continuous --config service_name=apm_mbse --config server_urls=http://server:8211
as the root user I get the following error message:

Exception in thread "main" java.lang.IllegalStateException: Matching JVMs with --include or --exclude requires jps to be installed
        at co.elastic.apm.attach.RemoteAttacher.main(RemoteAttacher.java:63)

However JPS is installed. When I execute "jps" on the machine, it lists me all the running JVMs. What can the problem be?

Thanks in advance

Hi @sbienert,

Can you provide the output of the following commands:

java -version
which java
which jps
echo $JAVA_HOME

The JAVA_HOME environment variable is used to locate path to jps binary, which is searched using $PATH variable by interactive shell.

Thanks for your answer.

java -version outputs:

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~16.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

which java outputs:
/usr/bin/java

which jps outputs:
/usr/bin/jps

echo $JAVA_HOME outputs:
/usr/lib/jvm/java-8-oracle

I've managed to reproduce the issue, it's definitely a fun one due to ubuntu using symlinks for the java binary.

I have opened a PR that should allow to use the value set with JAVA_HOME instead to find the path to the jps binary (not part of the JRE, and only in the JDK).

The fix has been merged in master and will be included in the next release.

You can use artifacts from the CI in the mean time: https://apm-ci.elastic.co/blue/organizations/jenkins/apm-agent-java%2Fapm-agent-java-mbp/detail/master/505/artifacts

Thanks a lot!

Hi @Sylvain_Juge,

can you confirm that in the apm-agent-attach-1.18.1.RC1-SNAPSHOT-standalone the detection of the jars with --include flag and the regex pattern inside works? I do not get the jps error anymore but I tried several regex patterns for the paths to the jars and they do not seem the get the jar. The log says "Not attaching to ... bacause it is not included or excluded". When I put my regex pattern in a regex debugger, it does get the path though.

Hi @sbienert,

Can you provide me a full example of the command line you are using with the output of jps -lv so I can check ? (make sure there is no confidential info in it please).

Hi @Sylvain_Juge,

I found out the issue. I think it only detects the JVM if the full line of the jps output is fetched by the regex pattern. Meaning if I my regex pattern in the include-flag ends with ".jar" it does not work, I would have to end it with ".jar.*" e.g. but in the documentation there is one example where it also ends with ".jar" and beneath it says that the regex pattern only has to match the path to the jar or the classname.

jps -l outputs:
32295 sun.tools.jps.Jps

My command I execute:

java -jar apm-agent-attach-1.18.1.RC1-SNAPSHOT-standalone.jar --include '.*application.jar' --continuous --config service_name=application_apm --config server_urls=http://address:8211

I tried with a several other patterns too but only works when I do a wildcard end. Don't want to post the output because I would have to change potentially sensible data, but it says for each application that it's not attaching because its not included and not excluded.

Happy to know that you managed to find the issue here. I meant jps -lv in my previous message (I've since fixed it just in case someones struggles with this again).

I will check documentation to see how we can improve this.