Skip to content

Commit 4de6ac3

Browse files
authored
server: Get vm network/disk statistics and update database per host (#4601)
* server: Get vm network/disk statistics and update database per host * #4601 : modify debug message
1 parent 78f73c1 commit 4de6ac3

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -684,18 +684,17 @@ protected void runInContext() {
684684
return;
685685
}
686686
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
687-
s_logger.trace("Running VM disk stats ...");
688-
try {
689-
Transaction.execute(new TransactionCallbackNoReturn() {
690-
@Override
691-
public void doInTransactionWithoutResult(TransactionStatus status) {
692-
s_logger.debug("VmDiskStatsTask is running...");
687+
s_logger.debug("VmDiskStatsTask is running...");
693688

694-
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
695-
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
696-
List<HostVO> hosts = _hostDao.search(sc, null);
689+
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
690+
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
691+
List<HostVO> hosts = _hostDao.search(sc, null);
697692

698-
for (HostVO host : hosts) {
693+
for (HostVO host : hosts) {
694+
try {
695+
Transaction.execute(new TransactionCallbackNoReturn() {
696+
@Override
697+
public void doInTransactionWithoutResult(TransactionStatus status) {
699698
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
700699
List<Long> vmIds = new ArrayList<Long>();
701700

@@ -706,7 +705,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
706705

707706
HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = _userVmMgr.getVmDiskStatistics(host.getId(), host.getName(), vmIds);
708707
if (vmDiskStatsById == null)
709-
continue;
708+
return;
710709

711710
Set<Long> vmIdSet = vmDiskStatsById.keySet();
712711
for (Long vmId : vmIdSet) {
@@ -793,10 +792,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
793792
}
794793
}
795794
}
796-
}
797-
});
798-
} catch (Exception e) {
799-
s_logger.warn("Error while collecting vm disk stats from hosts", e);
795+
});
796+
} catch (Exception e) {
797+
s_logger.warn(String.format("Error while collecting vm disk stats from host %s : ", host.getName()), e);
798+
}
800799
}
801800
}
802801
}
@@ -812,16 +811,16 @@ protected void runInContext() {
812811
return;
813812
}
814813
// collect the vm network statistics(total) from hypervisor
815-
try {
816-
Transaction.execute(new TransactionCallbackNoReturn() {
817-
@Override
818-
public void doInTransactionWithoutResult(TransactionStatus status) {
819-
s_logger.debug("VmNetworkStatsTask is running...");
814+
s_logger.debug("VmNetworkStatsTask is running...");
820815

821-
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
822-
List<HostVO> hosts = _hostDao.search(sc, null);
816+
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
817+
List<HostVO> hosts = _hostDao.search(sc, null);
823818

824-
for (HostVO host : hosts) {
819+
for (HostVO host : hosts) {
820+
try {
821+
Transaction.execute(new TransactionCallbackNoReturn() {
822+
@Override
823+
public void doInTransactionWithoutResult(TransactionStatus status) {
825824
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
826825
List<Long> vmIds = new ArrayList<Long>();
827826

@@ -832,7 +831,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
832831

833832
HashMap<Long, List<VmNetworkStatsEntry>> vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(), host.getName(), vmIds);
834833
if (vmNetworkStatsById == null)
835-
continue;
834+
return;
836835

837836
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
838837
for (Long vmId : vmIdSet) {
@@ -912,10 +911,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
912911
}
913912
}
914913
}
915-
}
916-
});
917-
} catch (Exception e) {
918-
s_logger.warn("Error while collecting vm network stats from hosts", e);
914+
});
915+
} catch (Exception e) {
916+
s_logger.warn(String.format("Error while collecting vm network stats from host %s : ", host.getName()), e);
917+
}
919918
}
920919
}
921920
}

0 commit comments

Comments
 (0)