Skip to content

Latest commit

 

History

History
85 lines (65 loc) · 2.09 KB

Readme.md

File metadata and controls

85 lines (65 loc) · 2.09 KB

Java GC Demo for OpenObserve

A simple Spring Boot application that generates Java GC activity for monitoring with OpenObserve.

Prerequisites

Quick Start

1. Build the Application

git clone https://github.com/openobserve/java-gc-demo.git
cd java-gc-demo
mvn clean package

2. Run with GC Logging Enabled

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

3. Generate GC Activity

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

4. Configure OpenTelemetry Collector

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

Learn More

For full details, see our blog post on Java GC logs and OpenObserve.