use of org.hyperic.sigar.FileSystem in project openhab1-addons by openhab.
the class SysteminfoBinding method initializeSystemMonitor.
private void initializeSystemMonitor(String variant) {
if (sigarImpl == null) {
Sigar.variant = variant;
sigarImpl = new Sigar();
}
if (sigar == null) {
sigar = SigarProxyCache.newInstance(sigarImpl, 1000);
}
logger.info("Using Sigar version {}", Sigar.VERSION_STRING);
logger.info("Using native version {}", Sigar.NATIVE_VERSION_STRING);
try {
String[] interfaces = sigar.getNetInterfaceList();
logger.debug("valid net interfaces: {}", Arrays.toString(interfaces));
FileSystem[] filesystems = sigar.getFileSystemList();
logger.debug("file systems: {}", Arrays.toString(filesystems));
List<String> disks = new ArrayList<String>();
for (int i = 0; i < filesystems.length; i++) {
FileSystem fs = filesystems[i];
if (fs.getType() == FileSystem.TYPE_LOCAL_DISK) {
disks.add(fs.getDevName());
}
}
logger.debug("valid disk names: {}", Arrays.toString(disks.toArray()));
} catch (SigarException e) {
logger.error("System monitor error:", e);
}
}
use of org.hyperic.sigar.FileSystem in project graylog2-server by Graylog2.
the class SigarFsProbe method fsStats.
@Override
public synchronized FsStats fsStats() {
final Sigar sigar = sigarService.sigar();
final Map<String, FsStats.Filesystem> filesystems = new HashMap<>(locations.size());
for (File location : locations) {
final String path = location.getAbsolutePath();
try {
FileSystem fileSystem = sigarFileSystems.get(location);
if (fileSystem == null) {
FileSystemMap fileSystemMap = sigar.getFileSystemMap();
if (fileSystemMap != null) {
fileSystem = fileSystemMap.getMountPoint(location.getPath());
sigarFileSystems.put(location, fileSystem);
}
}
String mount = null;
String dev = null;
long total = -1;
long free = -1;
long available = -1;
long used = -1;
short usedPercent = -1;
long inodesTotal = -1;
long inodesFree = -1;
long inodesUsed = -1;
short inodesUsedPercent = -1;
long diskReads = -1;
long diskWrites = -1;
long diskReadBytes = -1;
long diskWriteBytes = -1;
double diskQueue = -1.0d;
double diskServiceTime = -1.0d;
if (fileSystem != null) {
mount = fileSystem.getDirName();
dev = fileSystem.getDevName();
final FileSystemUsage fileSystemUsage = sigar.getFileSystemUsage(mount);
if (fileSystemUsage != null) {
total = fileSystemUsage.getTotal() * 1024;
free = fileSystemUsage.getFree() * 1024;
available = fileSystemUsage.getAvail() * 1024;
used = fileSystemUsage.getUsed() * 1024;
usedPercent = (short) (fileSystemUsage.getUsePercent() * 100);
inodesTotal = fileSystemUsage.getFiles();
inodesFree = fileSystemUsage.getFreeFiles();
inodesUsed = inodesTotal - inodesFree;
inodesUsedPercent = (short) ((double) inodesUsed / inodesTotal * 100);
diskReads = fileSystemUsage.getDiskReads();
diskWrites = fileSystemUsage.getDiskWrites();
diskReadBytes = fileSystemUsage.getDiskReadBytes();
diskWriteBytes = fileSystemUsage.getDiskWriteBytes();
diskQueue = fileSystemUsage.getDiskQueue();
diskServiceTime = fileSystemUsage.getDiskServiceTime();
}
}
final FsStats.Filesystem filesystem = FsStats.Filesystem.create(path, mount, dev, total, free, available, used, usedPercent, inodesTotal, inodesFree, inodesUsed, inodesUsedPercent, diskReads, diskWrites, diskReadBytes, diskWriteBytes, diskQueue, diskServiceTime);
filesystems.put(path, filesystem);
} catch (SigarException e) {
// ignore
}
}
return FsStats.create(filesystems);
}
use of org.hyperic.sigar.FileSystem 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