Lior Vernia has uploaded a new change for review.

Change subject: core: Add total RX/TX in DB and DAL
......................................................................

core: Add total RX/TX in DB and DAL

Added the total RX/TX columns to the host and VM interface statistics
tables, and updated their DAOs.

Change-Id: Ie91655cef0165375bf5e1e4f8b4d6e08275a541e
Signed-off-by: Lior Vernia <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkStatisticsDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/network_sp.sql
A packaging/dbscripts/upgrade/03_06_0700_add_total_rx_tx_statistics.sql
6 files changed, 76 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/36468/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkStatisticsDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkStatisticsDaoDbFacadeImpl.java
index 9bc2f88..e7ce8dc 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkStatisticsDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkStatisticsDaoDbFacadeImpl.java
@@ -37,9 +37,12 @@
             map.put("id", stats.getId());
             map.put("rx_drop", stats.getReceiveDropRate());
             map.put("rx_rate", stats.getReceiveRate());
+            map.put("rx_total", stats.getReceivedBytes());
             map.put("tx_drop", stats.getTransmitDropRate());
             map.put("tx_rate", stats.getTransmitRate());
+            map.put("tx_total", stats.getTransmittedBytes());
             map.put("iface_status", stats.getStatus());
+            map.put("sample_time", stats.getSampleTime());
             return map;
         }
     }
@@ -54,9 +57,12 @@
             entity.setId(getGuidDefaultEmpty(rs, "id"));
             entity.setReceiveRate(rs.getDouble("rx_rate"));
             entity.setTransmitRate(rs.getDouble("tx_rate"));
+            entity.setReceivedBytes(rs.getLong("rx_total"));
+            entity.setTransmittedBytes(rs.getLong("tx_total"));
             entity.setReceiveDropRate(rs.getDouble("rx_drop"));
             entity.setTransmitDropRate(rs.getDouble("tx_drop"));
             
entity.setStatus(InterfaceStatus.forValue(rs.getInt("iface_status")));
+            entity.setSampleTime(rs.getLong("sample_time"));
             return entity;
         }
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoTest.java
index cf7d06d..8a08692 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VmNetworkStatisticsDaoTest.java
@@ -35,10 +35,13 @@
         newVmStatistics.setId(NEW_INTERFACE_ID);
         newVmStatistics.setVmId(VM_ID);
         newVmStatistics.setStatus(InterfaceStatus.DOWN);
+        newVmStatistics.setSampleTime(0L);
         newVmStatistics.setReceiveDropRate(0.0);
         newVmStatistics.setReceiveRate(0.0);
+        newVmStatistics.setReceivedBytes(0L);
         newVmStatistics.setTransmitDropRate(0.0);
         newVmStatistics.setTransmitRate(0.0);
+        newVmStatistics.setTransmittedBytes(0L);
     }
 
     /**
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index d54c080..8d56d77 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -5405,11 +5405,17 @@
         <column>tx_rate</column>
         <column>rx_drop</column>
         <column>tx_drop</column>
+        <column>rx_total</column>
+        <column>tx_total</column>
         <column>iface_status</column>
+        <column>sample_time</column>
         <column>_update_date</column>
         <row>
             <value>e2817b12-f873-4046-b0da-0098293c14fd</value>
             <value>77296e00-0cad-4e5a-9299-008a7b6f4355</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>0</value>
             <value>0</value>
             <value>0</value>
@@ -5424,7 +5430,10 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>1</value>
+            <value>0</value>
             <null />
         </row>
         <row>
@@ -5434,7 +5443,10 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>1</value>
+            <value>0</value>
             <null />
         </row>
             <row>
@@ -5444,7 +5456,10 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>1</value>
+            <value>0</value>
             <null />
         </row>
     </table>
@@ -5567,11 +5582,17 @@
         <column>tx_rate</column>
         <column>rx_drop</column>
         <column>tx_drop</column>
+        <column>rx_total</column>
+        <column>tx_total</column>
         <column>iface_status</column>
+        <column>sample_time</column>
         <column>_update_date</column>
         <row>
             <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9db</value>
             <null />
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>0</value>
             <value>0</value>
             <value>0</value>
@@ -5587,11 +5608,17 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <null />
         </row>
         <row>
             <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9dc</value>
             <null />
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <value>0</value>
             <value>0</value>
             <value>0</value>
@@ -5607,6 +5634,9 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <null />
         </row>
         <row>
@@ -5617,6 +5647,9 @@
             <value>0</value>
             <value>0</value>
             <value>0</value>
+            <value>0</value>
+            <value>0</value>
+            <value>0</value>
             <null />
         </row>
     </table>
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 0224f22..62b7efe 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -1035,7 +1035,8 @@
 *************************************************/
 CREATE OR REPLACE VIEW vds_interface_view AS
   SELECT vds_interface_statistics.rx_rate, vds_interface_statistics.tx_rate, 
