Lior Vernia has uploaded a new change for review.

Change subject: engine: Calculate "true" host network usage
......................................................................

engine: Calculate "true" host network usage

Previously host network usage was calculated as the usage of the
highest-utilised interface. Now total usage is summed and divided by
total capacity to better reflect the burden on the host's total
networking resources. This calculation assumes full-duplex operation,
as "duplexity" isn't currently reported by VDSM.

Change-Id: I71adf32f76414fe34d433177741e73529959992b
Bug-Url: https://bugzilla.redhat.com/1114085
Signed-off-by: Lior Vernia <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
2 files changed, 41 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/31000/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
index d64a52f..9f295df 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VdsNetworkInterface.java
@@ -245,6 +245,15 @@
     }
 
     /**
+     * Checks whether an interface is a VLAN device.
+     *
+     * @return whether an interface is a VLAN device.
+     */
+    public boolean isVlanDevice() {
+        return vlanId != null;
+    }
+
+    /**
      * Sets whether the interface is bonded or not.
      *
      * @param bonded
@@ -283,6 +292,15 @@
     }
 
     /**
+     * Checks whether an interface is part of a bond.
+     *
+     * @return whether the interface is part of a bond.
+     */
+    public boolean isBondSlave() {
+        return bondName != null;
+    }
+
+    /**
      * Sets the bond type.
      *
      * @param bondType
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
index e0abb3c..7b3f26b 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
@@ -11,9 +11,11 @@
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang.StringUtils;
@@ -678,8 +680,8 @@
         // ------------- vds network statistics ---------------------
         Map<String, Object> interfaces = (Map<String, Object>) 
xmlRpcStruct.get(VdsProperties.NETWORK);
         if (interfaces != null) {
-            int networkUsage = 0;
             Map<String, VdsNetworkInterface> nicsByName = 
Entities.entitiesByName(vds.getInterfaces());
+            Set<String> usageNics = new HashSet<String>();
             for (Entry<String, Object> entry : interfaces.entrySet()) {
                 if (nicsByName.containsKey(entry.getKey())) {
                     VdsNetworkInterface iface = nicsByName.get(entry.getKey());
@@ -696,17 +698,25 @@
                     iface.setSpeed(AssignIntValue(dict, 
VdsProperties.INTERFACE_SPEED));
                     
iface.getStatistics().setStatus(AssignInterfaceStatusValue(dict, 
VdsProperties.iface_status));
 
-                    int hold =
-                            
(iface.getStatistics().getTransmitRate().compareTo(iface.getStatistics().getReceiveRate())
 > 0 ? iface.getStatistics()
-                                    .getTransmitRate()
-                                    : iface
-                                            
.getStatistics().getReceiveRate()).intValue();
-                    if (hold > networkUsage) {
-                        networkUsage = hold;
+                    if (!Boolean.TRUE.equals(iface.getBonded()) && 
!iface.isVlanDevice()) {
+                        usageNics.add(iface.isBondSlave() ? 
iface.getBondName() : iface.getName());
                     }
                 }
             }
-            vds.setUsageNetworkPercent((networkUsage > 100) ? 100 : 
networkUsage);
+
+            double networkUsage = 0;
+            int networkCapacity = 0;
+            for (String nicName : usageNics) {
+                VdsNetworkInterface iface = nicsByName.get(nicName);
+                networkUsage +=
+                        iface.getSpeed()
+                                * 
(truncatePercentage(iface.getStatistics().getReceiveRate())
+                                        + 
truncatePercentage(iface.getStatistics().getTransmitRate()));
+
+                // TODO: this assumes full-duplex, when half-duplex is 
reported only count speed once
+                networkCapacity += 2 * iface.getSpeed();
+            }
+            vds.setUsageNetworkPercent((int) (networkUsage / networkCapacity));
         }
 
         // ----------- vds cpu statistics info ---------------------
@@ -787,6 +797,10 @@
 
     }
 
+    private static double truncatePercentage(double value) {
+        return Math.min(100, value);
+    }
+
     public static void updateNumaStatisticsData(VDS vds, Map<String, Object> 
xmlRpcStruct) {
         List<VdsNumaNode> vdsNumaNodes = new ArrayList<>();
         List<CpuStatistics> cpuStatsData = new ArrayList<>();


-- 
To view, visit http://gerrit.ovirt.org/31000
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I71adf32f76414fe34d433177741e73529959992b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to