Skip to content

Commit 49a0998

Browse files
committed
AppD and fixing S4R
1 parent 047fbf7 commit 49a0998

File tree

11 files changed

+392
-1
lines changed

11 files changed

+392
-1
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Building the PetClinic Application
3+
linkTitle: 1. Build PetClinic
4+
weight: 1
5+
---
6+
7+
## 1. Spring PetClinic Application
8+
9+
The first thing we need to set up APM is... well, an application. For this exercise, we will use the Spring PetClinic application. This is a very popular sample Java application built with the Spring framework (Springboot).
10+
11+
First, clone the PetClinic GitHub repository, and then we will compile, build, package and test the application:
12+
13+
```bash
14+
git clone https://github.com/spring-projects/spring-petclinic
15+
```
16+
17+
Change into the `spring-petclinic` directory (and checkout a specific commit):
18+
19+
```bash
20+
cd spring-petclinic && git checkout 276880e
21+
```
22+
23+
Start a MySQL database for PetClinic to use:
24+
25+
```bash
26+
docker run -d -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 docker.io/biarms/mysql:5.7
27+
```
28+
29+
Next, we will start a Docker container running Locust that will generate some simple traffic to the PetClinic application. Locust is a simple load-testing tool that can be used to generate traffic to a web application.
30+
31+
```bash
32+
docker run --network="host" -d -p 8090:8090 -v ~/workshop/petclinic:/mnt/locust docker.io/locustio/locust -f /mnt/locust/locustfile.py --headless -u 1 -r 1 -H http://127.0.0.1:8083
33+
```
34+
35+
Next, run the `maven` command to compile/build/package PetClinic:
36+
37+
```bash
38+
./mvnw package -Dmaven.test.skip=true
39+
```
40+
41+
{{% notice style="info" %}}
42+
This will take a few minutes the first time you run, `maven` will download a lot of dependencies before it compiles the application. Future builds will be a lot quicker.
43+
{{% /notice %}}
44+
45+
Once the build completes, you need to obtain the public IP address of the instance you are running on. You can do this by running the following command:
46+
47+
```bash
48+
curl ifconfig.me
49+
```
50+
51+
You will see an IP address returned, make a note of this as we will need it to validate that the application is running.
52+
53+
We also need to obtain the `INSTANCE` environment variable value, as this is what is being used as the `otel.service.name` attribute. You can do this by running the following command:
54+
55+
```bash
56+
echo $INSTANCE
57+
```
58+
59+
Also, make a note of this value as we will need it to filter the data in the UI.
60+
61+
You can now run the application with the following command. Notice that we are passing the `mysql` profile to the application, this will tell the application to use the MySQL database we started earlier. We are also setting the `otel.service.name` to a logical service name that will also be used in the UI for filtering:
62+
63+
```bash
64+
java \
65+
-Dserver.port=8083 \
66+
-Dotel.service.name=$INSTANCE-petclinic-service \
67+
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
68+
```
69+
70+
You can validate if the application is running by visiting `http://<IP_ADDRESS>:8083` (replace `<IP_ADDRESS>` with the IP address you obtained earlier). You should see the PetClinic application running.
71+
72+
## 2. AlwaysOn Profiling and Metrics
73+
74+
When we installed the collector we configured it to enable **AlwaysOn Profiling** and **Metrics**. This means that the collector will automatically generate CPU and Memory profiles for the application and send them to Splunk Observability Cloud.
75+
76+
When you start the PetClinic application you will see the collector automatically detect the application and instrument it for traces and profiling.
77+
78+
{{% tab title="Example output" %}}
79+
80+
``` text {wrap="false"}
81+
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/lib/splunk-instrumentation/splunk-otel-javaagent.jar -Dsplunk.profiler.enabled=true -Dsplunk.profiler.memory.enabled=true
82+
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
83+
[otel.javaagent 2023-06-26 13:32:04:661 +0100] [main] INFO io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - version: splunk-1.25.0-otel-1.27.0
84+
[otel.javaagent 2023-06-26 13:32:05:294 +0100] [main] INFO com.splunk.javaagent.shaded.io.micrometer.core.instrument.push.PushMeterRegistry - publishing metrics for SignalFxMeterRegistry every 30s
85+
[otel.javaagent 2023-06-26 13:32:07:043 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - -----------------------
86+
[otel.javaagent 2023-06-26 13:32:07:044 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - Profiler configuration:
87+
[otel.javaagent 2023-06-26 13:32:07:047 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.enabled : true
88+
[otel.javaagent 2023-06-26 13:32:07:048 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.directory : /tmp
89+
[otel.javaagent 2023-06-26 13:32:07:049 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.recording.duration : 20s
90+
[otel.javaagent 2023-06-26 13:32:07:050 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.keep-files : false
91+
[otel.javaagent 2023-06-26 13:32:07:051 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.logs-endpoint : null
92+
[otel.javaagent 2023-06-26 13:32:07:053 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - otel.exporter.otlp.endpoint : null
93+
[otel.javaagent 2023-06-26 13:32:07:054 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.memory.enabled : true
94+
[otel.javaagent 2023-06-26 13:32:07:055 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.tlab.enabled : true
95+
[otel.javaagent 2023-06-26 13:32:07:056 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.memory.event.rate : 150/s
96+
[otel.javaagent 2023-06-26 13:32:07:057 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.call.stack.interval : PT10S
97+
[otel.javaagent 2023-06-26 13:32:07:058 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.include.internal.stacks : false
98+
[otel.javaagent 2023-06-26 13:32:07:059 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - splunk.profiler.tracing.stacks.only : false
99+
[otel.javaagent 2023-06-26 13:32:07:059 +0100] [main] INFO com.splunk.opentelemetry.profiler.ConfigurationLogger - -----------------------
100+
[otel.javaagent 2023-06-26 13:32:07:060 +0100] [main] INFO com.splunk.opentelemetry.profiler.JfrActivator - Profiler is active.
101+
```
102+
103+
{{% /tab %}}
104+
105+
## 3. Review Profiling Data Collection
106+
107+
You can now visit the Splunk APM UI and examine the application components, traces, profiling, DB Query performance and metrics. From the left-hand menu **APM****Explore**, click the environment dropdown and select your environment e.g. `<INSTANCE>-petclinic` (where`<INSTANCE>` is replaced with the value you noted down earlier).
108+
109+
![APM Environment](../images/apm-environment.png)
110+
111+
Once your validation is complete you can stop the application by pressing `Ctrl-c`.
112+
113+
## 4. Adding Resource Attributes to Spans
114+
115+
Resource attributes can be added to every reported span. For example `version=0.314`. A comma-separated list of resource attributes can also be defined e.g. `key1=val1,key2=val2`.
116+
117+
Let's launch the PetClinic again using new resource attributes. Note, that adding resource attributes to the run command will override what was defined when we installed the collector. Let's add two new resource attributes `deployment.environment=$INSTANCE-petclinic-env,version=0.314`:
118+
119+
```bash
120+
java \
121+
-Dserver.port=8083 \
122+
-Dotel.service.name=$INSTANCE-petclinic-service \
123+
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
124+
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
125+
```
126+
127+
Back in the Splunk APM UI we can drill down on a recent trace and see the new `version` attribute in a span.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: Installing the AppDynamics Agent
3+
linkTitle: 2. AppDynamics Agent
4+
weight: 2
5+
---
6+
7+
## 1. Introduction
8+
9+
## 2. Install AppDynamics Agent
10+
11+
- Login to the AppDynamics Controller.
12+
- Under the **Home** menu, select **Getting Started**.
13+
- Click **Getting Started Wizard**.
14+
- Click **Java**.
15+
- Ensure the **JVM** is **JDK8+**.
16+
- Create a new application and enter application name. Please use the syntax `<initials>-petclinic-<date>` e.g. `rwc-petclinic-13-06-2024`.
17+
- Create a new tier and enter tier name. Please use the syntax `<initials>-petclinic-tier` e.g. `rwc-petclinic-tier`.
18+
- Enter a new Node Name. Please use the syntax `<initials>-petclinic-node` e.g. `rwc-petclinic-node`.
19+
- Click **Continue**.
20+
- Secure copy the zip file to your workshop instance.
21+
22+
```bash
23+
scp -P 2222 ~/Downloads/AppServerAgent-1.8-24.5.0.36037.zip [email protected]:/home/splunk
24+
```
25+
26+
- SSH into the workshop instance.
27+
28+
- `mkdir appd`
29+
- `unzip AppServerAgent-1.8-24.5.0.36037.zip -d opt/appdynamics`
30+
- `cd ~/spring-petclinic`
31+
- Start PetClinic with the AppDynamics agent.
32+
33+
```bash
34+
java \
35+
-Dserver.port=8081 \
36+
-javaagent:/home/splunk/appd/appagent/javaagent.jar \
37+
-Dappdynamics.agent.applicationName="rwc-petclinic-13-06-2024"\
38+
-Dappdynamics.agent.tierName="rwc-petclinic-tier" \
39+
-Dappdynamics.agent.nodeName="rwc-petclinic-node" \
40+
-jar target/spring-petclinic-*.jar
41+
```
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: 3. Real User Monitoring
3+
weight: 3
4+
---
5+
6+
## 1. Enable RUM
7+
8+
For the Real User Monitoring (RUM) instrumentation, we will add the Open Telemetry Javascript [**https://github.com/signalfx/splunk-otel-js-web**](https://github.com/signalfx/splunk-otel-js-web) snippet in the pages, we will use the wizard again **Data Management → Add Integration → RUM Instrumentation → Browser Instrumentation**.
9+
10+
Your instructor will inform you which token to use from the dropdown, click **Next**. Enter **App name** and **Environment** using the following syntax:
11+
12+
- `<INSTANCE>-petclinic-service` - replacing `<INSTANCE>` with the value you noted down earlier.
13+
- `<INSTANCE>-petclinic-env` - replacing `<INSTANCE>` with the value you noted down earlier.
14+
15+
The wizard will then show a snippet of HTML code that needs to be placed at the top of the pages in the `<head>` section. The following is an example of the (do not use this snippet, use the one generated by the wizard):
16+
17+
``` html
18+
/*
19+
20+
IMPORTANT: Replace the <version> placeholder in the src URL with a
21+
version from https://github.com/signalfx/splunk-otel-js-web/releases
22+
23+
*/
24+
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
25+
<script>
26+
SplunkRum.init({
27+
realm: "eu0",
28+
rumAccessToken: "<redacted>",
29+
applicationName: "petclinic-1be0-petclinic-service",
30+
deploymentEnvironment: "petclinic-1be0-petclinic-env"
31+
});
32+
</script>
33+
```
34+
35+
The Spring PetClinic application uses a single HTML page as the "layout" page, that is reused across all pages of the application. This is the perfect location to insert the Splunk RUM Instrumentation Library as it will be loaded in all pages automatically.
36+
37+
Let's then edit the layout page:
38+
39+
```bash
40+
vi src/main/resources/templates/fragments/layout.html
41+
```
42+
43+
Next, insert the snippet we generated above in the `<head>` section of the page. Make sure you don't include the comment and replace `<version>` in the source URL to `latest` e.g.
44+
45+
```html
46+
<!doctype html>
47+
<html th:fragment="layout (template, menu)">
48+
49+
<head>
50+
<script src="https://cdn.signalfx.com/o11y-gdi-rum/latest/splunk-otel-web.js" crossorigin="anonymous"></script>
51+
<script>
52+
SplunkRum.init({
53+
realm: "eu0",
54+
rumAccessToken: "<redacted>",
55+
applicationName: "petclinic-1be0-petclinic-service",
56+
deploymentEnvironment: "petclinic-1be0-petclinic-env"
57+
});
58+
</script>
59+
...
60+
```
61+
62+
## 2. Rebuild PetClinic
63+
64+
With the code changes complete, we need to rebuild the application and run it again. Run the `maven` command to compile/build/package PetClinic:
65+
66+
```bash
67+
./mvnw package -Dmaven.test.skip=true
68+
```
69+
70+
```bash
71+
java \
72+
-Dserver.port=8083 \
73+
-Dotel.service.name=$INSTANCE-petclinic-service \
74+
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
75+
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
76+
```
77+
78+
Then let's visit the application using a browser to generate real-user traffic `http://<IP_ADDRESS>:8083`.
79+
80+
In RUM, filter down into the environment as defined in the RUM snippet above and click through to the dashboard.
81+
82+
When you drill down into a RUM trace you will see a link to APM in the spans. Clicking on the trace ID will take you to the corresponding APM trace for the current RUM trace.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
---
2+
title: 4. Log Observer
3+
weight: 4
4+
---
5+
6+
## 1. Introduction
7+
8+
For the Splunk Log Observer component, we will configure the Spring PetClinic application to write logs to a file and configure the Splunk OpenTelemetry Collector to read (tail) that log file and send the logs to Splunk Cloud.
9+
10+
## 2. OpenTelemetry Filelog Configuration
11+
12+
We need to configure the Splunk OpenTelemetry Collector to tail the Spring PetClinic log file and send the log data to Splunk Cloud.
13+
14+
The Splunk OpenTelemetry Collector uses **Fluentd** by default but we will change the configuration to use the OpenTelemetry [**Filelog Receiver**](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/filelogreceiver/README.md) to consume the logs. We will need to edit the collectors' configuration file:
15+
16+
``` bash
17+
sudo vi /etc/otel/collector/agent_config.yaml
18+
```
19+
20+
Under the `receivers:` section create the Filelog Receiver (make sure to indent correctly):
21+
22+
``` yaml {hl_lines="2-3"}
23+
receivers:
24+
filelog:
25+
include: [/tmp/spring-petclinic.log]
26+
```
27+
28+
Then under the `service:` section, find the `logs:` pipeline, replace `fluentforward` with`filelog` (again, make sure to indent correctly):
29+
30+
``` yaml {hl_lines="2-7"}
31+
logs:
32+
receivers: [filelog, otlp]
33+
```
34+
35+
Save the file and exit the editor. Next, we need to validate that the HEC Token and HEC URL are configured for the collector to use. We will inspect the `/etc/otel/collector/splunk-otel-collector.conf` file:
36+
37+
```bash
38+
sudo cat /etc/otel/collector/splunk-otel-collector.conf
39+
```
40+
41+
Make sure `SPLUNK_HEC_URL` and `SPLUNK_HEC_TOKEN` have values set. If they are not set, please reach out to your instructor. With the configuration change complete and validated, we can now restart the collector:
42+
43+
```bash
44+
sudo systemctl restart splunk-otel-collector
45+
```
46+
47+
## 3. Logback Settings
48+
49+
The Spring PetClinic application can be configured to use several different Java logging libraries. In this scenario, we are going to use `logback`. We just need to create a file named `logback.xml` in the configuration folder:
50+
51+
```bash
52+
vi ~/spring-petclinic/src/main/resources/logback.xml
53+
```
54+
55+
Copy and paste the following XML content:
56+
57+
```xml
58+
<?xml version="1.0" encoding="UTF-8"?>
59+
<!DOCTYPE xml>
60+
<configuration scan="true" scanPeriod="30 seconds">
61+
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
62+
<resetJUL>true</resetJUL>
63+
</contextListener>
64+
<logger name="org.springframework.samples.petclinic" level="info"/>
65+
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
66+
<file>/tmp/spring-petclinic.log</file>
67+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
68+
<fileNamePattern>springLogFile.%d{yyyy-MM-dd}.log</fileNamePattern>
69+
<maxHistory>5</maxHistory>
70+
<totalSizeCap>1GB</totalSizeCap>
71+
</rollingPolicy>
72+
<encoder>
73+
<pattern>
74+
%d{yyyy-MM-dd HH:mm:ss} - %logger{36} - %msg trace_id=%X{trace_id} span_id=%X{span_id} trace_flags=%X{trace_flags} %n service.name=%property{otel.resource.service.name}, deployment.environment=%property{otel.resource.deployment.environment}: %m%n
75+
</pattern>
76+
</encoder>
77+
</appender>
78+
<root level="info">
79+
<appender-ref ref="file" />
80+
</root>
81+
</configuration>
82+
```
83+
84+
Now we need to rebuild the application and run it again:
85+
86+
```bash
87+
./mvnw package -Dmaven.test.skip=true
88+
```
89+
90+
Once the rebuild has been completed we can then run the application again:
91+
92+
```bash
93+
java \
94+
-Dserver.port=8083 \
95+
-Dotel.service.name=$INSTANCE-petclinic-service \
96+
-Dotel.resource.attributes=deployment.environment=$INSTANCE-petclinic-env,version=0.314 \
97+
-jar target/spring-petclinic-*.jar --spring.profiles.active=mysql
98+
```
99+
100+
## 4. View Logs
101+
102+
From the left-hand menu click on **Log Observer** and ensure **Index** is set to **splunk4rookies-workshop**.
103+
104+
Next, click **Add Filter** search for the field `service_name` select the value `<INSTANCE>-petclinic-service` and click `=` (include). You should now see only the log messages from your PetClinic application.
105+
106+
![Log Observer](../images/log-observer.png)
107+
108+
## 4. Summary
109+
110+
This is the end of the workshop and we have certainly covered a lot of ground. At this point, you should have metrics, traces (APM & RUM), logs, database query performance and code profiling being reported into Splunk Observability Cloud.
111+
112+
**Congratulations!**
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: PetClinic Java Workshop
3+
weight: 1
4+
description: Instrumenting PetClinic using AppDynamics.
5+
authors: ["Robert Castley"]
6+
time: 30 minutes
7+
---
8+
9+
We will also show the steps about how to clone (download) a sample Java application (Spring PetClinic), as well as how to compile, package and run the application.
10+
11+
TBD
12+
13+
{{% notice title="Prerequisites" style="primary" icon="info" %}}
14+
15+
* Outbound SSH access to port `2222`.
16+
* Outbound HTTP access to port `8083`.
17+
* Familiarity with the `bash` shell and `vi/vim` editor.
18+
19+
{{% /notice %}}
138 KB
Loading
195 KB
Loading
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: AppDynamics Workshops
3+
description: AppDynamics Workshops
4+
weight: 12
5+
---
6+
7+
{{% children containerstyle="ul" depth="1" description="true" %}}

0 commit comments

Comments
 (0)