Skip to content

Add dumpinterval and json agent options#233

Open
debedb wants to merge 2 commits intojenkinsci:masterfrom
debedb:dumpinterval-and-json
Open

Add dumpinterval and json agent options#233
debedb wants to merge 2 commits intojenkinsci:masterfrom
debedb:dumpinterval-and-json

Conversation

@debedb
Copy link

@debedb debedb commented Feb 13, 2026

Description

Add two new agent options for the file-leak-detector Java agent:

  • dumpinterval=N — Periodically dump all open file descriptors every N seconds using a daemon Timer thread. This is useful for monitoring file descriptor leaks in long-running services where you want continuous visibility without waiting for shutdown.

  • json — Output dumps in single-line JSON format instead of plain text. Each dump is a single JSON line containing a timestamp, descriptor count, and an array of open descriptors with type, resource, thread, open time, and stack trace. This format is suitable for log aggregation systems (CloudWatch Logs, ELK, Splunk, etc.) and enables structured querying of leak data.

Example agent string:

-javaagent:file-leak-detector.jar=dumpinterval=5,json,dumpatshutdown

Sample JSON output:

{"timestamp":"2025-01-15T10:30:00.000Z","openDescriptors":3,"descriptors":[{"index":1,"type":"file","resource":"/tmp/leaky.tmp","thread":"main","openedAt":"...","stackTrace":["com.example.App.main(App.java:10)",...]}]}

The PR also includes a LeakyApp example under examples/ that demonstrates both options with a multi-threaded application that intentionally leaks file descriptors.

Testing done

  • Built the agent with mvn -DskipTests package
  • Ran the LeakyApp example with both plain text (run.sh) and JSON (run-json.sh) modes
  • Verified periodic dumps appear at the configured interval
  • Verified shutdown dump triggers on SIGTERM
  • Verified JSON output is valid single-line JSON parseable by jq

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests that demonstrate the feature works or the issue is fixed

Add two new agent options:
- dumpinterval=N: periodically dump open file descriptors every N seconds
  using a daemon Timer thread
- json: output dumps in single-line JSON format suitable for log
  aggregation (CloudWatch, ELK, etc.)

Also includes a LeakyApp example that demonstrates both options with a
multi-threaded app that intentionally leaks file descriptors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant