Monitor and Troubleshoot Jenkins: Logs, Metrics, Prometheus, Disk, Memory, Queue Problems and Common Errors
What to Watch
| Signal | Why it matters | Warning sign |
|---|---|---|
| Build queue length and wait time | Developers wait for executors | Queue grows for many minutes |
| Executor usage | Capacity | Always 100 percent busy |
| Agent status | Offline agents reduce capacity | Agents offline, flapping |
| JVM heap and GC time | Controller stability | Heap near full, long pauses |
Disk free on JENKINS_HOME and agents | Builds fail when disk is full | Under 20 percent free |
| Build success rate and duration | Pipeline health | Sudden increase in failures or time |
| HTTP response time | UI speed | Slow pages, timeouts |
Prometheus and Grafana
- Install the Prometheus metrics plugin (
prometheus) - Metrics appear at
/prometheus/(protect with authentication or an allow-list) - Add a scrape job in Prometheus
- Import a Jenkins dashboard in Grafana, then create alerts
yaml
# prometheus.yml
scrape_configs:
- job_name: jenkins
metrics_path: /prometheus/
scheme: https
authorization:
credentials_file: /etc/prometheus/jenkins.token
static_configs:
- targets: ["jenkins.example.com"]
yaml
# alert rules (examples)
groups:
- name: jenkins
rules:
- alert: JenkinsQueueLong
expr: jenkins_queue_size_value > 20
for: 10m
labels: {severity: warning}
annotations: {summary: "Jenkins queue has more than 20 items for 10 minutes"}
- alert: JenkinsNodesOffline
expr: jenkins_node_offline_value > 0
for: 15m
labels: {severity: warning}
- alert: JenkinsDiskLow
expr: (node_filesystem_avail_bytes{mountpoint="/var/lib/jenkins"} / node_filesystem_size_bytes{mountpoint="/var/lib/jenkins"}) < 0.15
for: 10m
labels: {severity: critical}
Check metric names: Names can vary with plugin versions. Open the
/prometheus/ page of your Jenkins and copy the exact metric names into your queries.
Where the Logs Are
| Log | Location |
|---|---|
| Build (console) log | Job page → Console Output; file jobs/NAME/builds/N/log |
| Jenkins system log | Manage Jenkins → System Log; or journalctl -u jenkins, or /var/log/jenkins/jenkins.log |
| Agent log | Node page → Log |
| Docker | docker logs jenkins |
| Kubernetes | kubectl logs deploy/jenkins, and agent pod logs |
| Reverse proxy | nginx access.log and error.log |
bash
sudo journalctl -u jenkins --since "1 hour ago" --no-pager | grep -iE "severe|exception|outofmemory"
docker logs --since 1h jenkins 2>&1 | grep -iE "severe|exception"
- Add a log recorder (Manage Jenkins → System Log → Add new log recorder) for a class such as
hudson.slavesat FINE level to debug agents, then switch it off - Send logs to a central system to search across time
Memory and the JVM
ini
# Example JAVA_OPTS for a controller with 8 GB RAM
JAVA_OPTS="-Xms2g -Xmx4g -XX:+UseG1GC -XX:+AlwaysPreTouch -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jenkins/ -Djava.awt.headless=true"
| Setting | Meaning |
|---|---|
-Xms / -Xmx | Start and maximum heap. Set both the same for steady behavior |
-XX:+UseG1GC | G1 garbage collector, a good default |
-XX:+HeapDumpOnOutOfMemoryError | Save a heap dump on crash for later analysis |
| Leave memory for the OS | Do not give Java all RAM; metaspace and native memory need space |
- Symptoms of memory trouble: UI slow, builds stall,
java.lang.OutOfMemoryErrorin logs - Common causes: too many jobs with long history, heavy plugins, huge Groovy data, many parallel pipelines
- Fixes: raise heap moderately, discard old builds, remove unused plugins, move work to agents, split into multiple controllers
Disk Space
bash
df -h /var/lib/jenkins
sudo du -sh /var/lib/jenkins/* | sort -h | tail
sudo du -sh /var/lib/jenkins/jobs/*/builds | sort -h | tail
docker system df # on agents
docker system prune -af --volumes # careful: removes unused images and volumes
- Set Discard old builds (days and count) on every job, or
buildDiscarderin pipelines - Use
cleanWs()at the end of pipelines and clean workspace policies on agents - Archive only needed artifacts and keep them in Nexus/Artifactory/S3
- Schedule a cleanup job for agents: old Docker images, volumes, Maven or npm caches
Queue and Executor Problems
| Message / symptom | Likely cause | Fix |
|---|---|---|
Waiting for next available executor | All executors busy | Add agents, reduce parallelism, shorten builds |
There are no nodes with the label 'x' | Label typo or no agent has it | Fix the label or add the node |
'x' is offline | Agent disconnected | Check agent log, network, Java, restart |
| Jobs wait while executors are idle | Exclusive mode, or label mismatch, or resource lock | Check node usage mode, labels, lockable resources |
Queue item stuck: Pending | Waiting for a Kubernetes pod or cloud agent to start | Check cloud quota, pod events, image pull |
Agent Connection Problems
| Error | Check |
|---|---|
java.net.ConnectException: Connection refused | Agent port, firewall, WebSocket setting, URL |
SSH: Authentication failed | Credential, key format, user, authorized_keys |
Host key verification failed | Known hosts strategy, or add the host key |
UnsupportedClassVersionError | Agent Java is older than required. Update Java on the agent |
| Agent keeps disconnecting | Network timeouts, load balancer idle timeout, low memory on the agent |
Cannot connect... 403 or No valid crumb | Reverse proxy headers, Jenkins URL, or security settings |
Pipeline Problems
| Symptom | What to try |
|---|---|
| Pipeline stuck, no output | Check for input waiting, a lock waiting, or a process that never ends. Add timeout |
groovy.lang.MissingMethodException | Plugin missing, step typo, or wrong arguments. Use the Pipeline Syntax snippet generator |
RejectedAccessException / Scripts not permitted | Sandbox blocked a method. Approve only if safe, or move logic to a library |
NotSerializableException | Non-serializable object held across steps. Use @NonCPS or simpler data |
WorkflowScript: unable to resolve class | Missing import or shared library not loaded (@Library) |
| Build works locally, fails in Jenkins | Different tool versions, environment variables, user, or missing files. Print env, pwd, whoami (without secrets) |
Permission denied for Docker | Jenkins user is not in the docker group, or socket not mounted |
Thread Dump and Support Bundle
- When Jenkins is slow or frozen: take a thread dump (Manage Jenkins → System Information → Thread dumps, or
jstack PID) and look for blocked threads or lock waits - The Support Core plugin makes a support bundle (logs, configuration, plugin list, thread dumps) to share with teammates or vendors
- Check
/manage/log/and the Administrative monitors banners in Manage Jenkins first
bash
PID=$(pgrep -f jenkins.war)
jstack $PID > /tmp/jenkins-threads-$(date +%s).txt
jcmd $PID GC.heap_info
Troubleshooting Routine
- Define the problem: what failed, since when, for whom
- Check recent changes: plugin update, config change, new job, infrastructure change
- Read the log around the first error, not the last one
- Check resources: disk, memory, CPU, network
- Reproduce on a test job or agent
- Fix, then write down the cause and add a monitor or alert
Practice Tasks
- Install the Prometheus plugin and view metrics in your browser
- Create a Grafana panel for queue size and executor usage
- Fill a lab disk and observe failures, then add
buildDiscarderand clean up - Break an agent label on purpose and read the queue message
- Take a thread dump and a support bundle on a lab Jenkins
Conclusion
Watch queue, executors, agents, JVM heap, disk and build health with Prometheus and Grafana, read system and build logs, tune the heap, discard old builds, and use a routine for errors: define, check changes, read first errors, check resources, reproduce, fix and record. Thread dumps and support bundles help with hard cases.
Quick Summary: signals table; Prometheus plugin + alerts; log locations; JVM options; disk cleanup; queue/agent/pipeline error tables; thread dump + support bundle; routine.

