use of com.cloudbees.jenkins.support.api.FileContent in project support-core-plugin by jenkinsci.
the class GCLogs method addContents.
@Override
public void addContents(@NonNull Container result) {
LOGGER.fine("Trying to gather GC logs for support bundle");
String gcLogFileLocation = getGcLogFileLocation();
if (gcLogFileLocation == null) {
LOGGER.config("No GC logging enabled, nothing about it will be retrieved for support bundle.");
return;
}
if (isGcLogRotationConfigured()) {
handleRotatedLogs(gcLogFileLocation, result);
} else {
File file = new File(gcLogFileLocation);
if (!file.exists()) {
LOGGER.warning("[Support Bundle] GC Logging apparently configured, " + "but file '" + gcLogFileLocation + "' not found");
return;
}
result.add(new FileContent(GCLOGS_BUNDLE_ROOT + "gc.log", file));
}
}
use of com.cloudbees.jenkins.support.api.FileContent in project support-core-plugin by jenkinsci.
the class JenkinsLogs method addOtherMasterLogs.
/**
* Grabs any files that look like log files directly under {@code $JENKINS_HOME}, just in case
* any of them are useful.
* Does not add anything if Jenkins instance is unavailable.
* Some plugins write log files here.
*/
private void addOtherMasterLogs(Container result) {
final Jenkins jenkins = Jenkins.getInstance();
File[] files = jenkins.getRootDir().listFiles(ROTATED_LOGFILE_FILTER);
if (files != null) {
for (File f : files) {
result.add(new FileContent("other-logs/" + f.getName(), f));
}
}
File logs = getLogsRoot();
files = logs.listFiles(ROTATED_LOGFILE_FILTER);
if (files != null) {
for (File f : files) {
result.add(new FileContent("other-logs/" + f.getName(), f));
}
}
File taskLogs = new File(logs, "tasks");
files = taskLogs.listFiles(ROTATED_LOGFILE_FILTER);
if (files != null) {
for (File f : files) {
result.add(new FileContent("other-logs/" + f.getName(), f));
}
}
}
use of com.cloudbees.jenkins.support.api.FileContent in project support-core-plugin by jenkinsci.
the class SlaveLaunchLogs method addSlaveLaunchLog.
/**
* <p>
* In the presence of {@link Cloud} plugins like EC2, we want to find past agents, not just current ones.
* So we don't try to loop through {@link Node} here but just try to look at the file systems to find them
* all.
*
* <p>
* Generally these cloud plugins do not clean up old logs, so if run for a long time, the log directory
* will be full of old files that are not very interesting. Use some heuristics to cut off logs
* that are old.
*/
private void addSlaveLaunchLog(Container result) {
class Slave implements Comparable<Slave> {
/**
* Launch log directory of the agent: logs/slaves/NAME
*/
File dir;
long time;
Slave(File dir, File lastLog) {
this.dir = dir;
this.time = lastLog.lastModified();
}
/**
* Agent name
*/
String getName() {
return dir.getName();
}
/**
* Use the primary log file's timestamp to compare newer agents from older agents.
*
* sort in descending order; newer ones first.
*/
public int compareTo(Slave that) {
long lhs = this.time;
long rhs = that.time;
if (lhs < rhs)
return 1;
if (lhs > rhs)
return -1;
return 0;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Slave slave = (Slave) o;
if (time != slave.time)
return false;
return true;
}
@Override
public int hashCode() {
return (int) (time ^ (time >>> 32));
}
/**
* If the file is more than a year old, can't imagine how that'd be of any interest.
*/
public boolean isTooOld() {
return time < System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365);
}
}
List<Slave> all = new ArrayList<Slave>();
{
// find all the agent launch log files and sort them newer ones first
File slaveLogsDir = new File(Jenkins.getInstance().getRootDir(), "logs/slaves");
File[] logs = slaveLogsDir.listFiles();
if (logs != null) {
for (File dir : logs) {
File lastLog = new File(dir, "slave.log");
if (lastLog.exists()) {
Slave s = new Slave(dir, lastLog);
// we don't care
if (s.isTooOld())
continue;
all.add(s);
}
}
}
Collections.sort(all);
}
{
// this might be still too many, so try to cap them.
int acceptableSize = Math.max(256, Jenkins.getInstance().getNodes().size() * 5);
if (all.size() > acceptableSize)
all = all.subList(0, acceptableSize);
}
// now add them all
for (Slave s : all) {
File[] files = s.dir.listFiles(ROTATED_LOGFILE_FILTER);
if (files != null)
for (File f : files) {
result.add(new FileContent("nodes/slave/" + s.getName() + "/launchLogs/" + f.getName(), f, FileListCapComponent.MAX_FILE_SIZE));
}
}
}
Aggregations