All pastes #824540 Raw Edit

skalman

public text v1 · immutable
·published 2007-12-20 00:54 UTC
rendered paste body
    public static void fillEnvSlaveStatus(ReplacerEnvironment env,
            SlaveStatus status, SlaveManager slaveManager) {
        env.add("disktotal", Bytes.formatBytes(status.getDiskSpaceCapacity()));
        env.add("disktotalm", Bytes.formatBytesToMega(status.getDiskSpaceCapacity()));
        env.add("diskfree", Bytes.formatBytes(status.getDiskSpaceAvailable()));
        env.add("diskfreem", Bytes.formatBytesToMega(status.getDiskSpaceAvailable()));
        env.add("diskused", Bytes.formatBytes(status.getDiskSpaceUsed()));
        env.add("diskusedm", Bytes.formatBytesToMega(status.getDiskSpaceUsed()));

        if (status.getDiskSpaceCapacity() == 0) {
            env.add("diskfreepercent", "n/a");
            env.add("diskusedpercent", "n/a");
        } else {
            env.add("diskfreepercent",
                    ((status.getDiskSpaceAvailable() * 100) / status.getDiskSpaceCapacity()) + "%");
            env.add("diskusedpercent",
                    ((status.getDiskSpaceUsed() * 100) / status.getDiskSpaceCapacity()) + "%");
        }

        env.add("xfers", "" + status.getTransfers());
        env.add("xfersdn", "" + status.getTransfersSending());
        env.add("xfersup", "" + status.getTransfersReceiving());
        env.add("xfersdown", "" + status.getTransfersSending());

		long throughputReceiving = 0;
		long throughputSending = 0;
		int i = 0;
		while (true) {
			long tmpThroughputReceiving = status.getThroughputReceiving();
			long tmpThroughputSending = status.getThroughputSending();
			if (tmpThroughputReceiving > throughputReceiving)
				throughputReceiving = tmpThroughputReceiving;
			if (tmpThroughputSending > throughputSending)
				throughputSending = tmpThroughputSending;
			if (i == 15)
				break;
			else {
				try {
					Thread.sleep(100);
				} catch (Exception ee) { }
			}
			status = slaveManager.getAllStatus();
			i++;
		}
        env.add("throughput", Bytes.formatBytes(throughputReceiving + throughputSending) + "/s");
        env.add("throughputm", Bytes.formatBytesToMega(throughputReceiving + throughputSending));

        env.add("throughputup",
                Bytes.formatBytes(throughputReceiving) + "/s");
        env.add("throughputupm",
                Bytes.formatBytesToMega(throughputReceiving));

        env.add("throughputdown",
                Bytes.formatBytes(throughputSending) + "/s");
        env.add("throughputdownm",
                Bytes.formatBytesToMega(throughputSending));

        try {
            env.add("slaves", "" + slaveManager.getAvailableSlaves().size());
        } catch (NoAvailableSlaveException e2) {
            env.add("slaves", "0");
        }
    }