本文整理汇总了Java中org.hyperic.sigar.Mem.getUsed方法的典型用法代码示例。如果您正苦于以下问题:Java Mem.getUsed方法的具体用法?Java Mem.getUsed怎么用?Java Mem.getUsed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hyperic.sigar.Mem
的用法示例。
在下文中一共展示了Mem.getUsed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCommand
import org.hyperic.sigar.Mem; //导入方法依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!isAllowed(sender, command)) {
sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
return true;
}
if (!plugin.getConfig().getBoolean("native-library")) {
sender.sendMessage(ChatColor.DARK_RED + "Native support is disabled");
return true;
}
//swap and load is already available in the environment command because MBeans already supports this
Sigar sigar = plugin.getNativeData().getSigar();
try {
int uptime = (int) sigar.getUptime().getUptime();
sender.sendMessage(PRIMARY_COLOR + "OS Uptime: " + SECONDARY_COLOR + formatUptime(uptime));
CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
int mhz = cpuInfoList[0].getMhz();
sender.sendMessage(PRIMARY_COLOR + "CPU MHZ: " + SECONDARY_COLOR + mhz);
CpuPerc cpuPerc = sigar.getCpuPerc();
//IO wait
double wait = cpuPerc.getWait();
sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');
Mem mem = sigar.getMem();
//included cache
long actualUsed = mem.getActualUsed();
long used = mem.getUsed();
long cache = used - actualUsed;
sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));
printNetworkInfo(sender, sigar);
//disk read write
List<String> diskNames = Arrays.stream(sigar.getFileSystemList())
.map(FileSystem::getDevName)
.filter(name -> name.startsWith("/dev/sd"))
.distinct()
.collect(Collectors.toList());
Collection<DiskUsage> diskUsages = new ArrayList<>();
for (String diskName : diskNames) {
diskUsages.add(sigar.getDiskUsage(diskName));
}
long diskReads = diskUsages.stream().mapToLong(DiskUsage::getReadBytes).sum();
long diskWrites = diskUsages.stream().mapToLong(DiskUsage::getWriteBytes).sum();
String diskReadBytes = Sigar.formatSize(diskReads);
String diskWriteBytes = Sigar.formatSize(diskWrites);
sender.sendMessage(PRIMARY_COLOR + "Disk read bytes: " + SECONDARY_COLOR + diskReadBytes);
sender.sendMessage(PRIMARY_COLOR + "Disk write bytes: " + SECONDARY_COLOR + diskWriteBytes);
sender.sendMessage(PRIMARY_COLOR + "Filesystems:");
for (FileSystem fileSystem : sigar.getFileSystemList()) {
String dirName = fileSystem.getDirName();
String typeName = fileSystem.getSysTypeName();
sender.sendMessage(PRIMARY_COLOR + dirName + " - " + SECONDARY_COLOR + typeName);
}
} catch (SigarException sigarException) {
plugin.getLogger().log(Level.SEVERE, null, sigarException);
}
return true;
}
示例2: output
import org.hyperic.sigar.Mem; //导入方法依赖的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" });
}
示例3: osMemStats
import org.hyperic.sigar.Mem; //导入方法依赖的package包/类
/**
* Generate memory statistics
* http://casidiablo.net/capturar-informacion-sistema-operativo-java/
*/
public JFreeChart osMemStats() throws IOException, ServletException {
DefaultPieDataset dataset = new DefaultPieDataset();
Sigar sigar = new Sigar();
String title = null;
try {
Mem mem = sigar.getMem();
long max = mem.getRam();
long available = mem.getFree();
long total = mem.getTotal();
long used = mem.getUsed();
long free = mem.getFree();
title = "OS memory: " + FormatUtil.formatSize(total);
log.debug("OS maximun memory: {}", FormatUtil.formatSize(max));
log.debug("OS available memory: {}", FormatUtil.formatSize(available));
log.debug("OS free memory: {}", FormatUtil.formatSize(free));
log.debug("OS used memory: {}", FormatUtil.formatSize(used));
log.debug("OS total memory: {}", FormatUtil.formatSize(total));
dataset.setValue("Available (" + FormatUtil.formatSize(free) + ")", free * 100 / total);
dataset.setValue("Used (" + FormatUtil.formatSize(used) + ")", used * 100 / total);
} catch (SigarException se) {
title = "OS memory: " + se.getMessage();
} catch (UnsatisfiedLinkError ule) {
title = "OS memory: (missing native libraries)";
}
return ChartFactory.createPieChart(title, dataset, true, false, false);
}
示例4: getMemoryUsed
import org.hyperic.sigar.Mem; //导入方法依赖的package包/类
/**
* 已用物理内存
*/
public static long getMemoryUsed() throws SigarException {
Sigar sigar = new Sigar();
Mem mem = sigar.getMem();
return mem.getUsed() / 1024 / 1024; // MB
}
示例5: getNativeInfo
import org.hyperic.sigar.Mem; //导入方法依赖的package包/类
public static void getNativeInfo() {
Sigar sigar = new Sigar();
try {
int uptime = (int) sigar.getUptime().getUptime();
CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
int mhz = cpuInfoList[0].getMhz();
CpuPerc cpuPerc = sigar.getCpuPerc();
//IO wait
double wait = cpuPerc.getWait();
Mem mem = sigar.getMem();
//included cache
long actualUsed = mem.getActualUsed();
long used = mem.getUsed();
long cache = used - actualUsed;
//net upload download
NetInterfaceStat usedNetInterfaceStat = null;
String[] netInterfaceList = sigar.getNetInterfaceList();
for (String interfaceName : netInterfaceList) {
NetInterfaceStat interfaceStat = sigar.getNetInterfaceStat(interfaceName);
if (interfaceStat.getRxBytes() != 0) {
usedNetInterfaceStat = interfaceStat;
break;
}
}
if (usedNetInterfaceStat != null) {
long speed = usedNetInterfaceStat.getSpeed();
long receivedBytes = usedNetInterfaceStat.getRxBytes();
long sentBytes = usedNetInterfaceStat.getTxBytes();
}
String rootFileSystem = File.listRoots()[0].getAbsolutePath();
FileSystemUsage fileSystemUsage = sigar.getFileSystemUsage(rootFileSystem);
long diskReadBytes = fileSystemUsage.getDiskReadBytes();
long diskWriteBytes = fileSystemUsage.getDiskWriteBytes();
} catch (SigarException ex) {
Logger.getLogger(NativeStats.class.getName()).log(Level.SEVERE, null, ex);
} finally {
sigar.close();
}
}
示例6: getValue
import org.hyperic.sigar.Mem; //导入方法依赖的package包/类
@Override
public void getValue(StringBuffer res) throws SigarException {
Mem mem = this.sigarProxy.getMem();
int factor = 1;
double val;
switch (this.type) {
case 0:
val = mem.getActualFree();
factor = this.dividingFactor;
break;
case 1:
val = mem.getActualUsed();
factor = this.dividingFactor;
break;
case 2:
val = mem.getFree();
factor = this.dividingFactor;
break;
case 3:
val = mem.getFreePercent();
break;
case 4:
val = mem.getRam();
break;
case 5:
val = mem.getTotal();
factor = this.dividingFactor;
break;
case 6:
val = mem.getUsed();
factor = this.dividingFactor;
break;
case 7:
val = mem.getUsedPercent();
break;
default:
throw new SigarException("Unknown total mem type " + this.type);
}
val /= factor;
res.append(Double.toString(val));
}