Unable to configure Elastic APM with Java App

Hello team

I'm trying to integrate apm with java app.

Kibana version: 7.1.1

Elasticsearch version: 7.1.1

APM Server version: 7.2.0

APM Agent language and version: Java 1.7.0

Java App: https://github.com/elastic/spring-petclinic

Java app is up and running(on AWS EC-2):
image

APM is running too
image

APM is configured in Java as a jar. you can see it here
image

Now, How do I make sure the logs from java app are being sent to apm server and then to elasticsearch. I dont see any service related to java in kibana.

I tried this option in cmd to configure java app with apm:

Is there anything that I need to do while running java app.

Please suggest

Thanks for your time as always :slight_smile:

You only need to do this if you actually want to enhance the traces via the public API. I suggest to remove that until you need it. You are also using a very old version of the API.

You are using the wrong jar to runtime attach to your application. See the installation instructions where to download the correct jar for remote attachment.

1 Like

Thank you @felixbarny

Running with command. Stuck here, can you please suggest, I tried changing jdk path in env variables but couldnt work.

can you send all Path variable value?

As the exception message suggests, you are probably trying to attach with a JRE but attaching requires a JDK. Could you send me the output of java -version?

Here it is

image

Please try to verify that the java command you are using is coming from a JDK bin and jre/bin.
Regardless, any reason why you can't install the agent through the -javaagent configuration?

1 Like

First can you echo your JAVA_HOME it is still unclear if you are using a JRE or JDK

echo $JAVA_HOME

Also your your startup command should look something like the following, substitute the URL of your APM Server. You do not need the APM as part of the dependency for the application to use the automatic instrumentation.

java -javaagent:./elastic-apm-agent-1.7.0.jar \
-Delastic.apm.server_urls="http://localhost:8200" \
-Delastic.apm.service_name="spring-petclinic-monolith" \
-Delastic.apm.application_packages="org.springframework.samples" \
-Delastic.apm.trace_methods="org.springframework.samples.petclinic.*" \
-jar target/spring-petclinic-2.1.0.BUILD-SNAPSHOT.jar

A complete quick sample on how to run Petclinic with APM can be found here. You can ignore the docker stuff but it shows you how to build and run Petclinic and get APM data. This is a fork that I put a performance bug in that you can find with APM

1 Like

Hey @stephenb

I've followed the same procedure and able to configure for the java app. It's working well

And, the spring pet-clinic app you have mentioned is monolith. I've also configured it for micro-services based pet-clinic app(https://github.com/elastic/spring-petclinic).
Configured it for java, python. trying to set up front end. Not much aware of how to start the front-end app. I'm exploring, please let me know if you are aware of it.

Also, I've one question related to java apm.

I also wanted to monitor jvm and threads. Is there any way using APM ? or do i need to use beats for that ?

Thanks for your time

Best
Rahul

@rahulnama the Java agent is sending JVM metrics that are stored in dedicated APM indices.
Since Kibana version 7.2, the APM UI also shows JVM memory and thread count on the Metrics tab.
There is a work going on to expand that to show more JVM metrics (like GC), better filtering options and more in upcoming releases.

If you want a little better instructions on the real user monitoring RUM check out this blog

1 Like

Well, that’s great stuff. It used to be very difficult with beats configuring jolokia jmx and all. Awesome feature this is. I will try it out soon

Thanks for the great news :slight_smile:

Thanks. That helps

hey @stephenb

Stuck with a typical requirement.

All my java apps are running in production(assume on ec2 instances). Now I've to integrate them with APM without re-deploying/re-starting the java app. how to achieve this. We are using ansible for remote installation of apm on different machines.

The attacher allows to instrument running applications without a restart: https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html

2 Likes

Thank you @felixbarny
will look into it.

Hello @stephenb

Running the spring pet-clinic app: Integrated with apm and working fine.

But, Once I click on Error Page, In kibana I see the number of occurrences very high(Though I actually hit the error page only once)

If you see in the image it's displaying number of occurences as 214 and 56 in last 5 mins. However, I've clicked the error page only 6-7 times. not sure why is it showing such a high count ?
Any suggestions ?

Hello @stephenb

Running petclinic app. need your help.
I want to use mysql (instead of hsqldb)which is installed on AWS ec2. In that case I can also track the mysql metrics and query logs using packetbeat and filebeat.

Could you explain me how to configure mysql for spring-petclinic?

I've changed the details of mysql in appliation.properties file.
And also I've changed database=mysql(hsqldb). Also tried running scripts manually.

but when I build and run I see lot of errors. could you let me know what else is needed to run app with mysql running on localhost.

Thanks for your time.

Hi @rahulnama

That is really petclinic related not elastic stack related there is a whole community and lots of help around petclinic perhaps you can share your error messages and get some help there... of course include your error messages because without them no one will be able to really help

Here are a couple places to look...

https://projects.spring.io/spring-petclinic/

https://spring-petclinic.github.io/

https://spring-petclinic.github.io/docs/forks.html

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.