Skip to content

Instantly share code, notes, and snippets.

@bvader
Last active September 27, 2018 04:33
Show Gist options
  • Save bvader/41cc23db56c66e4a452015a0d7afb2ed to your computer and use it in GitHub Desktop.
Save bvader/41cc23db56c66e4a452015a0d7afb2ed to your computer and use it in GitHub Desktop.
Setup Spring Petclinic Rest with Elastic APM Agent
###
# I am not a Maven Guru so I am sure there is a better way to do the copy in the pom.xml
# But I am demonstrating that java apm agent is not required at compile time
# the java apm agent should probably be installed / pulled from a local or maven repo
# In PCF the entire app and app agent need to be deployed
# There are some subtleties with PCF that I will not go into here
###
#
# Prequisite setup APM running localhost
#
# spring-petclinic-rest https://github.com/spring-petclinic/spring-petclinic-rest
$ git clone https://github.com/spring-petclinic/spring-petclinic-rest.git
$ cd spring-petclinic-rest/
$ curl -O https://search.maven.org/remotecontent?filepath=co/elastic/apm/elastic-apm-agent/0.7.0/elastic-apm-agent-0.7.0.jar
$ ./mvnw package
$ java -javaagent:../spring-petclinic-rest/elastic-apm-agent-0.7.0.jar -Delastic.apm.server_urls=http://localhost:8200 -Delastic.apm.service_name=spring-petclinic-rest -Delastic.apm.application_packages=org.springframework.samples.petclinic -jar target/spring-petclinic-1.5.2.war
# Browse to
http://localhost:9966/petclinic
# Explore the Swagger, You can See the API Documents
# and exercise Rest Endpoints, and they will end up in the APM server
###
# Now if you want to do my mysql
###
# Quick setup of mysql docker
docker run --name mysql-petclinic -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8
# Edit these two files the will connect the app to local mysq
# There is a couple minor issues with the README i.e.
# see gist https://gist.github.com/bvader/d37cb69f51b52f340de24665d5aa8530
$ vi src/main/resources/application.properties
# need to use user:root
# turn on create the schema etc
# see gist https://gist.github.com/bvader/8327fcea691e1016e9fdd4403478886d
$ vi src/main/resources/application-mysql.properties
$ ./mvnw package
$ java -javaagent:../spring-petclinic-rest/elastic-apm-agent-0.7.0.jar -Delastic.apm.server_urls=http://localhost:8200 -Delastic.apm.service_name=spring-petclinic-rest -Delastic.apm.application_packages=org.springframework.samples.petclinic -jar target/spring-petclinic-1.5.2.war
# Browse to
http://localhost:9966/petclinic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment