Index: src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java =================================================================== --- src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java (revision 23683) +++ src/main/java/hudson/diagnosis/HudsonHomeDiskUsageChecker.java (working copy) @@ -56,10 +56,15 @@ LOGGER.fine("Monitoring disk usage of HUDSON_HOME. total="+total+" free="+free); - // if it's more than 90% full and less than 1GB, activate + // Get the minimum amount of space to check for, with a default of 1GB + long freeSpaceTheshold = Long.getLong( + HudsonHomeDiskUsageChecker.class.getName() + ".freeSpaceTheshold", + Long.valueOf(1073741824L)); + + // if it's more than 90% full and less than the minimum, activate // it's AND and not OR so that small Hudson home won't get a warning, // and similarly, if you have a 1TB disk, you don't get a warning when you still have 100GB to go. - HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free<1024L*1024*1024); + HudsonHomeDiskUsageMonitor.get().activated = (total/free>10 && free<freeSpaceTheshold); } catch (LinkageError _) { // pre Mustang LOGGER.info("Not on JDK6. Cannot monitor HUDSON_HOME disk usage"); Index: src/main/java/hudson/node_monitors/DiskSpaceMonitor.java =================================================================== --- src/main/java/hudson/node_monitors/DiskSpaceMonitor.java (revision 23683) +++ src/main/java/hudson/node_monitors/DiskSpaceMonitor.java (working copy) @@ -29,10 +29,11 @@ import hudson.model.Computer; import hudson.model.Hudson; import hudson.node_monitors.DiskSpaceMonitorDescriptor.DiskSpace; -import net.sf.json.JSONObject; -import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.DataBoundConstructor; + import java.io.IOException; +import java.util.logging.Logger; /** * Checks available disk space of the remote FS root. @@ -42,6 +43,17 @@ * @since 1.123 */ public class DiskSpaceMonitor extends NodeMonitor { + /** + * The free space threshold, in bytes, below which the node + * monitor will be triggered. + */ + public final long freeSpaceTheshold; + + @DataBoundConstructor + public DiskSpaceMonitor(long freeSpaceTheshold) { + this.freeSpaceTheshold = freeSpaceTheshold; + } + public DiskSpace getFreeSpace(Computer c) { return DESCRIPTOR.get(c); } @@ -57,11 +69,6 @@ return Messages.DiskSpaceMonitor_DisplayName(); } - @Override - public NodeMonitor newInstance(StaplerRequest req, JSONObject formData) throws FormException { - return new DiskSpaceMonitor(); - } - protected DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException { FilePath p = c.getNode().getRootPath(); if(p==null) return null; @@ -75,4 +82,18 @@ if(Functions.isMustangOrAbove()) return DESCRIPTOR; return null; } + + @Override + public Object data(Computer c) { + DiskSpace size = (DiskSpace) super.data(c); + if(size!=null && size.size < freeSpaceTheshold) { + size.setTriggered(true); + if(DESCRIPTOR.markOffline(c,size)) { + LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName())); + } + } + return size; + } + + private static final Logger LOGGER = Logger.getLogger(DiskSpaceMonitor.class.getName()); } Index: src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java =================================================================== --- src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java (revision 23683) +++ src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java (working copy) @@ -34,7 +34,6 @@ import java.io.File; import java.io.IOException; import java.io.Serializable; -import java.util.logging.Logger; import java.math.BigDecimal; import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.export.Exported; @@ -52,6 +51,8 @@ public static final class DiskSpace extends OfflineCause implements Serializable { @Exported public final long size; + + private boolean triggered; public DiskSpace(long size) { this.size = size; @@ -80,26 +81,27 @@ long space = size; space/=1024L; // convert to KB space/=1024L; // convert to MB - if(space<1024) { + if(triggered) { // less than a GB return Util.wrapToErrorSpan(new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString()+"GB"); } return space/1024+"GB"; } - - public boolean moreThanGB() { - return size>1024L*1024*1024; + + /** + * Sets whether this disk space amount should be treated as outside + * the acceptable conditions or not. + */ + protected void setTriggered(boolean triggered) { + this.triggered = triggered; } - - private static final long serialVersionUID = 1L; + + private static final long serialVersionUID = 2L; } protected DiskSpace monitor(Computer c) throws IOException, InterruptedException { - DiskSpace size = getFreeSpace(c); - if(size!=null && !size.moreThanGB() && markOffline(c,size)) - LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName())); - return size; + return getFreeSpace(c); } /** @@ -121,6 +123,4 @@ } private static final long serialVersionUID = 1L; } - - private static final Logger LOGGER = Logger.getLogger(DiskSpaceMonitor.class.getName()); } Index: src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java =================================================================== --- src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java (revision 23683) +++ src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java (working copy) @@ -31,12 +31,13 @@ import hudson.Functions; import hudson.remoting.VirtualChannel; import hudson.FilePath.FileCallable; -import org.kohsuke.stapler.StaplerRequest; + +import org.kohsuke.stapler.DataBoundConstructor; import org.jvnet.animal_sniffer.IgnoreJRERequirement; -import net.sf.json.JSONObject; import java.io.IOException; import java.io.File; +import java.util.logging.Logger; /** * Monitors the disk space of "/tmp". @@ -44,6 +45,17 @@ * @author Kohsuke Kawaguchi */ public class TemporarySpaceMonitor extends NodeMonitor { + /** + * The free space threshold, in bytes, below which the node + * monitor will be triggered. + */ + public final long freeSpaceTheshold; + + @DataBoundConstructor + public TemporarySpaceMonitor(long freeSpaceTheshold) { + this.freeSpaceTheshold = freeSpaceTheshold; + } + public DiskSpace getFreeSpace(Computer c) { return DESCRIPTOR.get(c); } @@ -59,11 +71,6 @@ return Messages.TemporarySpaceMonitor_DisplayName(); } - @Override - public NodeMonitor newInstance(StaplerRequest req, JSONObject formData) throws FormException { - return new TemporarySpaceMonitor(); - } - protected DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException { FilePath p = c.getNode().getRootPath(); if(p==null) return null; @@ -77,6 +84,20 @@ if(Functions.isMustangOrAbove()) return DESCRIPTOR; return null; } + + @Override + public Object data(Computer c) { + DiskSpace size = (DiskSpace) super.data(c); + if(size!=null && size.size < freeSpaceTheshold) { + size.setTriggered(true); + if(DESCRIPTOR.markOffline(c,size)) { + LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName())); + } + } + return size; + } + + private static final Logger LOGGER = Logger.getLogger(TemporarySpaceMonitor.class.getName()); protected static final class GetTempSpace implements FileCallable<DiskSpace> { @IgnoreJRERequirement Index: src/main/resources/hudson/node_monitors/DiskSpaceMonitor/config.jelly =================================================================== --- src/main/resources/hudson/node_monitors/DiskSpaceMonitor/config.jelly (revision 0) +++ src/main/resources/hudson/node_monitors/DiskSpaceMonitor/config.jelly (revision 0) @@ -0,0 +1,30 @@ +<!-- +The MIT License + +Copyright (c) 2004-2009, Sun Microsystems, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +--> +<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> + <f:advanced> + <f:entry title="${%Free Space Threshold}" field="freeSpaceTheshold"> + <f:textbox default="1073741824"/> + </f:entry> + </f:advanced> +</j:jelly> \ No newline at end of file Index: src/main/resources/hudson/node_monitors/DiskSpaceMonitor/help-freeSpaceTheshold.html =================================================================== --- src/main/resources/hudson/node_monitors/DiskSpaceMonitor/help-freeSpaceTheshold.html (revision 0) +++ src/main/resources/hudson/node_monitors/DiskSpaceMonitor/help-freeSpaceTheshold.html (revision 0) @@ -0,0 +1,5 @@ +<div> + This option configures the amount of minimum amount of free disk space, in + bytes, desired for a slave's proper operation. If a slave is found to + have less free disk space than this amount, it will be marked offline. +</div> \ No newline at end of file Index: src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/config.jelly =================================================================== --- src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/config.jelly (revision 0) +++ src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/config.jelly (revision 0) @@ -0,0 +1,30 @@ +<!-- +The MIT License + +Copyright (c) 2004-2009, Sun Microsystems, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +--> +<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> + <f:advanced> + <f:entry title="${%Free Space Threshold}" field="freeSpaceTheshold"> + <f:textbox default="1073741824"/> + </f:entry> + </f:advanced> +</j:jelly> \ No newline at end of file Index: src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/help-freeSpaceTheshold.html =================================================================== --- src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/help-freeSpaceTheshold.html (revision 0) +++ src/main/resources/hudson/node_monitors/TemporarySpaceMonitor/help-freeSpaceTheshold.html (revision 0) @@ -0,0 +1,5 @@ +<div> + This option configures the amount of minimum amount of free disk space, in + bytes, desired for a slave's proper operation. If a slave is found to + have less free disk space than this amount, it will be marked offline. +</div> \ No newline at end of file