Search in sources :

Example 1 with Sigar

use of org.hyperic.sigar.Sigar 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);
}
Also used : Sigar(org.hyperic.sigar.Sigar) CpuInfo(org.hyperic.sigar.CpuInfo) SigarException(org.hyperic.sigar.SigarException) Mem(org.hyperic.sigar.Mem) CpuPerc(org.hyperic.sigar.CpuPerc)

Example 2 with Sigar

use of org.hyperic.sigar.Sigar in project graylog2-server by Graylog2.

the class SigarProcessProbe method processStats.

@Override
public synchronized ProcessStats processStats() {
    final Sigar sigar = sigarService.sigar();
    final long pid = sigar.getPid();
    final long openFileDescriptors = JmxProcessProbe.getOpenFileDescriptorCount();
    final long maxFileDescriptorCount = JmxProcessProbe.getMaxFileDescriptorCount();
    ProcessStats.Cpu cpu;
    try {
        ProcCpu procCpu = sigar.getProcCpu(pid);
        cpu = ProcessStats.Cpu.create((short) (procCpu.getPercent() * 100), procCpu.getSys(), procCpu.getUser(), procCpu.getTotal());
    } catch (SigarException e) {
        cpu = null;
    }
    ProcessStats.Memory memory;
    try {
        ProcMem mem = sigar.getProcMem(sigar.getPid());
        memory = ProcessStats.Memory.create(mem.getSize(), mem.getResident(), mem.getShare());
    } catch (SigarException e) {
        memory = null;
    }
    return ProcessStats.create(pid, openFileDescriptors, maxFileDescriptorCount, cpu, memory);
}
Also used : Sigar(org.hyperic.sigar.Sigar) SigarException(org.hyperic.sigar.SigarException) ProcCpu(org.hyperic.sigar.ProcCpu) ProcMem(org.hyperic.sigar.ProcMem)

Example 3 with Sigar

use of org.hyperic.sigar.Sigar in project ats-framework by Axway.

the class MatchedProcess method init.

public static void init(SigarWrapper sigarWrapper, int pollingInterval) throws UnsupportedReadingException, SigarException {
    /*
         * We need to know the number of CPUs for some readings in some cases. For example
         *      1. Sigar gives average CPU usage in percents.
         *      2. Sigar gives accumulated CPU usage times.
         *      If we have 2 CPUs loaded on 20% and 40%, we will get 30% and 0.60 time usage for 1 second.
         *      We fix that to get get 30% and 0.30 time usage for 1 second.
         */
    getNumberOfCPUs(sigarWrapper);
    // clean up the processes map
    matchedProcessesMap = new HashMap<String, Map<Long, MatchedProcess>>();
    matchedProcessesIds = new HashSet<Long>();
    matchedProcessesIndexes = new HashMap<String, Integer>();
    processesReadingInstanceIdentifiers = new HashSet<String>();
    // On Solaris it takes a significant amount of time (around 1 minute) until Sigar iterates the
    // system processes for first time. We do it here, so the real polls are quick
    Sigar sigar = sigarWrapper.getSigarInstance();
    for (long pid : sigar.getProcList()) {
        try {
            sigar.getProcArgs(pid);
        } catch (SigarException e) {
        // some system processes can not be accessed
        }
    }
}
Also used : Sigar(org.hyperic.sigar.Sigar) SigarException(org.hyperic.sigar.SigarException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Sigar

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

Example 5 with Sigar

use of org.hyperic.sigar.Sigar 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

Sigar (org.hyperic.sigar.Sigar)7 SigarException (org.hyperic.sigar.SigarException)6 HashMap (java.util.HashMap)3 FileSystem (org.hyperic.sigar.FileSystem)3 CpuInfo (org.hyperic.sigar.CpuInfo)2 NetInterfaceConfig (org.hyperic.sigar.NetInterfaceConfig)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 CpuPerc (org.hyperic.sigar.CpuPerc)1 FileSystemMap (org.hyperic.sigar.FileSystemMap)1 FileSystemUsage (org.hyperic.sigar.FileSystemUsage)1 Mem (org.hyperic.sigar.Mem)1 NetInterfaceStat (org.hyperic.sigar.NetInterfaceStat)1 ProcCpu (org.hyperic.sigar.ProcCpu)1 ProcMem (org.hyperic.sigar.ProcMem)1 Tcp (org.hyperic.sigar.Tcp)1