mirror of https://github.com/apache/cloudstack.git
bug 11345: Compare current and previous network stats before updating. Ignore stats if the current stats are not same as the prev stats. Set NetworkUsageAnswer log level to debug
This commit is contained in:
parent
03958369e0
commit
3a6c226bc9
|
|
@ -19,9 +19,10 @@ package com.cloud.agent.api;
|
|||
|
||||
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
||||
|
||||
@LogLevel(Log4jLevel.Trace)
|
||||
@LogLevel(Log4jLevel.Debug)
|
||||
public class NetworkUsageAnswer extends Answer {
|
||||
Long bytesSent;
|
||||
String routerName;
|
||||
Long bytesSent;
|
||||
Long bytesReceived;
|
||||
|
||||
protected NetworkUsageAnswer() {
|
||||
|
|
@ -31,6 +32,7 @@ public class NetworkUsageAnswer extends Answer {
|
|||
super(cmd, true, details);
|
||||
this.bytesReceived = bytesReceived;
|
||||
this.bytesSent = bytesSent;
|
||||
routerName = cmd.getDomRName();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -49,4 +51,8 @@ public class NetworkUsageAnswer extends Answer {
|
|||
public Long getBytesSent() {
|
||||
return bytesSent;
|
||||
}
|
||||
|
||||
public String getRouterName() {
|
||||
return routerName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
|
|||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.net.MacAddress;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
|
|
@ -311,11 +312,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
int _routerStatsInterval = 300;
|
||||
int _checkRouterInterval = 30;
|
||||
private ServiceOfferingVO _offering;
|
||||
private String trafficSentinelHostname;
|
||||
private String _dnsBasicZoneUpdates = "all";
|
||||
|
||||
private boolean _disable_rp_filter = false;
|
||||
|
||||
|
||||
private long mgmtSrvrId = MacAddress.getMacAddress().toLong();
|
||||
|
||||
ScheduledExecutorService _executor;
|
||||
ScheduledExecutorService _checkExecutor;
|
||||
|
||||
|
|
@ -617,8 +620,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
|
||||
_systemAcct = _accountService.getSystemAccount();
|
||||
|
||||
trafficSentinelHostname = configs.get("traffic.sentinel.hostname");
|
||||
|
||||
s_logger.info("DomainRouterManager is configured.");
|
||||
|
||||
return true;
|
||||
|
|
@ -704,13 +705,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
@Override
|
||||
public void run() {
|
||||
|
||||
final List<DomainRouterVO> routers = _routerDao.listByStateAndNetworkType(State.Running, GuestIpType.Virtual);
|
||||
final List<DomainRouterVO> routers = _routerDao.listByStateAndNetworkType(State.Running, GuestIpType.Virtual, mgmtSrvrId);
|
||||
s_logger.debug("Found " + routers.size() + " running routers. ");
|
||||
|
||||
for (DomainRouterVO router : routers) {
|
||||
String privateIP = router.getPrivateIpAddress();
|
||||
if (privateIP != null) {
|
||||
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName());
|
||||
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString());
|
||||
final NetworkUsageAnswer answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
|
||||
if (answer != null) {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
|
@ -725,9 +727,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
s_logger.warn("unable to find stats for account: " + router.getAccountId());
|
||||
continue;
|
||||
}
|
||||
|
||||
if(previousStats != null
|
||||
&& ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
|
||||
s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Reported: " + answer.getBytesReceived()
|
||||
s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesReceived()
|
||||
+ " Stored: " + stats.getCurrentBytesReceived());
|
||||
}
|
||||
stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
|
||||
|
|
@ -735,7 +744,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
|
|||
stats.setCurrentBytesReceived(answer.getBytesReceived());
|
||||
if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Reported: " + answer.getBytesSent()
|
||||
s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesSent()
|
||||
+ " Stored: " + stats.getCurrentBytesSent());
|
||||
}
|
||||
stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
|
||||
|
|
|
|||
|
|
@ -94,10 +94,10 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
|
|||
List<DomainRouterVO> listActive(long networkId);
|
||||
|
||||
/**
|
||||
* List domain routers by state and network type
|
||||
* List domain routers by state and network type which reside on Host managed by the specified management server
|
||||
* @return
|
||||
*/
|
||||
List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType);
|
||||
List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType, long mgmtSrvrId);
|
||||
|
||||
List<DomainRouterVO> findByNetworkOutsideThePod(long networkId, long podId, State state, Role role);
|
||||
|
||||
|
|
@ -105,5 +105,4 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
|
|||
|
||||
List<DomainRouterVO> listByNetworkAndRole(long networkId, Role role);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import javax.ejb.Local;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDaoImpl;
|
||||
import com.cloud.network.Network.GuestIpType;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.dao.NetworkDaoImpl;
|
||||
|
|
@ -48,7 +50,8 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
protected final SearchBuilder<DomainRouterVO> StateNetworkTypeSearch;
|
||||
protected final SearchBuilder<DomainRouterVO> OutsidePodSearch;
|
||||
NetworkDaoImpl _networksDao = ComponentLocator.inject(NetworkDaoImpl.class);
|
||||
|
||||
HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class);
|
||||
|
||||
protected DomainRouterDaoImpl() {
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterIdToDeployIn(), Op.EQ);
|
||||
|
|
@ -81,6 +84,9 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
SearchBuilder<NetworkVO> joinStateNetwork = _networksDao.createSearchBuilder();
|
||||
joinStateNetwork.and("guestType", joinStateNetwork.entity().getGuestType(), Op.EQ);
|
||||
StateNetworkTypeSearch.join("network", joinStateNetwork, joinStateNetwork.entity().getId(), StateNetworkTypeSearch.entity().getNetworkId(), JoinType.INNER);
|
||||
SearchBuilder<HostVO> joinHost = _hostsDao.createSearchBuilder();
|
||||
joinHost.and("mgmtServerId", joinHost.entity().getManagementServerId(), Op.EQ);
|
||||
StateNetworkTypeSearch.join("host", joinHost, joinHost.entity().getId(), StateNetworkTypeSearch.entity().getHostId(), JoinType.INNER);
|
||||
StateNetworkTypeSearch.done();
|
||||
|
||||
OutsidePodSearch = createSearchBuilder();
|
||||
|
|
@ -197,10 +203,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType) {
|
||||
public List<DomainRouterVO> listByStateAndNetworkType(State state, GuestIpType ipType, long mgmtSrvrId) {
|
||||
SearchCriteria<DomainRouterVO> sc = StateNetworkTypeSearch.create();
|
||||
sc.setParameters("state", state);
|
||||
sc.setJoinParameters("network", "guestType", ipType);
|
||||
sc.setJoinParameters("host", "mgmtServerId", mgmtSrvrId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue