本文整理汇总了Java中org.hyperic.sigar.CpuPerc类的典型用法代码示例。如果您正苦于以下问题:Java CpuPerc类的具体用法?Java CpuPerc怎么用?Java CpuPerc使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CpuPerc类属于org.hyperic.sigar包,在下文中一共展示了CpuPerc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPercPerThreadStats
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
* this function calculates for each thread its load percentage, then return, in a single string, load percentage for each thread of CPU.
* <p>
* before return, this method call <code>setPercPerThreadInModel(String cpuLoad)</code> to set values in model
* @see CPUStats#setPercPerThreadInModel(String)
* @return this functions returns, in a single string, load percentage for each thread of CPU separated by a "\n".
* In case of problem return the string "0"
*/
public String getPercPerThreadStats(){
try {
CpuPerc[] cpuperclist = SigarFactory.newSigar().getCpuPercList();
genericStringBuilder.setLength(0);
for (CpuPerc aCpuperclist : cpuperclist) {
genericStringBuilder.append(GeneralStats.getInstance().round((float) (aCpuperclist.getCombined() * 100), 2)).append("\n");
}
setPercPerThreadInModel(genericStringBuilder.toString());
return genericStringBuilder.toString();
} catch (SigarException e) {
setPercPerThreadInModel("0");
e.printStackTrace();
return "0";
}
}
示例2: onCommand
import org.hyperic.sigar.CpuPerc; //导入依赖的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;
}
示例3: getCurrentWorkerStat
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public WorkerStat getCurrentWorkerStat(){
try {
CpuPerc cpp=sigar.getCpuPerc();
Mem mem=sigar.getMem();
workerStat.cpuUsage=cpp.getCombined();
workerStat.memUsed=mem.getActualUsed();
workerStat.memFree=mem.getActualFree();
workerStat.timestampMS=System.currentTimeMillis();
workerStat.instanceCount=worker.insMap.size();
return workerStat;
}
catch (SigarException e) {
e.printStackTrace();
return workerStat;
}
}
示例4: getCpuUsage
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
* Gets the cpu usage.
*
* @return the cpu usage
*/
private Object getCpuUsage() {
try {
// cpu percentage object.
CpuPerc per = sigar.getCpuPerc();
// getting the string value of percentage.
String p = String.valueOf(per.getCombined() * 100.0);
// getting index of the .
int ix = p.indexOf('.') + 1;
// getting only one digit after .
return p.substring(0, ix) + p.substring(ix, ix + 1);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
示例5: executeCommand
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
StrBuilder sb = new StrBuilder(200);
CpuPerc[] cpus = sigar.getCpuPercList();
CpuPerc cpuAll = sigar.getCpuPerc();
sb.append(TYPE_CPU_X);
sb.append(separator);
writeCpu(sb, cpuAll);
if (cpus.length > 1) { // more than one CPU
appendLineBreak(sb);
for (int i = 0; i < cpus.length; i++) {
appendLineBreak(sb, i);
sb.append(TYPE_CPU + i);
sb.append(separator);
writeCpu(sb, cpus[i]);
}
}
return sb.toString();
}
示例6: executeCommand
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
StrBuilder sb = new StrBuilder(200);
String[] type = new String[] { "State.Name.sw=java" };
long[] pids = Shell.getPids(sigar, type);
for (int i = 0; i < pids.length; i++) {
appendLineBreak(sb, i);
sb.append(TYPE_JAVA_X + i);
sb.append(separator);
long pid = pids[i];
String cpuPerc = "?";
@SuppressWarnings("unchecked")
List<Object> info = new ArrayList<Object>(Ps.getInfo(sigar, pid));
ProcCpu cpu = sigar.getProcCpu(pid);
cpuPerc = CpuPerc.format(cpu.getPercent());
info.add(info.size() - 1, cpuPerc);
sb.append(Ps.join(info));
}
return sb.toString();
}
示例7: output
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void output(CpuPerc cpu) {
println("User Time....." + CpuPerc.format(cpu.getUser()));
println("Sys Time......" + CpuPerc.format(cpu.getSys()));
println("Idle Time....." + CpuPerc.format(cpu.getIdle()));
println("Wait Time....." + CpuPerc.format(cpu.getWait()));
println("Nice Time....." + CpuPerc.format(cpu.getNice()));
println("Combined......" + CpuPerc.format(cpu.getCombined()));
println("Irq Time......" + CpuPerc.format(cpu.getIrq()));
if (SigarLoader.IS_LINUX) {
println("SoftIrq Time.." + CpuPerc.format(cpu.getSoftIrq()));
println("Stolen Time...." + CpuPerc.format(cpu.getStolen()));
}
println("");
}
示例8: output
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
String query = args[0];
MultiProcCpu cpu = this.proxy.getMultiProcCpu(query);
println("Number of processes: " + cpu.getProcesses());
println("Cpu usage: " + CpuPerc.format(cpu.getPercent()));
println("Cpu time: " + Ps.getCpuTime(cpu.getTotal()));
ProcMem mem = this.proxy.getMultiProcMem(query);
println("Size: " + Sigar.formatSize(mem.getSize()));
println("Resident: " + Sigar.formatSize(mem.getResident()));
println("Share: " + Sigar.formatSize(mem.getShare()));
}
示例9: printCpuPerc
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void printCpuPerc(CpuPerc cpu) {
System.out.println("用户使用率:" + CpuPerc.format(cpu.getUser()));// 用户使用率
System.out.println("系统使用率:" + CpuPerc.format(cpu.getSys()));// 系统使用率
System.out.println("当前等待率:" + CpuPerc.format(cpu.getWait()));// 当前等待率
System.out.println("Nice :" + CpuPerc.format(cpu.getNice()));//
System.out.println("当前空闲率:" + CpuPerc.format(cpu.getIdle()));// 当前空闲率
System.out.println("总的使用率:" + CpuPerc.format(cpu.getCombined()));// 总的使用率
System.out.println("**************");
}
示例10: getCPUUsage
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
* @desc 获取cpu使用率
*
* @author liuliang
*
* @return Double 比例(保留2位小数)
*/
public static Double getCPUUsage() {
double cpuUsage = 0;
try {
CpuPerc[] cpuList = getInstance().getCpuPercList();
// 不管是单块CPU还是多CPU都适用
for (int i = 0; i < cpuList.length; i++) {
cpuUsage += cpuList[i].getCombined() * 100;
}
cpuUsage = NumberUtil.format(cpuUsage / cpuList.length);
} catch (SigarException e) {
e.printStackTrace();
}
return cpuUsage;
}
示例11: getCPULoad
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
public double getCPULoad() {
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
return nativeOsBean.getSystemCpuLoad();
} else if (sigar != null) {
try {
CpuPerc systemCpu = sigar.getCpuPerc();
return systemCpu.getCombined();
} catch (SigarException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
return -1;
}
示例12: setUp
import org.hyperic.sigar.CpuPerc; //导入依赖的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();
}
示例13: updateSystemCpuUsage
import org.hyperic.sigar.CpuPerc; //导入依赖的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);
}
}
示例14: writeCpu
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
private void writeCpu(final StrBuilder sb, final CpuPerc cpuPerc) {
appendPercent(sb, cpuPerc.getCombined());
sb.append(separator);
appendPercent(sb, cpuPerc.getUser());
sb.append(separator);
appendPercent(sb, cpuPerc.getNice());
sb.append(separator);
appendPercent(sb, cpuPerc.getSys());
sb.append(separator);
appendPercent(sb, cpuPerc.getWait());
sb.append(separator);
appendPercent(sb, cpuPerc.getIdle());
}
示例15: getCpuCombined
import org.hyperic.sigar.CpuPerc; //导入依赖的package包/类
/**
* CPU总使用率
*/
public static double getCpuCombined() throws SigarException {
Sigar sigar = new Sigar();
CpuPerc cpuPerc = sigar.getCpuPerc();
return new Double(df.format(cpuPerc.getCombined() * 100));
}