コード例 #1
0
ファイル: stats.go プロジェクト: hyperhq/runv
func getNetworkStats(domain *libvirtgo.VirDomain, virDomain *VirDomain) (types.NetworkStats, error) {
	stats := types.NetworkStats{
		Interfaces: make([]types.InterfaceStats, 0, 1),
	}

	for _, iface := range virDomain.Devices.Interfaces {
		ifaceStats, err := domain.InterfaceStats(iface.Device.Dev)
		if err != nil {
			return stats, err
		}

		stats.Interfaces = append(stats.Interfaces, types.InterfaceStats{
			Name:      iface.Device.Dev,
			RxBytes:   uint64(ifaceStats.RxBytes),
			RxPackets: uint64(ifaceStats.RxPackets),
			RxErrors:  uint64(ifaceStats.RxErrs),
			RxDropped: uint64(ifaceStats.RxDrop),
			TxBytes:   uint64(ifaceStats.TxBytes),
			TxPackets: uint64(ifaceStats.TxPackets),
			TxErrors:  uint64(ifaceStats.TxErrs),
			TxDropped: uint64(ifaceStats.TxDrop),
		})
	}

	return stats, nil
}