Search in sources :

Example 1 with FileSystemUsage

use of org.hyperic.sigar.FileSystemUsage 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);
}
Also used : Sigar(org.hyperic.sigar.Sigar) HashMap(java.util.HashMap) SigarException(org.hyperic.sigar.SigarException) FileSystemMap(org.hyperic.sigar.FileSystemMap) FileSystem(org.hyperic.sigar.FileSystem) FileSystemUsage(org.hyperic.sigar.FileSystemUsage) File(java.io.File)

Aggregations

File (java.io.File)1 HashMap (java.util.HashMap)1 FileSystem (org.hyperic.sigar.FileSystem)1 FileSystemMap (org.hyperic.sigar.FileSystemMap)1 FileSystemUsage (org.hyperic.sigar.FileSystemUsage)1 Sigar (org.hyperic.sigar.Sigar)1 SigarException (org.hyperic.sigar.SigarException)1