vds_interface_statistics.rx_drop,
-      vds_interface_statistics.tx_drop, vds_interface_statistics.iface_status, 
vds_interface.type, vds_interface.gateway,
+      vds_interface_statistics.tx_drop, vds_interface_statistics.rx_total, 
vds_interface_statistics.tx_total,
+      vds_interface_statistics.iface_status, 
vdS_interface_statistics.sample_time, vds_interface.type, vds_interface.gateway,
       vds_interface.subnet, vds_interface.addr, vds_interface.speed, 
vds_interface.base_interface, vds_interface.vlan_id, vds_interface.bond_type,
       vds_interface.bond_name, vds_interface.is_bond, vds_interface.bond_opts, 
vds_interface.mac_addr,
       vds_interface.network_name, vds_interface.name, vds_static.vds_id, 
vds_static.vds_name,  vds_interface.id,
@@ -1047,7 +1048,8 @@
 
 CREATE OR REPLACE VIEW vm_interface_view AS
   SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, 
vm_interface_statistics.rx_drop,
-      vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, 
vm_interface.type, vm_interface.speed,
+      vm_interface_statistics.tx_drop, vm_interface_statistics.rx_total, 
vm_interface_statistics.tx_total,
+      vm_interface_statistics.iface_status, 
vm_interface_statistics.sample_time, vm_interface.type, vm_interface.speed,
       vm_interface.mac_addr, network.name AS network_name, vm_interface.name, 
vm_interface.vnic_profile_id, vm_static.vm_guid, vm_interface.vmt_guid,
       vm_static.vm_name, vm_interface.id, 0 AS boot_protocol, 0 AS is_vds, 
vm_device.is_plugged,
       vm_device.custom_properties, vnic_profiles.port_mirroring AS 
port_mirroring, vm_interface.linked,
@@ -1059,7 +1061,8 @@
   LEFT JOIN ((vnic_profiles JOIN network ON network.id = 
vnic_profiles.network_id)LEFT JOIN qos ON vnic_profiles.network_qos_id = 
qos.id) ON vnic_profiles.id = vm_interface.vnic_profile_id
   UNION
   SELECT vm_interface_statistics.rx_rate, vm_interface_statistics.tx_rate, 
vm_interface_statistics.rx_drop,
-      vm_interface_statistics.tx_drop, vm_interface_statistics.iface_status, 
vm_interface.type, vm_interface.speed,
+      vm_interface_statistics.tx_drop, vm_interface_statistics.rx_total, 
vm_interface_statistics.tx_total,
+      vm_interface_statistics.iface_status, 
vm_interface_statistics.sample_time, vm_interface.type, vm_interface.speed,
       vm_interface.mac_addr, network.name AS network_name, vm_interface.name, 
vm_interface.vnic_profile_id, NULL::uuid as vm_guid,
       vm_interface.vmt_guid, vm_templates.vm_name AS vm_name, vm_interface.id, 
0 AS boot_protocol, 0 AS is_vds,
       vm_device.is_plugged as is_plugged, vm_device.custom_properties as 
custom_properties, vnic_profiles.port_mirroring AS port_mirroring,
diff --git a/packaging/dbscripts/network_sp.sql 
b/packaging/dbscripts/network_sp.sql
index c6ad01e..0c1583a 100644
--- a/packaging/dbscripts/network_sp.sql
+++ b/packaging/dbscripts/network_sp.sql
@@ -751,15 +751,18 @@
 Create or replace FUNCTION Insertvm_interface_statistics(v_id UUID,
        v_rx_drop DECIMAL(18,0) ,
        v_rx_rate DECIMAL(18,0) ,
+       v_rx_total BIGINT ,
        v_tx_drop DECIMAL(18,0) ,
        v_tx_rate DECIMAL(18,0) ,
+       v_tx_total BIGINT ,
        v_iface_status INTEGER ,
+       v_sample_time BIGINT ,
        v_vm_id UUID)
 RETURNS VOID
    AS $procedure$
 BEGIN
-INSERT INTO vm_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, 
vm_id, iface_status)
-       VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, 
v_vm_id,v_iface_status);
+INSERT INTO vm_interface_statistics(id, rx_drop, rx_rate, rx_total, tx_drop, 
tx_rate, tx_total, vm_id, iface_status, sample_time)
+       VALUES(v_id, v_rx_drop, v_rx_rate, v_rx_total, v_tx_drop, v_tx_rate, 
v_tx_total, v_vm_id, v_iface_status, v_sample_time);
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -770,9 +773,12 @@
 Create or replace FUNCTION Updatevm_interface_statistics(v_id UUID,
  v_rx_drop DECIMAL(18,0) ,
  v_rx_rate DECIMAL(18,0) ,
+ v_rx_total BIGINT ,
  v_tx_drop DECIMAL(18,0) ,
  v_tx_rate DECIMAL(18,0) ,
+ v_tx_total BIGINT ,
  v_iface_status INTEGER ,
+ v_sample_time BIGINT ,
  v_vm_id UUID)
 RETURNS VOID
 
@@ -780,8 +786,9 @@
    AS $procedure$
 BEGIN
       UPDATE vm_interface_statistics
-      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate 
= v_tx_rate,
-      vm_id = v_vm_id,iface_status = v_iface_status, _update_date = 
LOCALTIMESTAMP
+      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,rx_total = v_rx_total,
+      tx_drop = v_tx_drop,tx_rate = v_tx_rate,tx_total = v_tx_total,
+      vm_id = v_vm_id,iface_status = v_iface_status,sample_time = 
v_sample_time, _update_date = LOCALTIMESTAMP
       WHERE id = v_id;
 END; $procedure$
 LANGUAGE plpgsql;
@@ -859,15 +866,18 @@
 Create or replace FUNCTION Insertvds_interface_statistics(v_id UUID,
        v_rx_drop DECIMAL(18,0) ,
        v_rx_rate DECIMAL(18,0) ,
+       v_rx_total BIGINT ,
        v_tx_drop DECIMAL(18,0) ,
        v_tx_rate DECIMAL(18,0) ,
+       v_tx_total BIGINT ,
        v_iface_status INTEGER ,
+       v_sample_time BIGINT ,
        v_vds_id UUID)
 RETURNS VOID
    AS $procedure$
 BEGIN
-INSERT INTO vds_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, 
vds_id, iface_status)
-       VALUES(v_id, v_rx_drop, v_rx_rate, v_tx_drop, v_tx_rate, 
v_vds_id,v_iface_status);
+INSERT INTO vds_interface_statistics(id, rx_drop, rx_rate, tx_drop, tx_rate, 
tx_total, vds_id, iface_status, sample_time)
+       VALUES(v_id, v_rx_drop, v_rx_rate, v_rx_total, v_tx_drop, v_tx_rate, 
v_tx_total, v_vds_id, v_iface_status, v_sample_time);
 END; $procedure$
 LANGUAGE plpgsql;
 
@@ -878,9 +888,12 @@
 Create or replace FUNCTION Updatevds_interface_statistics(v_id UUID,
  v_rx_drop DECIMAL(18,0) ,
  v_rx_rate DECIMAL(18,0) ,
+ v_rx_total BIGINT ,
  v_tx_drop DECIMAL(18,0) ,
  v_tx_rate DECIMAL(18,0) ,
+ v_tx_total BIGINT ,
  v_iface_status INTEGER ,
+ v_sample_time BIGINT ,
  v_vds_id UUID)
 RETURNS VOID
 
@@ -888,8 +901,9 @@
    AS $procedure$
 BEGIN
       UPDATE vds_interface_statistics
-      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,tx_drop = v_tx_drop,tx_rate 
= v_tx_rate,
-      vds_id = v_vds_id,iface_status = v_iface_status, _update_date = 
LOCALTIMESTAMP
+      SET rx_drop = v_rx_drop,rx_rate = v_rx_rate,rx_total = v_rx_total,
+      tx_drop = v_tx_drop,tx_rate = v_tx_rate,tx_total = v_tx_total,
+      vds_id = v_vds_id,iface_status = v_iface_status,sample_time = 
v_sample_time, _update_date = LOCALTIMESTAMP
       WHERE id = v_id;
 END; $procedure$
 LANGUAGE plpgsql;
diff --git 
a/packaging/dbscripts/upgrade/03_06_0700_add_total_rx_tx_statistics.sql 
b/packaging/dbscripts/upgrade/03_06_0700_add_total_rx_tx_statistics.sql
new file mode 100644
index 0000000..4fef0a8
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_06_0700_add_total_rx_tx_statistics.sql
@@ -0,0 +1,6 @@
+SELECT fn_db_add_column('vds_interface_statistics', 'rx_total', 'BIGINT 
DEFAULT NULL');
+SELECT fn_db_add_column('vds_interface_statistics', 'tx_total', 'BIGINT 
DEFAULT NULL');
+SELECT fn_db_add_column('vds_interface_statistics', 'sample_time', 'BIGINT 
DEFAULT NULL');
+SELECT fn_db_add_column('vm_interface_statistics', 'rx_total', 'BIGINT DEFAULT 
NULL');
+SELECT fn_db_add_column('vm_interface_statistics', 'tx_total', 'BIGINT DEFAULT 
NULL');
+SELECT fn_db_add_column('vm_interface_statistics', 'sample_time', 'BIGINT 
DEFAULT NULL');


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie91655cef0165375bf5e1e4f8b4d6e08275a541e
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