Github user wido commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/926#discussion_r41961830
--- Diff: server/src/com/cloud/server/StatsCollector.java ---
@@ -700,6 +734,121 @@ public void
doInTransactionWithoutResult(TransactionStatus status) {
}
}
+ class VmNetworkStatsTask extends ManagedContextRunnable {
+ @Override
+ protected void runInContext() {
+ //Check for ownership
+ //msHost in UP state with min id should run the job
+ ManagementServerHostVO msHost =
_msHostDao.findOneInUpState(new Filter(ManagementServerHostVO.class, "id",
true, 0L, 1L));
+ if(msHost == null || (msHost.getMsid() != mgmtSrvrId)){
+ s_logger.debug("Skipping collect vm network stats from
hosts");
+ return;
+ }
+ // collect the vm network statistics(total) from hypervisor
+ try {
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void
doInTransactionWithoutResult(TransactionStatus status) {
+ s_logger.debug("VmNetworkStatsTask is running...");
+
+ SearchCriteria<HostVO> sc =
_hostDao.createSearchCriteria();
+ sc.addAnd("status", SearchCriteria.Op.EQ,
Status.Up.toString());
+ sc.addAnd("resourceState", SearchCriteria.Op.NIN,
ResourceState.Maintenance, ResourceState.PrepareForMaintenance,
ResourceState.ErrorInMaintenance);
+ sc.addAnd("type", SearchCriteria.Op.EQ,
Host.Type.Routing.toString());
+ List<HostVO> hosts = _hostDao.search(sc, null);
+
+ for (HostVO host : hosts)
+ {
+ List<UserVmVO> vms =
_userVmDao.listRunningByHostId(host.getId());
+ List<Long> vmIds = new ArrayList<Long>();
+
+ for (UserVmVO vm : vms) {
+ if (vm.getType() ==
VirtualMachine.Type.User) // user vm
+ vmIds.add(vm.getId());
+ }
+
+ HashMap<Long, List<VmNetworkStatsEntry>>
vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(),
host.getName(), vmIds);
+ if (vmNetworkStatsById == null)
+ continue;
+
+ Set<Long> vmIdSet =
vmNetworkStatsById.keySet();
+ for(Long vmId : vmIdSet)
+ {
+ List<VmNetworkStatsEntry> vmNetworkStats =
vmNetworkStatsById.get(vmId);
+ if (vmNetworkStats == null)
+ continue;
+ UserVmVO userVm =
_userVmDao.findById(vmId);
+ for (VmNetworkStatsEntry
vmNetworkStat:vmNetworkStats) {
+ SearchCriteria<NicVO> sc_nic =
_nicDao.createSearchCriteria();
+ sc_nic.addAnd("macAddress",
SearchCriteria.Op.EQ, vmNetworkStat.getMacAddress());
+ NicVO nic = _nicDao.search(sc_nic,
null).get(0);
+ List<VlanVO> vlan =
_vlanDao.listVlansByNetworkId(nic.getNetworkId());
+ if (vlan == null || vlan.size() == 0
|| vlan.get(0).getVlanType() != VlanType.DirectAttached)
+ continue; // only get network
statistics for DirectAttached network (shared networks in Basic zone and
Advanced zone with/without SG)
+ UserStatisticsVO
previousvmNetworkStats = _userStatsDao.findBy(userVm.getAccountId(),
userVm.getDataCenterId(), nic.getNetworkId(), nic.getIPv4Address(), vmId,
"UserVm");
+ if (previousvmNetworkStats == null) {
+ previousvmNetworkStats = new
UserStatisticsVO(userVm.getAccountId(),
userVm.getDataCenterId(),nic.getIPv4Address(), vmId, "UserVm",
nic.getNetworkId());
+
_userStatsDao.persist(previousvmNetworkStats);
+ }
+ UserStatisticsVO vmNetworkStat_lock =
_userStatsDao.lock(userVm.getAccountId(), userVm.getDataCenterId(),
nic.getNetworkId(), nic.getIPv4Address(), vmId, "UserVm");
+
+ if ((vmNetworkStat.getBytesSent() ==
0) && (vmNetworkStat.getBytesReceived() == 0)) {
+ s_logger.debug("bytes sent and
received are all 0. Not updating user_statistics");
--- End diff --
Shouldn't we print the vmId here as well? Now you don't know which VM we
are talking about
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---