本文整理汇总了Java中org.hyperic.sigar.ptql.ProcessFinder类的典型用法代码示例。如果您正苦于以下问题:Java ProcessFinder类的具体用法?Java ProcessFinder怎么用?Java ProcessFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcessFinder类属于org.hyperic.sigar.ptql包,在下文中一共展示了ProcessFinder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPid
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
@Override
public long findPid(BeyondJProcessQuery query, List<String> optionalArgs) throws IOException {
try {
long[] pids = ProcessFinder.find(sigar, query.getQuery());
if (pids.length > 0) {
return pids[0];
} else {
return new PureJavaProcessManager().findPid(optionalArgs);
}
} catch (Exception s1) {
try {
return new PureJavaProcessManager().findPid(optionalArgs);
} catch (Exception e) {
throw new IOException("findPid failed", s1);
}
} finally {
sigar.close();
}
}
示例2: getPids
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
public static long[] getPids(SigarProxy sigar, String[] args)
throws SigarException {
long[] pids;
switch (args.length) {
case 0:
pids = new long[] { sigar.getPid() };
break;
case 1:
if (args[0].indexOf("=") > 0) {
pids = ProcessFinder.find(sigar, args[0]);
}
else if (args[0].equals("$$")) {
pids = new long[] { sigar.getPid() };
}
else {
pids = new long[] {
Long.parseLong(args[0])
};
}
break;
default:
pids = new long[args.length];
for (int i=0; i<args.length; i++) {
pids[i] = Long.parseLong(args[i]);
}
break;
}
return pids;
}
示例3: getPIDByPTQL
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
private long getPIDByPTQL(String token) {
String query = token.substring(token.indexOf("=") + 1);
try {
@SuppressWarnings("deprecation")
long[] pids = new ProcessFinder(this.sigar).find(query);
if (pids.length < 1) {
log.warn("Unable to find process from query: " + query);
return -1L;
}
return pids[0];
} catch (SigarException ex) {
log.warn("Error querying PTQL: " + query, ex);
}
return -1L;
}
示例4: measureMemory
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的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: getAliveWithSigar
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
private Set<Integer> getAliveWithSigar(boolean printProcesses) {
Sigar sigar = new Sigar();
try {
long[] pids = new ProcessFinder(sigar).find("State.Name.eq=java,Args.*.re=" + pattern);
Set<Integer> setOfPids = new HashSet<>();
for (long pid : pids) {
setOfPids.add((int) pid);
if (printProcesses)
System.out.println("Running java processes matching regex:" + pid);
}
return setOfPids;
} catch (SigarException e) {
return Collections.emptySet();
}
}
示例6: getPid
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
private long getPid(String processName) throws SigarException {
long pid;
ProcessFinder processFinder = new ProcessFinder(sigarImpl);
String query;
if (processName.equals("$$")) {
pid = sigar.getPid();
logger.debug("Return own pid {}", pid);
return pid;
} else if (processName.startsWith("*")) {
query = "State.Name.sw=" + processName.replace("*", "");
} else if (processName.endsWith("*")) {
query = "State.Name.ew=" + processName.replace("*", "");
} else if (processName.startsWith("=")) {
query = "State.Name.eq=" + processName.replace("=", "");
} else if (processName.startsWith("#")) {
query = processName.replace("#", "");
} else {
query = "State.Name.ct=" + processName;
}
logger.debug("Query pid by '{}'", query);
pid = processFinder.findSingleProcess(query);
logger.debug("Return pid {}", pid);
return pid;
}
示例7: getPid
import org.hyperic.sigar.ptql.ProcessFinder; //导入依赖的package包/类
private long getPid(String processName) throws SigarException {
long pid;
ProcessFinder processFinder = new ProcessFinder(sigarImpl);
String query;
if (processName.equals("$$")) {
pid = sigar.getPid();
logger.debug("Return own pid {}", pid);
return pid;
} else if (processName.startsWith("*")) {
query = "State.Name.sw=" + processName.replace("*", "");
} else if (processName.endsWith("*")) {
query = "State.Name.ew=" + processName.replace("*", "");
} else if (processName.startsWith("=")) {
query = "State.Name.eq=" + processName.replace("=", "");
} else if (processName.startsWith("#")) {
query = processName.replace("#", "");
} else {
query = "State.Name.ct=" + processName;
}
logger.debug("Query pid by '{}'", query);
pid = processFinder.findSingleProcess(query);
logger.debug("Return pid {}", pid);
return pid;
}