Skip to content

Commit 6501879

Browse files
committed
Routed: get vm network statistics on Routed network
1 parent 5b9a3d7 commit 6501879

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
5858
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
5959
import org.apache.cloudstack.management.ManagementServerHost;
60+
import org.apache.cloudstack.network.RoutedIpv4Manager;
6061
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
6162
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
6263
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
@@ -113,6 +114,8 @@
113114
import com.cloud.hypervisor.Hypervisor;
114115
import com.cloud.hypervisor.Hypervisor.HypervisorType;
115116
import com.cloud.network.as.AutoScaleManager;
117+
import com.cloud.network.dao.NetworkDao;
118+
import com.cloud.network.dao.NetworkVO;
116119
import com.cloud.org.Cluster;
117120
import com.cloud.resource.ResourceManager;
118121
import com.cloud.resource.ResourceState;
@@ -202,6 +205,11 @@
202205
@Component
203206
public class StatsCollector extends ManagerBase implements ComponentMethodInterceptable, Configurable, DbStatsCollection {
204207

208+
@Inject
209+
private NetworkDao networkDao;
210+
@Inject
211+
private RoutedIpv4Manager routedIpv4Manager;
212+
205213
public static enum ExternalStatsProtocol {
206214
NONE("none"), GRAPHITE("graphite"), INFLUXDB("influxdb");
207215
String _type;
@@ -267,9 +275,9 @@ public String toString() {
267275
private static final ConfigKey<Integer> vmDiskStatsIntervalMin = new ConfigKey<>("Advanced", Integer.class, "vm.disk.stats.interval.min", "300",
268276
"Minimal interval (in seconds) to report vm disk statistics. If vm.disk.stats.interval is smaller than this, use this to report vm disk statistics.", false);
269277
private static final ConfigKey<Integer> vmNetworkStatsInterval = new ConfigKey<>("Advanced", Integer.class, "vm.network.stats.interval", "0",
270-
"Interval (in seconds) to report vm network statistics (for Shared networks). Vm network statistics will be disabled if this is set to 0 or less than 0.", false);
278+
"Interval (in seconds) to report vm network statistics (for Shared and Routed networks). Vm network statistics will be disabled if this is set to 0 or less than 0.", false);
271279
private static final ConfigKey<Integer> vmNetworkStatsIntervalMin = new ConfigKey<>("Advanced", Integer.class, "vm.network.stats.interval.min", "300",
272-
"Minimal Interval (in seconds) to report vm network statistics (for Shared networks). If vm.network.stats.interval is smaller than this, use this to report vm network statistics.",
280+
"Minimal Interval (in seconds) to report vm network statistics (for Shared and Routed networks). If vm.network.stats.interval is smaller than this, use this to report vm network statistics.",
273281
false);
274282
private static final ConfigKey<Integer> StatsTimeout = new ConfigKey<>("Advanced", Integer.class, "stats.timeout", "60000",
275283
"The timeout for stats call in milli seconds.", true,
@@ -1582,8 +1590,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
15821590
sc_nic.addAnd("macAddress", SearchCriteria.Op.EQ, vmNetworkStatEntry.getMacAddress());
15831591
NicVO nic = _nicDao.search(sc_nic, null).get(0);
15841592
List<VlanVO> vlan = _vlanDao.listVlansByNetworkId(nic.getNetworkId());
1585-
if (vlan == null || vlan.size() == 0 || vlan.get(0).getVlanType() != VlanType.DirectAttached)
1586-
continue; // only get network statistics for DirectAttached network (shared networks in Basic zone and Advanced zone with/without SG)
1593+
NetworkVO networkVO = networkDao.findById(nic.getNetworkId());
1594+
if (CollectionUtils.isEmpty(vlan) || (vlan.get(0).getVlanType() != VlanType.DirectAttached
1595+
&& (networkVO == null || !routedIpv4Manager.isRoutedNetwork(networkVO)))) {
1596+
continue; // only get network statistics for Shared or Routed network
1597+
}
15871598
UserStatisticsVO previousvmNetworkStats = _userStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), nic.getNetworkId(),
15881599
nic.getIPv4Address(), vmId, "UserVm");
15891600
if (previousvmNetworkStats == null) {

0 commit comments

Comments
 (0)