Linux环境下Jenkins日志查询:找不到jenkins.wrapper.log时如何查启停时间
Hey there! I totally get it—sometimes the log files you expect aren't where you think they are. Let's walk through several reliable ways to track Jenkins' start/stop times on your Linux VM:
If your Jenkins is managed via a systemd service (standard on most modern Linux distros), the journalctl command is your go-to:
- View the full Jenkins service log:
journalctl -u jenkins.service - Filter for explicit start/stop entries to save time:
journalctl -u jenkins.service | grep -E "Started Jenkins|Stopped Jenkins" - Narrow it down to a specific time range, like the last 24 hours:
journalctl -u jenkins.service --since "24 hours ago" | grep -E "Started|Stopped"
Jenkins writes core runtime logs to a default path (varies by distro):
- Common locations:
/var/log/jenkins/jenkins.log(Debian/Ubuntu-based systems)/var/lib/jenkins/logs/jenkins.log(some RHEL/CentOS setups)
- Search for key start/stop markers:
grep -E "Jenkins is fully up and running|Shutdown started" /var/log/jenkins/jenkins.log
You’ll see lines like "Jenkins is fully up and running" on startup, and "Shutdown started" when the service stops.
If Jenkins is currently running, you can pull its start time directly from the process:
- First get the Jenkins PID:
ps -ef | grep jenkins | grep -v grep - Use the PID to get the exact start time:
Or useps -o lstart= -p <JENKINS_PID>statfor another format:stat /proc/<JENKINS_PID> | grep Birth
If Jenkins is up, you can use its API to get uptime and calculate the start time:
Visit http://<your-jenkins-url>:<port>/api/json and look for the uptimeMillis field (milliseconds Jenkins has been running). Subtract this from the current time to get the start timestamp.
For a command-line approach with curl and jq:
CURRENT_TIME=$(date +%s%3N) UPTIME=$(curl -s http://localhost:8080/api/json | jq '.uptimeMillis') START_TIME=$(( (CURRENT_TIME - UPTIME) / 1000 )) date -d @$START_TIME
Note: If Jenkins has authentication enabled, add your credentials to the curl command like curl -u username:password ...
If you have the acct package installed, use lastcomm to view Jenkins process history:
lastcomm jenkins
This shows when Jenkins processes started and how long they ran—just make sure the acct service is enabled first.
内容的提问来源于stack exchange,提问作者andreasgk

