本文整理匯總了Java中org.hyperic.sigar.Sigar.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Sigar.close方法的具體用法?Java Sigar.close怎麽用?Java Sigar.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hyperic.sigar.Sigar
的用法示例。
在下文中一共展示了Sigar.close方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPlatformName
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
/**
* 3.操作係統信息
*/
// a)取到當前操作係統的名稱:
public String getPlatformName() {
String hostname = "";
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (Exception exc) {
Sigar sigar = new Sigar();
try {
hostname = sigar.getNetInfo().getHostName();
} catch (SigarException e) {
hostname = "localhost.unknown";
} finally {
sigar.close();
}
}
return hostname;
}
示例2: getStats
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
public MachineStats getStats(Sigar sigar) {
CpuStats cpuStats = CpuStats.builder()
.build();
SwapStats swapStats = SwapStats.builder()
.build();
MemoryStats memoryStats = MemoryStats.builder()
.build();
try {
swapStats = getSwapStats(sigar);
cpuStats = getCpuStats(sigar);
getMemoryStats(sigar);
} catch (SigarException | UnsatisfiedLinkError e) {
logger.error("Error during sigar stats operation", e);
} finally {
sigar.close();
}
return getMachineStats(swapStats, cpuStats, memoryStats);
}
示例3: getenv
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private static String getenv(String key) {
try {
return System.getenv("ANT_HOME"); //check for junit.jar
} catch (Error e) {
/*1.4*/
Sigar sigar = new Sigar();
try {
return sigar.getProcEnv("$$", "ANT_HOME");
} catch (Exception se) {
return null;
}
finally { sigar.close(); }
}
}
示例4: getCpuCount
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
/**
* 1.CPU資源信息
*/
// a)CPU數量(單位:個)
public static int getCpuCount() throws SigarException {
Sigar sigar = new Sigar();
try {
return sigar.getCpuInfoList().length;
} finally {
sigar.close();
}
}
示例5: cpuStats
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
CpuStats cpuStats(Sigar sigar) {
try {
return getCpuStats(sigar);
} catch (SigarException | UnsatisfiedLinkError e) {
logger.error("Error during sigar stats operation", e);
} finally {
sigar.close();
}
return CpuStats.builder()
.build();
}
示例6: printNativeInfo
import org.hyperic.sigar.Sigar; //導入方法依賴的package包/類
private static void printNativeInfo(PrintStream os) {
String version =
"java=" + Sigar.VERSION_STRING +
", native=" + Sigar.NATIVE_VERSION_STRING;
String build =
"java=" + Sigar.BUILD_DATE +
", native=" + Sigar.NATIVE_BUILD_DATE;
String scm =
"java=" + Sigar.SCM_REVISION +
", native=" + Sigar.NATIVE_SCM_REVISION;
String archlib =
SigarLoader.getNativeLibraryName();
os.println("Sigar version......." + version);
os.println("Build date.........." + build);
os.println("SCM rev............." + scm);
String host = getHostName();
String fqdn;
Sigar sigar = new Sigar();
try {
File lib = sigar.getNativeLibrary();
if (lib != null) {
archlib = lib.getName();
}
fqdn = sigar.getFQDN();
} catch (SigarException e) {
fqdn = "unknown";
} finally {
sigar.close();
}
os.println("Archlib............." + archlib);
os.println("Current fqdn........" + fqdn);
if (!fqdn.equals(host)) {
os.println("Hostname............" + host);
}
if (SigarLoader.IS_WIN32) {
LocaleInfo info = new LocaleInfo();
os.println("Language............" + info);
os.println("Perflib lang id....." +
info.getPerflibLangId());
}
}
示例7: 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();
}
}