本文整理汇总了Java中org.hyperic.sigar.ProcMem类的典型用法代码示例。如果您正苦于以下问题:Java ProcMem类的具体用法?Java ProcMem怎么用?Java ProcMem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProcMem类属于org.hyperic.sigar包,在下文中一共展示了ProcMem类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collectMetrics
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
private void collectMetrics()
{
logger.debug("Collecting metrics...");
try
{
//get process CPU usage
ProcCpu procCpu = sigar.getProcCpu(pid);
//get process memory usage
ProcMem procMem = sigar.getProcMem(pid);
// get network interface stats
NetInterfaceStat netStat = sigar.getNetInterfaceStat(interfaceName);
ProcessMetrics measurement = new ProcessMetrics(procCpu.getPercent(),
procMem.getSize(), procMem.getResident(), procMem.getPageFaults(),
interfaceName, netStat.getRxBytes(), netStat.getTxBytes());
metrics.add(measurement);
} catch(SigarException ex)
{
logger.error(ex.getMessage(), ex);
}
}
示例2: main
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Sigar sigar = new Sigar();
if (args.length != 1) {
throw new Exception("Usage: MemWatch pid");
}
long pid = Long.parseLong(args[0]);
long lastTime = System.currentTimeMillis();
ProcMem last = sigar.getProcMem(pid);
while (true) {
ProcMem cur = sigar.getProcMem(pid);
StringBuffer diff = diff(last, cur);
if (diff.length() == 0) {
System.out.println("no change " +
"(size=" +
Sigar.formatSize(cur.getSize()) +
")");
}
else {
long curTime = System.currentTimeMillis();
long timeDiff = curTime - lastTime;
lastTime = curTime;
diff.append(" after " + timeDiff + "ms");
System.out.println(diff);
}
last = cur;
Thread.sleep(SLEEP_TIME);
}
}
示例3: output
import org.hyperic.sigar.ProcMem; //导入依赖的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()));
}
示例4: measureMemory
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
private void measureMemory(String id, String uid, Collector collector) throws Exception {
// see https://support.hyperic.com/display/SIGAR/PTQL
Sigar sigar = new Sigar();
final ProcessFinder processFinder = new ProcessFinder(sigar);
long pid = processFinder.findSingleProcess("State.Name.eq=java,Args.1.ct="+uid);
Jcmd.gc(pid);
ProcMem procMem = sigar.getProcMem(pid);
long rss = procMem.getResident();
collector.onMeasurement(id, Measure.RSS_AFTER_INVOCATION, bytesToMegabytes(rss));
long javaHeap = Jstat.usedHeap(pid);
collector.onMeasurement(id, Measure.JAVA_HEAP_AFTER_INVOCATION, bytesToMegabytes(javaHeap));
}
示例5: main
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
public static void main(String[] args) throws SigarException {
ProcMem mem = sigar.getProcMem(SysJMX.getProcessPID());
System.out.println(Sigar.formatSize(mem.getSize()));
System.out.println(Sigar.formatSize(mem.getResident()));
System.out.println(Sigar.formatSize(mem.getRss()));
System.out.println(Sigar.formatSize(mem.getShare()));
System.out.println(Sigar.formatSize(mem.getVsize()));
}
示例6: getVirtualMemSizeMb
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
@Override
public double getVirtualMemSizeMb() {
return units.map(memory, ProcMem::getSize, 0L) / ONE_MEGABYTE;
}
示例7: getResidentMemSizeMb
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
@Override
public double getResidentMemSizeMb() {
return units.map(memory, ProcMem::getResident, 0L) / ONE_MEGABYTE;
}
示例8: getShareMemSizeMb
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
@Override
public double getShareMemSizeMb() {
return units.map(memory, ProcMem::getShare, 0L) / ONE_MEGABYTE;
}
示例9: getValue
import org.hyperic.sigar.ProcMem; //导入依赖的package包/类
@Override
public void getValue(StringBuffer res) throws SigarException {
ProcMem mem = this.sigarProxy.getProcMem(this.params.PID);
int factor = 1;
double val;
long cur;
switch (this.type) {
case 0:
val = mem.getSize();
factor = this.dividingFactor;
break;
case 1:
cur = mem.getShare();
this.prev = cur;
val = cur;
factor = this.dividingFactor;
break;
case 2:
cur = mem.getPageFaults();
val = this.prev > 0.0D ? cur - this.prev : 0.0D;
this.prev = cur;
break;
case 3:
cur = mem.getMajorFaults();
val = this.prev > 0.0D ? cur - this.prev : 0.0D;
this.prev = cur;
break;
case 4:
cur = mem.getMinorFaults();
val = this.prev > 0.0D ? cur - this.prev : 0.0D;
this.prev = cur;
break;
case 5:
cur = mem.getResident();
this.prev = cur;
val = cur;
factor = this.dividingFactor;
break;
default:
throw new SigarException("Unknown proc mem type " + this.type);
}
val /= factor;
res.append(Double.toString(val));
}