|
57 | 57 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
58 | 58 | import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
59 | 59 | import org.apache.cloudstack.management.ManagementServerHost; |
| 60 | +import org.apache.cloudstack.network.RoutedIpv4Manager; |
60 | 61 | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; |
61 | 62 | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; |
62 | 63 | import org.apache.cloudstack.utils.bytescale.ByteScaleUtils; |
|
113 | 114 | import com.cloud.hypervisor.Hypervisor; |
114 | 115 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
115 | 116 | import com.cloud.network.as.AutoScaleManager; |
| 117 | +import com.cloud.network.dao.NetworkDao; |
| 118 | +import com.cloud.network.dao.NetworkVO; |
116 | 119 | import com.cloud.org.Cluster; |
117 | 120 | import com.cloud.resource.ResourceManager; |
118 | 121 | import com.cloud.resource.ResourceState; |
|
202 | 205 | @Component |
203 | 206 | public class StatsCollector extends ManagerBase implements ComponentMethodInterceptable, Configurable, DbStatsCollection { |
204 | 207 |
|
| 208 | + @Inject |
| 209 | + private NetworkDao networkDao; |
| 210 | + @Inject |
| 211 | + private RoutedIpv4Manager routedIpv4Manager; |
| 212 | + |
205 | 213 | public static enum ExternalStatsProtocol { |
206 | 214 | NONE("none"), GRAPHITE("graphite"), INFLUXDB("influxdb"); |
207 | 215 | String _type; |
@@ -267,9 +275,9 @@ public String toString() { |
267 | 275 | private static final ConfigKey<Integer> vmDiskStatsIntervalMin = new ConfigKey<>("Advanced", Integer.class, "vm.disk.stats.interval.min", "300", |
268 | 276 | "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); |
269 | 277 | 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); |
271 | 279 | 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.", |
273 | 281 | false); |
274 | 282 | private static final ConfigKey<Integer> StatsTimeout = new ConfigKey<>("Advanced", Integer.class, "stats.timeout", "60000", |
275 | 283 | "The timeout for stats call in milli seconds.", true, |
@@ -1582,8 +1590,11 @@ public void doInTransactionWithoutResult(TransactionStatus status) { |
1582 | 1590 | sc_nic.addAnd("macAddress", SearchCriteria.Op.EQ, vmNetworkStatEntry.getMacAddress()); |
1583 | 1591 | NicVO nic = _nicDao.search(sc_nic, null).get(0); |
1584 | 1592 | 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 | + } |
1587 | 1598 | UserStatisticsVO previousvmNetworkStats = _userStatsDao.findBy(userVm.getAccountId(), userVm.getDataCenterId(), nic.getNetworkId(), |
1588 | 1599 | nic.getIPv4Address(), vmId, "UserVm"); |
1589 | 1600 | if (previousvmNetworkStats == null) { |
|
0 commit comments