|
| 1 | +:compat-mode: |
| 2 | += Lesson 3: Creating Operations-Friendly Microservices (Logging) |
| 3 | + |
| 4 | +== Introduction |
| 5 | +Provides an introduction to Spring Boot Actuator. |
| 6 | + |
| 7 | +== Building and running the sample |
| 8 | +Use the following commands to build run the application: |
| 9 | + |
| 10 | +``` |
| 11 | +$ mvn clean package |
| 12 | +$ java -jar target/livelessons-operations-actuator-1.0.0-SNAPSHOT.jar |
| 13 | +``` |
| 14 | + |
| 15 | +== HTTP Endpoints |
| 16 | +The following HTTP endpoints can be inspected in a running application: |
| 17 | + |
| 18 | +- http://localhost:8080/autoconfig[/autoconfig] |
| 19 | +- http://localhost:8080/beans[/beans] |
| 20 | +- http://localhost:8080/configprops[/configprops] |
| 21 | +- http://localhost:8080/dump[/dump] |
| 22 | +- http://localhost:8080/env[/env] |
| 23 | +- http://localhost:8080/health[/health] |
| 24 | +- http://localhost:8080/info[/info] |
| 25 | +- http://localhost:8080/metrics[/metrics] |
| 26 | +- http://localhost:8080/mappings[/mappings] |
| 27 | +- http://localhost:8080/trace[/trace] |
| 28 | + |
| 29 | +== JMX |
| 30 | +To view the same information using JMX you can use `jconsole`: |
| 31 | + |
| 32 | +``` |
| 33 | +$ jconsole |
| 34 | +``` |
| 35 | + |
| 36 | +Select `demo.OperationsActuatorApplication` from the ``local applications'' section (use |
| 37 | +insecure connection if asked) then click on the MBeans tab. You can the endpoints under |
| 38 | +`org.springframework.boot/Endpoint` pick an endpoint then click the `getData` button |
| 39 | +under `operations`. |
| 40 | + |
| 41 | +== SSH |
| 42 | +You can ssh into the running application using the following command: |
| 43 | + |
| 44 | +``` |
| 45 | +$ ssh -p 2000 livelessons@localhost |
| 46 | +``` |
| 47 | + |
| 48 | +The password is `livelessons` (see `application.properties`). |
| 49 | + |
| 50 | +Type `help` to get a list of commands. Endpoints can be executed using |
| 51 | +`endpoint invoke <name>` (for example `endpoint invoke info`). Several endpoints are |
| 52 | +also surfaced directly (for example `metrics`). The `dashboard` command is also quite |
| 53 | +fun. |
| 54 | + |
| 55 | + |
| 56 | +== JMX over Jolokia |
| 57 | +Jolokia allows you to expose JMX beans over HTTP. Adding the library is all you need to |
| 58 | +do to configure it with Spring Boot. It can be useful if you have existing MBeans (or |
| 59 | +MBeans exposed by libraries that you use). |
| 60 | + |
| 61 | +Here is an example call that will return `HeapMemoryUsage` information from the `Memory` |
| 62 | +MBean in `java/lang`: |
| 63 | + |
| 64 | +``` |
| 65 | +$ curl http://localhost:8080/jolokia/read/java.lang:type=Memory/HeapMemoryUsage |
| 66 | +``` |
| 67 | + |
| 68 | +== Using the Git Commit ID |
| 69 | +This sample includes the `git-commit-id-plugin`Maven Plugin which will write a |
| 70 | +`git.properties` file whenever the project is build. This information is automatically |
| 71 | +exposed on the `/info` endpoint. |
| 72 | + |
| 73 | +The commit SHA is very useful when running applications in production as it allows you |
| 74 | +to know exactly which commit was used to build the running app. You also use this to |
| 75 | +get back to the `POM.xml` or `build.gradle` and know exactly which library versions were |
| 76 | +used when the app was built. |
0 commit comments