use of org.hyperic.sigar.SigarException 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.SigarException in project ats-framework by Axway.
the class AtsSystemMonitor method init.
@Override
public void init(FullReadingBean[] readings) throws Exception {
log.info("Initializing the ATS System Monitor");
try {
this.sigarWrapper = new SigarWrapper();
} catch (SigarException e) {
log.error("Error initializing the Sigar System", e);
throw new Exception("Error initializing the Sigar System", e);
}
List<FullReadingBean> staticReadings = new ArrayList<FullReadingBean>();
List<FullReadingBean> dynamicReadings = new ArrayList<FullReadingBean>();
for (FullReadingBean reading : readings) {
if (!reading.isDynamicReading()) {
staticReadings.add(reading);
} else {
// check if this process has parent
String parentProcessName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
if (parentProcessName != null) {
final String parentProcessId = parentProcessName + "-" + reading.getName();
if (!parentProcessReadingInstances.containsKey(parentProcessId)) {
parentProcessReadingInstances.put(parentProcessId, new ParentProcessReadingBean(reading.getId(), reading.getMonitorName(), parentProcessName, reading.getName(), reading.getUnit()));
}
}
dynamicReadings.add(reading);
}
}
ReadingInstancesFactory.init(sigarWrapper, getPollInterval());
// create the actual static reading instances
staticReadingInstances = ReadingInstancesFactory.createStaticReadingInstances(sigarWrapper, staticReadings);
// remember the initial dynamic readings
initialDynamicReadings = new ArrayList<FullReadingBean>(dynamicReadings);
// calculations on the first poll
if (initialDynamicReadings.size() > 0) {
dynamicReadingInstances = ReadingInstancesFactory.createOrUpdateDynamicReadingInstances(sigarWrapper, parentProcessReadingInstances, initialDynamicReadings, dynamicReadingInstances);
}
}
use of org.hyperic.sigar.SigarException in project ats-framework by Axway.
the class MatchedProcess method getProcessCpuUsageRunningTotal.
private static List<ReadingInstance> getProcessCpuUsageRunningTotal(SigarWrapper sigarWrapper, FullReadingBean reading, ParentProcessReadingBean parentProcess) throws SigarException {
String readingProcessPattern = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN);
// we can match more than 1 process
List<ReadingInstance> readingInstancesList = new ArrayList<ReadingInstance>();
// iterate all processes in the map
Map<Long, MatchedProcess> processesForThisPattern = matchedProcessesMap.get(readingProcessPattern);
if (processesForThisPattern != null) {
for (final MatchedProcess processInfo : processesForThisPattern.values()) {
// check if we are not already measuring this reading for this process
String processesReadingInstanceIdentifier = reading.getName() + "->" + processInfo.getPid();
if (!processesReadingInstanceIdentifiers.contains(processesReadingInstanceIdentifier)) {
processesReadingInstanceIdentifiers.add(processesReadingInstanceIdentifier);
// create a new reading for this process
Map<String, String> parameters = constructProcessParametersMap(processInfo, readingProcessPattern, "3");
readingInstancesList.add(new ReadingInstance(sigarWrapper, parentProcess, reading.getId() + "->" + processInfo.getPid(), processInfo.getPid(), reading.getMonitorName(), "[process] " + processInfo.getAlias() + " - CPU usage - Total", reading.getUnit(), parameters, 1.0F) {
private static final long serialVersionUID = 1L;
@Override
public void init() throws SigarException {
this.lastLongValue = fixLongValue(fixOverflow(getName(), sigarWrapper.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
}
@Override
public float poll() throws SigarException {
long totalTime = fixLongValue(fixOverflow(getName(), sigarWrapper.getProcessCpuTimeRunningTotal(processInfo.getPid()), ReadingInstance.CPU_PROCESS_OVERFLOW_VALUE));
double deltaTotalTime;
if (totalTime > 0) {
deltaTotalTime = (totalTime - this.lastLongValue) / numberOfCPUs;
this.lastLongValue = totalTime;
} else {
return -1;
}
float deltaTotalPercentUsage = 0.0F;
long elapsedTime = getElapsedTime();
// moment of creating the ReadingInstance, it is normal for new processes
if (elapsedTime > 900) {
// calculate total code time for 1ms
deltaTotalTime = deltaTotalTime / elapsedTime;
// convert to percentage usage
deltaTotalPercentUsage = new BigDecimal(deltaTotalTime).setScale(2, BigDecimal.ROUND_DOWN).floatValue() * 100.0F;
}
addValueToParentProcess(deltaTotalPercentUsage);
return deltaTotalPercentUsage;
}
});
}
}
}
return readingInstancesList;
}
use of org.hyperic.sigar.SigarException in project ats-framework by Axway.
the class SigarWrapper method refresh.
/**
* called on each poll
*
* @throws SigarException
* @throws MonitorConfigurationException
*/
void refresh() throws SigarException, MonitorConfigurationException {
try {
this.swap = this.sigar.getSwap();
this.memory = this.sigar.getMem();
this.cpu = this.sigar.getCpu();
this.cpuPerc = this.sigar.getCpuPerc();
if (!OperatingSystemType.getCurrentOsType().equals(OperatingSystemType.AIX)) {
this.netstat = this.sigar.getNetStat();
this.tcp = this.sigar.getTcp();
}
this.loadAvrg = new SigarLoadAverage(this.sigar);
} catch (Exception e) {
final String errorMsg = "Error retrieving data from the Sigar monitoring system";
log.error(errorMsg, e);
throw new MonitorConfigurationException(errorMsg, e);
}
}
Aggregations