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
This commit is contained in:
Wei Zhou 2021-02-04 10:14:47 +01:00 committed by GitHub
parent 78f73c1bc6
commit 4de6ac3c05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -684,18 +684,17 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
return;
}
// collect the vm disk statistics(total) from hypervisor. added by weizhou, 2013.03.
s_logger.trace("Running VM disk stats ...");
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
s_logger.debug("VmDiskStatsTask is running...");
s_logger.debug("VmDiskStatsTask is running...");
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
List<HostVO> hosts = _hostDao.search(sc, null);
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, HypervisorType.KVM, HypervisorType.VMware);
List<HostVO> hosts = _hostDao.search(sc, null);
for (HostVO host : hosts) {
for (HostVO host : hosts) {
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
List<Long> vmIds = new ArrayList<Long>();
@ -706,7 +705,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
HashMap<Long, List<VmDiskStatsEntry>> vmDiskStatsById = _userVmMgr.getVmDiskStatistics(host.getId(), host.getName(), vmIds);
if (vmDiskStatsById == null)
continue;
return;
Set<Long> vmIdSet = vmDiskStatsById.keySet();
for (Long vmId : vmIdSet) {
@ -793,10 +792,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
}
}
}
}
});
} catch (Exception e) {
s_logger.warn("Error while collecting vm disk stats from hosts", e);
});
} catch (Exception e) {
s_logger.warn(String.format("Error while collecting vm disk stats from host %s : ", host.getName()), e);
}
}
}
}
@ -812,16 +811,16 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
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...");
s_logger.debug("VmNetworkStatsTask is running...");
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
List<HostVO> hosts = _hostDao.search(sc, null);
SearchCriteria<HostVO> sc = createSearchCriteriaForHostTypeRoutingStateUpAndNotInMaintenance();
List<HostVO> hosts = _hostDao.search(sc, null);
for (HostVO host : hosts) {
for (HostVO host : hosts) {
try {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
List<UserVmVO> vms = _userVmDao.listRunningByHostId(host.getId());
List<Long> vmIds = new ArrayList<Long>();
@ -832,7 +831,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
HashMap<Long, List<VmNetworkStatsEntry>> vmNetworkStatsById = _userVmMgr.getVmNetworkStatistics(host.getId(), host.getName(), vmIds);
if (vmNetworkStatsById == null)
continue;
return;
Set<Long> vmIdSet = vmNetworkStatsById.keySet();
for (Long vmId : vmIdSet) {
@ -912,10 +911,10 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
}
}
}
}
});
} catch (Exception e) {
s_logger.warn("Error while collecting vm network stats from hosts", e);
});
} catch (Exception e) {
s_logger.warn(String.format("Error while collecting vm network stats from host %s : ", host.getName()), e);
}
}
}
}