[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-7984?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14956415#comment-14956415
 ] 

ASF GitHub Bot commented on CLOUDSTACK-7984:
--------------------------------------------

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


> Collect network statistics for VMs on shared network
> ----------------------------------------------------
>
>                 Key: CLOUDSTACK-7984
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-7984
>             Project: CloudStack
>          Issue Type: New Feature
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>         Environment: KVM
>            Reporter: Wei Zhou
>            Assignee: Wei Zhou
>             Fix For: 4.6.0
>
>
> now we get the network usage from virtual router which is only applied on 
> isolated network.
> We need to collect the network statistics for VM nics on shared network. The 
> data can be fetched from the hypervisor.
> Similar to vm disk statistics, I will implement it for KVM.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to