提交 f8245685 编写于 作者: K Kohsuke Kawaguchi

When NodeMonitor is reconfigured or when the instance goes online, recompute the values.

Based on the following IRC conversations:

 (04:02:29 PM) cliffano: my build slave is offline, "Disk space is too low. Only 0.331GB left on" , but the box has 5.5Gb free.. i've tried disabling the disk space checking, restarted both master and slave, that error message is still there
 (04:03:03 PM) rtyler: I've seen that a couple times, I think I just disconnected and reconnected the slave
 (04:03:47 PM) cliffano: no dice for me.. reconnected several times.. even tried deleting more stuffs to free up more space, still exactly the same error message
 (04:04:04 PM) rtyler: you could try reinstalling windows
 (04:04:06 PM) ***rtyler ducks
 (04:04:22 PM) cliffano: lol yea
 (04:04:49 PM) kohsuke: cliffano: you can force the recomputation of those metrics
 (04:04:56 PM) kohsuke: otherwise it's only once an hour
 (04:05:17 PM) rtyler: wait, you can force it?
 (04:05:37 PM) kohsuke: http://ci.jenkins-ci.org/computer/ "refresh status"
 (04:06:26 PM) rtyler: ah
 (04:07:25 PM) cliffano: kohsuke: thanks, that worked..
 (04:07:43 PM) kohsuke: although I expect that if you've been reconnecting that should be sufficient
 (04:08:08 PM) kohsuke: And I probably should also do that automatically when you reconfigure the column, threashold, etc
 (04:10:39 PM) cliffano: kohsuke: reconnecting didn't help somehow... i tried disconnecting from the UI, tried killing the process on the slave machine, restarted etc
 (04:10:56 PM) kohsuke: it's probably caching the value
 (04:12:16 PM) cliffano: kohsuke: does it cache in the filesystem? i restarted both master and slaves
 (04:13:09 PM) kohsuke: it's stored in Computer
 (04:13:11 PM) kohsuke: so I guess that explains
 (04:13:34 PM) kohsuke: let me clear this when a slave connects
 (04:16:23 PM) cliffano: kohsuke: thanks :)
上级 fe6febb0
......@@ -318,6 +318,12 @@ public final class ComputerSet extends AbstractModelObject implements Describabl
if(i!=null)
monitors.add(i);
}
// recompute the data
for (NodeMonitor nm : monitors) {
nm.triggerUpdate();
}
rsp.sendRedirect2(".");
} finally {
bc.commit();
......
......@@ -83,6 +83,9 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon
return (AbstractNodeMonitorDescriptor<?>) Jenkins.getInstance().getDescriptorOrDie(getClass());
}
/**
* Obtains the monitoring result currently available, or null if no data is available.
*/
public Object data(Computer c) {
return getDescriptor().get(c);
}
......
package hudson.node_monitors;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.TaskListener;
import hudson.slaves.ComputerListener;
import hudson.util.DaemonThreadFactory;
import jenkins.model.Jenkins;
import java.io.IOException;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* When a slave is connected, redo the node monitoring.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class NodeMonitorUpdater extends ComputerListener {
// TODO: shutdown hook to kill off this timer
private final ScheduledExecutorService timer = new ScheduledThreadPoolExecutor(1,new DaemonThreadFactory());
private volatile long timestamp;
/**
* Triggers the update with 5 seconds quiet period, to avoid triggering data check too often
* when multiple slaves become online at about the same time.
*/
@Override
public void onOnline(Computer c, TaskListener listener) throws IOException, InterruptedException {
timestamp = System.currentTimeMillis();
timer.schedule(new Runnable() {
public void run() {
if (System.currentTimeMillis()-timestamp<4000)
return;
for (NodeMonitor nm : Jenkins.getInstance().getComputer().getMonitors()) {
nm.triggerUpdate();
}
}
}, 5, TimeUnit.SECONDS);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册