提交 58aa439c 编写于 作者: K kohsuke

Hudson can now monitor the swap space of slaves.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10668 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5eaec9b9
...@@ -485,6 +485,11 @@ ...@@ -485,6 +485,11 @@
<artifactId>winp</artifactId> <artifactId>winp</artifactId>
<version>1.5</version> <version>1.5</version>
</dependency> </dependency>
<dependency>
<groupId>org.jvnet.hudson</groupId>
<artifactId>memory-monitor</artifactId>
<version>1.1</version>
</dependency>
<dependency> <dependency>
<groupId>com.octo.captcha</groupId> <groupId>com.octo.captcha</groupId>
<artifactId>jcaptcha-all</artifactId> <artifactId>jcaptcha-all</artifactId>
......
...@@ -80,6 +80,7 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon ...@@ -80,6 +80,7 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon
LIST.load(ClockMonitor.class); LIST.load(ClockMonitor.class);
if(Functions.isMustangOrAbove()) if(Functions.isMustangOrAbove())
LIST.load(DiskSpaceMonitor.class); LIST.load(DiskSpaceMonitor.class);
LIST.load(SwapSpaceMonitor.class);
LIST.load(ArchitectureMonitor.class); LIST.load(ArchitectureMonitor.class);
} catch (Throwable e) { } catch (Throwable e) {
Logger.getLogger(NodeMonitor.class.getName()).log(Level.SEVERE, "Failed to load built-in monitors",e); Logger.getLogger(NodeMonitor.class.getName()).log(Level.SEVERE, "Failed to load built-in monitors",e);
......
package hudson.node_monitors;
import hudson.Util;
import hudson.model.Computer;
import hudson.remoting.Callable;
import net.sf.json.JSONObject;
import org.jvnet.hudson.MemoryMonitor;
import org.jvnet.hudson.MemoryUsage;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
/**
* Checks the swap space availability.
*
* @author Kohsuke Kawaguchi
* @sine 1.233
*/
public class SwapSpaceMonitor extends NodeMonitor {
public AbstractNodeMonitorDescriptor getDescriptor() {
return DESCRIPTOR;
}
/**
* Returns the HTML representation of the space.
*/
public String toHtml(MemoryUsage usage) {
if(usage.availableSwapSpace==-1)
return "N/A";
long free = usage.availableSwapSpace;
free/=1024L; // convert to KB
free/=1024L; // convert to MB
if(free>256 || usage.totalSwapSpace/usage.availableSwapSpace<5)
return usage+"MB"; // if we have more than 256MB free or less than 80% filled up, it's OK
// Otherwise considered dangerously low.
return Util.wrapToErrorSpan(usage+"MB");
}
public static final AbstractNodeMonitorDescriptor<MemoryUsage> DESCRIPTOR = new AbstractNodeMonitorDescriptor<MemoryUsage>(DiskSpaceMonitor.class) {
protected MemoryUsage monitor(Computer c) throws IOException, InterruptedException {
return c.getChannel().call(new MonitorTask());
}
public String getDisplayName() {
return "Free Swap Space";
}
@Override
public NodeMonitor newInstance(StaplerRequest req, JSONObject formData) throws FormException {
return new SwapSpaceMonitor();
}
};
/**
* Obtains the string that represents the architecture.
*/
private static class MonitorTask implements Callable<MemoryUsage,IOException> {
public MemoryUsage call() throws IOException {
return MemoryMonitor.get().monitor();
}
private static final long serialVersionUID = 1L;
}
static {
LIST.add(DESCRIPTOR);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册