use of org.hyperic.sigar.CpuInfo in project graylog2-server by Graylog2.
the class SigarOsProbe method osStats.
@Override
public OsStats osStats() {
final Sigar sigar = sigarService.sigar();
double[] loadAverage;
try {
loadAverage = sigar.getLoadAverage();
} catch (SigarException e) {
loadAverage = OsStats.EMPTY_LOAD;
}
long uptime;
try {
uptime = (long) sigar.getUptime().getUptime();
} catch (SigarException e) {
uptime = -1L;
}
Processor processor;
try {
final CpuInfo[] cpuInfos = sigar.getCpuInfoList();
final String vendor = cpuInfos[0].getVendor();
final String model = cpuInfos[0].getModel();
final int mhz = cpuInfos[0].getMhz();
final int totalCores = cpuInfos[0].getTotalCores();
final int totalSockets = cpuInfos[0].getTotalSockets();
final int coresPerSocket = cpuInfos[0].getCoresPerSocket();
long cacheSize = -1L;
if (cpuInfos[0].getCacheSize() != Sigar.FIELD_NOTIMPL) {
cacheSize = cpuInfos[0].getCacheSize();
}
final CpuPerc cpuPerc = sigar.getCpuPerc();
final short sys = (short) (cpuPerc.getSys() * 100);
final short user = (short) (cpuPerc.getUser() * 100);
final short idle = (short) (cpuPerc.getIdle() * 100);
final short stolen = (short) (cpuPerc.getStolen() * 100);
processor = Processor.create(model, vendor, mhz, totalCores, totalSockets, coresPerSocket, cacheSize, sys, user, idle, stolen);
} catch (SigarException e) {
processor = Processor.create("Unknown", "Unknown", -1, -1, -1, -1, -1L, (short) -1, (short) -1, (short) -1, (short) -1);
}
Memory memory;
try {
Mem mem = sigar.getMem();
long total = mem.getTotal();
long free = mem.getFree();
short freePercent = (short) mem.getFreePercent();
long used = mem.getUsed();
short usedPercent = (short) mem.getUsedPercent();
long actualFree = mem.getActualFree();
long actualUsed = mem.getActualUsed();
memory = Memory.create(total, free, freePercent, used, usedPercent, actualFree, actualUsed);
} catch (SigarException e) {
memory = Memory.create(-1L, -1L, (short) -1, -1L, (short) -1, -1L, -1L);
}
Swap swap;
try {
org.hyperic.sigar.Swap sigSwap = sigar.getSwap();
long total = sigSwap.getTotal();
long free = sigSwap.getFree();
long used = sigSwap.getUsed();
swap = Swap.create(total, free, used);
} catch (SigarException e) {
swap = Swap.create(-1L, -1L, -1L);
}
return OsStats.create(loadAverage, uptime, processor, memory, swap);
}
use of org.hyperic.sigar.CpuInfo in project ats-framework by Axway.
the class MachineDescriptionOperations method getInfoFromSigar.
private StringBuilder getInfoFromSigar() throws Exception {
StringBuilder sb = new StringBuilder();
Sigar sigar = new Sigar();
sb.append("Fully Qualified Domain Name:\n\t" + sigar.getFQDN().toString());
sb.append("\nSystem uptime:\n\t" + new Double(sigar.getUptime().getUptime()).intValue() + " seconds");
sb.append("\nDate:\n\t" + new Date());
sb.append("\nNetwork settings:" + format(sigar.getNetInfo().toString(), 1));
sb.append("\nCPU info:");
CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
for (int i = 0; i < cpuInfoList.length; i++) {
CpuInfo cpuInfo = cpuInfoList[i];
sb.append("\n\tCPU " + i + ": ");
sb.append(format(cpuInfo.toString(), 2));
}
double totalMemory = (new Long(sigar.getMem().getTotal()).doubleValue() / 1024 / 1024 / 1024);
sb.append("\nTotal memory:\n\t" + new BigDecimal(totalMemory).setScale(2, BigDecimal.ROUND_DOWN).floatValue() + " GB");
String[] nicList = sigar.getNetInterfaceList();
sb.append("\nNIC info: ");
for (int i = 0; i < nicList.length; i++) {
NetInterfaceConfig nic = sigar.getNetInterfaceConfig(nicList[i]);
sb.append("\n\tNIC " + i + ": ");
sb.append(format(nic.toString(), 2));
}
FileSystem[] fileSystemList = sigar.getFileSystemList();
sb.append("\nFile system info: ");
for (int i = 0; i < fileSystemList.length; i++) {
FileSystem fileSystem = fileSystemList[i];
sb.append("\n\t" + fileSystem.getDevName() + " is a");
if (fileSystem.getType() == FileSystem.TYPE_LOCAL_DISK) {
sb.append(" local");
} else if (fileSystem.getType() == FileSystem.TYPE_NETWORK) {
sb.append(" network");
} else if (fileSystem.getType() == FileSystem.TYPE_RAM_DISK) {
sb.append(" ram disk");
} else if (fileSystem.getType() == FileSystem.TYPE_SWAP) {
sb.append(" swap");
}
sb.append(" " + fileSystem.getSysTypeName() + ", dir name '" + fileSystem.getDirName() + "', options '" + fileSystem.getOptions() + "'");
}
sb.append("\nResource limits:" + format(sigar.getResourceLimit().toString(), "max", 1));
return sb;
}
Aggregations