Java Code Examples for org.hyperic.sigar.NetInterfaceStat#getTxOverruns()

The following examples show how to use org.hyperic.sigar.NetInterfaceStat#getTxOverruns() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private NetworkStatistic getCurrentNetworkStatistic(final ITimeSource timesource, final String interfaceName) throws SigarException {
	final long currentTimestamp = timesource.getTime();
	final NetInterfaceStat interfaceStat = this.sigar.getNetInterfaceStat(interfaceName);
	final long speed = interfaceStat.getSpeed();
	final long txBytes = interfaceStat.getTxBytes();
	final long txCarrier = interfaceStat.getTxCarrier();
	final long txCollisions = interfaceStat.getTxCollisions();
	final long txDropped = interfaceStat.getTxDropped();
	final long txErrors = interfaceStat.getTxErrors();
	final long txOverruns = interfaceStat.getTxOverruns();
	final long txPackets = interfaceStat.getTxPackets();
	final long rxBytes = interfaceStat.getRxBytes();
	final long rxDropped = interfaceStat.getRxDropped();
	final long rxErrors = interfaceStat.getRxErrors();
	final long rxFrame = interfaceStat.getRxFrame();
	final long rxOverruns = interfaceStat.getRxOverruns();
	final long rxPackets = interfaceStat.getRxPackets();

	return new NetworkStatistic(currentTimestamp, speed, txBytes, txCarrier, txCollisions, txDropped, txErrors, txOverruns, txPackets, rxBytes, rxDropped,
			rxErrors, rxFrame, rxOverruns, rxPackets);
}
 
Example 2
Source Project: perfmon-agent   File: NetworkIOMetric.java    License: Apache License 2.0 4 votes vote down vote up
public void getValue(StringBuffer res) throws SigarException {
    double val = 0;
    double cur;
    int factor = 1;
    for (int n = 0; n < interfaces.length; n++) {
        NetInterfaceStat usage;
        try {
            usage = sigarProxy.getNetInterfaceStat(interfaces[n]);
        } catch (SigarException e) {
            log.error("Failed to get interface stat: " + interfaces[n], e);
            continue;
        }
        switch (type) {
            case RX_BYTES:
                val += usage.getRxBytes();
                factor = dividingFactor;
                break;
            case RX_DROPPED:
                val += usage.getRxDropped();
                break;
            case RX_ERRORS:
                val += usage.getRxErrors();
                break;
            case RX_FRAME:
                val += usage.getRxFrame();
                break;
            case RX_OVERRUNS:
                val += usage.getRxOverruns();
                break;
            case RX_PACKETS:
                val += usage.getRxPackets();
                break;
            case TX_BYTES:
                val += usage.getTxBytes();
                factor = dividingFactor;
                break;
            case TX_CARRIER:
                val += usage.getTxCarrier();
                break;
            case TX_COLLISIONS:
                val += usage.getTxCollisions();
                break;
            case TX_DROPPED:
                val += usage.getTxDropped();
                break;
            case TX_ERRORS:
                val += usage.getTxErrors();
                break;
            case TX_OVERRUNS:
                val += usage.getTxOverruns();
                break;
            case USED:
                val = usage.getTxPackets();
                break;
            case SPEED:
                val = usage.getSpeed();
                break;
            case TX_PACKETS:
                val += usage.getTxPackets();
                break;
            default:
                throw new SigarException("Unknown net io type " + type);
        }
    }

    // some post-processing
    switch (type) {
        case SPEED:
            break;
        case USED:
            break;
        default:
            cur = val;
            val = prev > 0 ? cur - prev : 0;
            prev = cur;
    }
    val = val / factor;
    res.append(Double.toString(val));
}