mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
added disk space monitoring, too.
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3929 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
0d143f963d
commit
30e54a7bc9
3 files changed
+69
-4
No files matched your search
@@ -1,9 +1,12 @@
|
||||
package hudson.model;
|
||||
|
||||
import hudson.model.Descriptor.FormException;
|
||||
import hudson.node_monitors.NodeMonitor;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import hudson.node_monitors.NodeMonitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -14,12 +17,28 @@ import java.util.List;
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class ComputerSet implements ModelObject {
|
||||
private static volatile List<NodeMonitor> monitors = Collections.emptyList();
|
||||
|
||||
public ComputerSet() {
|
||||
if(monitors.isEmpty()) {
|
||||
// create all instances when requested for the first time.
|
||||
ArrayList<NodeMonitor> r = new ArrayList<NodeMonitor>();
|
||||
for (Descriptor<NodeMonitor> d : NodeMonitor.LIST)
|
||||
try {
|
||||
r.add(d.newInstance(null));
|
||||
} catch (FormException e) {
|
||||
// so far impossible. TODO: report
|
||||
}
|
||||
monitors = r;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return "nodes";
|
||||
}
|
||||
|
||||
public List<NodeMonitor> get_monitors() {
|
||||
return null;
|
||||
return monitors;
|
||||
}
|
||||
|
||||
public Computer[] get_all() {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package hudson.node_monitors;
|
||||
|
||||
import hudson.FilePath;
|
||||
import hudson.FilePath.FileCallable;
|
||||
import hudson.model.Computer;
|
||||
import hudson.model.Descriptor;
|
||||
import hudson.remoting.VirtualChannel;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Checks available disk space of the node.
|
||||
* Requres Mustang.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @since 1.123
|
||||
*/
|
||||
public class DiskSpaceMonitor extends NodeMonitor {
|
||||
public Descriptor<NodeMonitor> getDescriptor() {
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
|
||||
public static final Descriptor<NodeMonitor> DESCRIPTOR = new AbstractNodeMonitorDescriptor<Long>(DiskSpaceMonitor.class) {
|
||||
protected Long monitor(Computer c) throws IOException, InterruptedException {
|
||||
FilePath p = c.getNode().getRootPath();
|
||||
if(p==null) return null;
|
||||
|
||||
return p.act(new FileCallable<Long>() {
|
||||
public Long invoke(File f, VirtualChannel channel) throws IOException {
|
||||
return f.getUsableSpace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return "Disk Space";
|
||||
}
|
||||
|
||||
public NodeMonitor newInstance(StaplerRequest req) throws FormException {
|
||||
return new DiskSpaceMonitor();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package hudson.node_monitors;
|
||||
|
||||
import hudson.ExtensionPoint;
|
||||
import hudson.Functions;
|
||||
import hudson.model.ComputerSet;
|
||||
import hudson.model.Describable;
|
||||
import hudson.model.Descriptor;
|
||||
@@ -42,7 +43,7 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon
|
||||
|
||||
static {
|
||||
LIST.add(ClockMonitor.DESCRIPTOR);
|
||||
//if(Functions.isMustangOrAbove())
|
||||
// LIST.add(new DiskSpaceMonitor());
|
||||
if(Functions.isMustangOrAbove())
|
||||
LIST.add(DiskSpaceMonitor.DESCRIPTOR);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user