本文整理汇总了Java中org.hyperic.sigar.Swap类的典型用法代码示例。如果您正苦于以下问题:Java Swap类的具体用法?Java Swap怎么用?Java Swap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Swap类属于org.hyperic.sigar包,在下文中一共展示了Swap类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNodeSwapInfo
import org.hyperic.sigar.Swap; //导入依赖的package包/类
/**
* 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;
}
示例2: executeCommand
import org.hyperic.sigar.Swap; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
StrBuilder sb = new StrBuilder(200);
Swap swap = sigar.getSwap();
sb.append(TYPE_SWAP);
sb.append(separator);
sb.append(swap.getTotal() / 1024L);
sb.append(separator);
sb.append(swap.getUsed() / 1024L);
sb.append(separator);
sb.append(swap.getFree() / 1024L);
return sb.toString();
}
示例3: output
import org.hyperic.sigar.Swap; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
Mem mem = this.sigar.getMem();
Swap swap = this.sigar.getSwap();
Object[] header = new Object[] { "total", "used", "free" };
Object[] memRow = new Object[] {
format(mem.getTotal()),
format(mem.getUsed()),
format(mem.getFree())
};
Object[] actualRow = new Object[] {
format(mem.getActualUsed()),
format(mem.getActualFree())
};
Object[] swapRow = new Object[] {
format(swap.getTotal()),
format(swap.getUsed()),
format(swap.getFree())
};
printf("%18s %10s %10s", header);
printf("Mem: %10ld %10ld %10ld", memRow);
//e.g. linux
if ((mem.getUsed() != mem.getActualUsed()) ||
(mem.getFree() != mem.getActualFree()))
{
printf("-/+ buffers/cache: " + "%10ld %10d", actualRow);
}
printf("Swap: %10ld %10ld %10ld", swapRow);
printf("RAM: %10ls", new Object[] { mem.getRam() + "MB" });
}
示例4: getPhysicalMemory
import org.hyperic.sigar.Swap; //导入依赖的package包/类
/**
* 2.内存资源信息
*/
public void getPhysicalMemory() {
// a)物理内存信息
DecimalFormat df = new DecimalFormat("#0.00");
Sigar sigar = new Sigar();
Mem mem;
try {
mem = sigar.getMem();
// 内存总量
System.out.println("内存总量:" + df.format((float) mem.getTotal() / 1024 / 1024 / 1024) + "G");
// 当前内存使用量
System.out.println("当前内存使用量:" + df.format((float) mem.getUsed() / 1024 / 1024 / 1024) + "G");
// 当前内存剩余量
System.out.println("当前内存剩余量:" + df.format((float) mem.getFree() / 1024 / 1024 / 1024) + "G");
// b)系统页面文件交换区信息
Swap swap = sigar.getSwap();
// 交换区总量
System.out.println("交换区总量:" + df.format((float) swap.getTotal() / 1024 / 1024 / 1024) + "G");
// 当前交换区使用量
System.out.println("当前交换区使用量:" + df.format((float) swap.getUsed() / 1024 / 1024 / 1024) + "G");
// 当前交换区剩余量
System.out.println("当前交换区剩余量:" + df.format((float) swap.getFree() / 1024 / 1024 / 1024) + "G");
} catch (SigarException e) {
e.printStackTrace();
}
}
示例5: totalSwap
import org.hyperic.sigar.Swap; //导入依赖的package包/类
/**
* 获取交换区总大小
*/
public static long totalSwap() throws SigarException{
if(staticResource.totalSwap == null){
Swap swap = sigar.getSwap();
staticResource.totalSwap = (long)(swap.getTotal()/1048576);
}
return staticResource.totalSwap;
}
示例6: getValue
import org.hyperic.sigar.Swap; //导入依赖的package包/类
@Override
public void getValue(StringBuffer res) throws SigarException {
Swap mem = this.sigarProxy.getSwap();
int factor = 1;
double cur;
double val;
switch (this.type) {
case 0:
cur = mem.getPageIn();
val = this.prev != -1.0D ? cur - this.prev : 0.0D;
this.prev = cur;
break;
case 1:
cur = mem.getPageOut();
val = this.prev != -1.0D ? cur - this.prev : 0.0D;
this.prev = cur;
break;
case 2:
val = mem.getFree();
factor = this.dividingFactor;
break;
case 3:
val = mem.getTotal();
factor = this.dividingFactor;
break;
case 4:
val = mem.getUsed();
factor = this.dividingFactor;
break;
default:
throw new SigarException("Unknown swap type " + this.type);
}
val /= factor;
res.append(Double.toString(val));
}
示例7: getFreeSwap
import org.hyperic.sigar.Swap; //导入依赖的package包/类
public long getFreeSwap() {
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
return nativeOsBean.getFreeSwapSpaceSize();
} else if (sigar != null) {
try {
Swap swap = sigar.getSwap();
return swap.getFree();
} catch (SigarException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
return -1;
}
示例8: getTotalSwap
import org.hyperic.sigar.Swap; //导入依赖的package包/类
public long getTotalSwap() {
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
return nativeOsBean.getTotalSwapSpaceSize();
} else if (sigar != null) {
try {
Swap swap = sigar.getSwap();
return swap.getTotal();
} catch (SigarException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
return -1;
}
示例9: setUp
import org.hyperic.sigar.Swap; //导入依赖的package包/类
@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();
}
示例10: freeSwap
import org.hyperic.sigar.Swap; //导入依赖的package包/类
/**
* 获取交换区剩余
*/
public static long freeSwap() throws SigarException{
Swap swap = sigar.getSwap();
return (long)(swap.getFree()/1048576);
}
示例11: getSwap
import org.hyperic.sigar.Swap; //导入依赖的package包/类
public static Swap getSwap() throws SigarException {
_init();
return sigar.getSwap();
}
示例12: getMemInfo
import org.hyperic.sigar.Swap; //导入依赖的package包/类
public static MemInfo getMemInfo() {
LOGGER.debug("Getting memory info...");
try {
Mem mem = sigar.getMem();
Swap swap = sigar.getSwap();
MemInfo memInfo = new MemInfo(mem.getTotal(), mem.getActualUsed(), mem.getActualFree(), swap.getTotal() - mem.getTotal(), swap.getUsed()
- mem.getActualUsed(), swap.getFree());
LOGGER.debug("Memory info: {}", memInfo);
return memInfo;
} catch (SigarException e) {
throw new AgentException("Error reading memory info", e);
}
}
示例13: sendRAMEvent
import org.hyperic.sigar.Swap; //导入依赖的package包/类
private void sendRAMEvent() throws JMSException, SigarException {
log.finer("Starting to collect RAM event");
final RAMEvent event = new RAMEvent();
initializeBaseEventProperties(event);
event.setHostId(hostId);
if (sunOsMX == null) {
final Runtime runtime = Runtime.getRuntime();
event.setMaxMemory(runtime.maxMemory());
event.setFreeMemory(runtime.freeMemory());
event.setUsedMemory(event.getMaxMemory() - event.getFreeMemory());
} else {
event.setFreeMemory(sunOsMX.getFreePhysicalMemorySize());
event.setMaxMemory(sunOsMX.getTotalPhysicalMemorySize());
event.setUsedMemory(event.getMaxMemory() - event.getFreeMemory());
event.setCommitedMemory(sunOsMX.getCommittedVirtualMemorySize());
event.setFreeSwapMemory(sunOsMX.getFreeSwapSpaceSize());
event.setMaxSwapMemory(sunOsMX.getTotalSwapSpaceSize());
event.setUsedSwapMemory(event.getMaxSwapMemory() - event.getFreeSwapMemory());
}
// Sigar
if (sigar != null) {
final Mem memory = sigar.getMem();
final Swap swap = sigar.getSwap();
// getActual* doesn't take buffers/caches into account, but
// doesn' match the behavior of runtime/sunOsMX
// event.setFreeMemory(memory.getActualFree());
// event.setUsedMemory(memory.getActualUsed());
event.setFreeMemory(memory.getFree());
event.setMaxMemory(memory.getTotal());
event.setUsedMemory(memory.getUsed());
event.setFreeSwapMemory(swap.getFree());
event.setMaxSwapMemory(swap.getTotal());
event.setUsedSwapMemory(swap.getUsed());
}
log.finer("Current RAM usage is " + event.getUsedMemory());
getMqHelper().sendEvent(event);
log.finer("Successfully sent RAM event");
}
示例14: loadSnapshot
import org.hyperic.sigar.Swap; //导入依赖的package包/类
@Override
Swap loadSnapshot(Sigar sigar) throws SigarException {
return sigar.getSwap();
}