use of org.hyperic.sigar.NetInterfaceConfig 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);
}
use of org.hyperic.sigar.NetInterfaceConfig 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