Search in sources :

Example 6 with Sigar

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

the class SigarNetworkProbe method networkStats.

@Override
public synchronized NetworkStats networkStats() {
    final Sigar sigar = sigarService.sigar();
    String primaryInterface;
    try {
        final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(null);
        primaryInterface = netInterfaceConfig.getName();
    } catch (SigarException e) {
        primaryInterface = null;
    }
    final Map<String, NetworkStats.Interface> interfaces = new HashMap<>();
    try {
        final String[] netInterfaceList = firstNonNull(sigar.getNetInterfaceList(), new String[0]);
        for (String interfaceName : netInterfaceList) {
            final NetInterfaceStat netInterfaceStat = sigar.getNetInterfaceStat(interfaceName);
            final NetworkStats.InterfaceStats interfaceStats = NetworkStats.InterfaceStats.create(netInterfaceStat.getRxPackets(), netInterfaceStat.getRxErrors(), netInterfaceStat.getRxDropped(), netInterfaceStat.getRxOverruns(), netInterfaceStat.getRxFrame(), netInterfaceStat.getTxPackets(), netInterfaceStat.getTxErrors(), netInterfaceStat.getTxDropped(), netInterfaceStat.getTxOverruns(), netInterfaceStat.getTxCarrier(), netInterfaceStat.getTxCollisions(), netInterfaceStat.getRxBytes(), netInterfaceStat.getTxBytes());
            final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(interfaceName);
            final NetworkStats.Interface networkInterface = NetworkStats.Interface.create(netInterfaceConfig.getName(), Collections.singleton(netInterfaceConfig.getAddress()), netInterfaceConfig.getHwaddr(), netInterfaceConfig.getMtu(), interfaceStats);
            interfaces.put(interfaceName, networkInterface);
        }
    } catch (SigarException e) {
    // ignore
    }
    NetworkStats.TcpStats tcpStats;
    try {
        final Tcp tcp = sigar.getTcp();
        tcpStats = NetworkStats.TcpStats.create(tcp.getActiveOpens(), tcp.getPassiveOpens(), tcp.getAttemptFails(), tcp.getEstabResets(), tcp.getCurrEstab(), tcp.getInSegs(), tcp.getOutSegs(), tcp.getRetransSegs(), tcp.getInErrs(), tcp.getOutRsts());
    } catch (SigarException e) {
        tcpStats = null;
    }
    return NetworkStats.create(primaryInterface, interfaces, tcpStats);
}
Also used : Sigar(org.hyperic.sigar.Sigar) Tcp(org.hyperic.sigar.Tcp) NetInterfaceConfig(org.hyperic.sigar.NetInterfaceConfig) HashMap(java.util.HashMap) SigarException(org.hyperic.sigar.SigarException) NetInterfaceStat(org.hyperic.sigar.NetInterfaceStat)

Example 7 with Sigar

use of org.hyperic.sigar.Sigar 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;
}
Also used : Sigar(org.hyperic.sigar.Sigar) NetInterfaceConfig(org.hyperic.sigar.NetInterfaceConfig) CpuInfo(org.hyperic.sigar.CpuInfo) Date(java.util.Date) BigDecimal(java.math.BigDecimal) FileSystem(org.hyperic.sigar.FileSystem)

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