本文整理匯總了Java中org.hyperic.sigar.Sigar.getCpuPerc方法的典型用法代碼示例。如果您正苦於以下問題:Java Sigar.getCpuPerc方法的具體用法?Java Sigar.getCpuPerc怎麽用?Java Sigar.getCpuPerc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hyperic.sigar.Sigar
的用法示例。
在下文中一共展示了Sigar.getCpuPerc方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCommand
import org.hyperic.sigar.Sigar; //導入方法依賴的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: updateSystemCpuUsage
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private void updateSystemCpuUsage(Sigar sigar, MachineInfo info)
{
try {
CpuPerc perc = sigar.getCpuPerc();
info.setSystemCpuUsage((float) perc.getCombined());
} catch (SigarException e) {
log.error(e.getMessage(), e);
}
}
示例3: getCpuCombined
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
/**
* CPU總使用率
*/
public static double getCpuCombined() throws SigarException {
Sigar sigar = new Sigar();
CpuPerc cpuPerc = sigar.getCpuPerc();
return new Double(df.format(cpuPerc.getCombined() * 100));
}
示例4: getNativeInfo
import org.hyperic.sigar.Sigar; //導入方法依賴的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();
}
}
示例5: main
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
System.setProperty("java.library.path", System.getProperty("java.library.path")+File.pathSeparator+"lib");
//set sys_paths to null
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);
System.out.println(System.getProperty("java.library.path"));
FileWriter fw = new FileWriter("resource_usage.csv", true);
StringJoiner stringJoiner = new StringJoiner(",");
stringJoiner.add("time");
stringJoiner.add("cpu");
stringJoiner.add("used mem");
stringJoiner.add("used mem%");
stringJoiner.add("downloaded");
stringJoiner.add("uploaded");
fw.write(stringJoiner.toString() + '\n');
fw.flush();
Sigar sigar = new Sigar();
new NetworkData(sigar);
NumberFormat formatter = new DecimalFormat("0.00", new MyDecimalFormatSymbols());
while (true) {
long start = System.currentTimeMillis();
Mem mem = sigar.getMem();
CpuPerc cpuPerc = sigar.getCpuPerc();
System.out.print(mem.getUsed() + "\t");
System.out.print(mem.getUsedPercent() + "\t");
System.out.print(formatter.format(cpuPerc.getCombined() * 100) + "\t");
Long[] metric = NetworkData.getMetric();
long downloaded = metric[0];
long uploaded = metric[1];
System.out.println("in-bound " + Sigar.formatSize(downloaded)
+ " out-bound " + Sigar.formatSize(uploaded));
System.out.println();
stringJoiner = new StringJoiner(",");
stringJoiner.add(Long.toString(start));
stringJoiner
.add(formatter.format(cpuPerc.getCombined() * 100))
.add(mem.getUsed() + "")
.add(mem.getUsedPercent() + "")
.add((downloaded) + "")
.add((uploaded) + "");
fw.write(stringJoiner.toString() + "\n");
fw.flush();
long end = System.currentTimeMillis();
Thread.sleep(Math.max(1000 - (end - start), 0));
}
}
示例6: loadSnapshot
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
@Override
CpuPerc loadSnapshot(Sigar sigar) throws SigarException {
return sigar.getCpuPerc();
}