org.hyperic.sigar.Swap Java Examples

The following examples show how to use org.hyperic.sigar.Swap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sigar.java    From sigar-system_runtime with MIT License 6 votes vote down vote up
private static void memory() throws SigarException {
    Sigar sigar = new Sigar();
    Mem mem = sigar.getMem();
    // 内存总量
    System.out.println("内存总量:    " + mem.getTotal() / 1024L + "K av");
    // 当前内存使用量
    System.out.println("当前内存使用量:    " + mem.getUsed() / 1024L + "K used");
    // 当前内存剩余量
    System.out.println("当前内存剩余量:    " + mem.getFree() / 1024L + "K free");
    Swap swap = sigar.getSwap();
    // 交换区总量
    System.out.println("交换区总量:    " + swap.getTotal() / 1024L + "K av");
    // 当前交换区使用量
    System.out.println("当前交换区使用量:    " + swap.getUsed() / 1024L + "K used");
    // 当前交换区剩余量
    System.out.println("当前交换区剩余量:    " + swap.getFree() / 1024L + "K free");
}
 
Example #2
Source File: MemSwapUsageSampler.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void sample(final IMonitoringController monitoringCtr) throws SigarException {
	if (!monitoringCtr.isMonitoringEnabled()) {
		return;
	}
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createMemSwapSignature())) {
		return;
	}

	final Mem mem = this.sigar.getMem();
	final Swap swap = this.sigar.getSwap();
	final MemSwapUsageRecord r = new MemSwapUsageRecord(
			monitoringCtr.getTimeSource().getTime(), monitoringCtr.getHostname(),
			mem.getTotal(), mem.getActualUsed(), mem.getActualFree(),
			swap.getTotal(), swap.getUsed(), swap.getFree());
	monitoringCtr.newMonitoringRecord(r);
}
 
Example #3
Source File: SigarNodeInfoProvider.java    From ankush with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Method getNodeSwapInfo.
 * 
 * @return Map<Object,Object>
 */
public Map<Object, Object> getNodeSwapInfo() {

	Swap swap = null;
	Map<Object, Object> nodeSwapInfo = new HashMap<Object, Object>();

	try {
		swap = sigar.getSwap();
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}

	nodeSwapInfo.put("freeSystemSwap", swap.getFree());
	nodeSwapInfo.put("pageIn", swap.getPageIn());
	nodeSwapInfo.put("pageOut", swap.getPageOut());
	nodeSwapInfo.put("totalSystemSwap", swap.getTotal());
	nodeSwapInfo.put("usedSystemSwap", swap.getUsed());

	return nodeSwapInfo;
}
 
Example #4
Source File: Monitor.java    From JobX with Apache License 2.0 5 votes vote down vote up
public Mem(org.hyperic.sigar.Mem mem, Swap swap) {
    this.total = mem.getTotal() / 1024;
    this.ram = mem.getRam();
    this.used = mem.getUsed() / 1024;
    this.free = mem.getFree() / 1024;
    this.actualUsed = mem.getActualUsed() / 1024;
    this.actualFree = mem.getActualFree() / 1024;
    this.usedPercent = mem.getUsedPercent() / 1024;
    this.freePercent = mem.getFreePercent() / 1024;
    this.swapTotal = swap.getTotal() / 1024;
    this.swapFree = swap.getFree() / 1024;
    this.swapUsed = swap.getUsed() / 1024;
}
 
Example #5
Source File: MachineStatsCheckerTest.java    From micro-server with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	sigar = mock(Sigar.class);
	swap = mock(Swap.class);
	cpuPerc = mock(CpuPerc.class);
	cpuInfo = mock(CpuInfo.class);
	mem = mock(Mem.class);
	
	machineStatsChecker = new MachineStatsChecker();		
}
 
Example #6
Source File: SwapMetric.java    From perfmon-agent with Apache License 2.0 5 votes vote down vote up
public void getValue(StringBuffer res) throws SigarException {
    Swap mem = sigarProxy.getSwap();
    double val;
    double cur;
    int factor = 1;
    switch (type) {
        case PAGE_IN:
            cur = mem.getPageIn();
            val = prev != -1 ? cur - prev : 0;
            prev = cur;
            break;
        case PAGE_OUT:
            cur = mem.getPageOut();
            val = prev != -1 ? cur - prev : 0;
            prev = cur;
            break;
        case FREE:
            val = mem.getFree();
            factor = dividingFactor;
            break;
        case TOTAL:
            val = mem.getTotal();
            factor = dividingFactor;
            break;
        case USED:
            val = mem.getUsed();
            factor = dividingFactor;
            break;
        default:
            throw new SigarException("Unknown swap type " + type);
    }
    val = val / factor;
    res.append(Double.toString(val));
}
 
Example #7
Source File: HttpClientTool.java    From maintain with MIT License 4 votes vote down vote up
public static Swap getSwapJson(String url) {
	return getJson(url + "swapInfo", Swap.class);
}
 
Example #8
Source File: ServerInfo.java    From maintain with MIT License 4 votes vote down vote up
public Swap getSwap() {
	return swap;
}
 
Example #9
Source File: ServerInfo.java    From maintain with MIT License 4 votes vote down vote up
public void setSwap(Swap swap) {
	this.swap = swap;
}