Search in sources :

Example 1 with Tcp

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

Aggregations

HashMap (java.util.HashMap)1 NetInterfaceConfig (org.hyperic.sigar.NetInterfaceConfig)1 NetInterfaceStat (org.hyperic.sigar.NetInterfaceStat)1 Sigar (org.hyperic.sigar.Sigar)1 SigarException (org.hyperic.sigar.SigarException)1 Tcp (org.hyperic.sigar.Tcp)1