A simple Spring Boot application that generates Java GC activity for monitoring with OpenObserve.
- JDK 11+
- Maven
- OpenTelemetry Collector(Contrib Distribution)
- OpenObserve: You can get started with OpenObserve Cloud or a self hosted installation.
git clone https://github.com/openobserve/java-gc-demo.git
cd java-gc-demo
mvn clean package
mkdir -p logs
java '-Xlog:gc*=info:file=logs/gc.log:time,uptime,level,tags:filecount=10,filesize=10M' -jar target/gc-demo-0.0.1-SNAPSHOT.jar
Access these endpoints to generate different GC patterns:
- View memory status:
http://localhost:8080/status
- Allocate persistent memory (leak simulation):
http://localhost:8080/allocate?megabytes=20
- Allocate temporary memory:
http://localhost:8080/allocate-temp?megabytes=50
- Release temporary memory:
http://localhost:8080/clear-temp
- Clear all allocated memory:
http://localhost:8080/clear-all
Create config.yaml
:
receivers:
filelog:
include: [ /path/to/your/logs/gc.log ]
start_at: beginning
processors:
batch: {}
resource:
attributes:
- key: service.name
value: "java-gc-demo"
action: upsert
- key: app.name
value: "java-gc-demo"
action: upsert
- key: log.type
value: "gc_log"
action: upsert
exporters:
otlphttp/openobserve:
endpoint: https://api.openobserve.ai/api/default
headers:
Authorization: Basic <your-api-key>
stream-name: default
service:
pipelines:
logs:
receivers: [filelog]
processors: [batch, resource]
exporters: [otlphttp/openobserve]
Run the collector:
otelcol-contrib --config config.yaml
For full details, see our blog post on Java GC logs and OpenObserve.