cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [cloudstack] 02/03: CLOUDSTACK-7984: Add vm.{disk, network}.stats.interval.min global setting
Date Sun, 23 Jul 2017 15:15:29 GMT
This is an automated email from the ASF dual-hosted git repository.

bhaisaab pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 047a57ddf25c42a688f17ae037d8692856833c00
Author: Wei Zhou <w.zhou@tech.leaseweb.com>
AuthorDate: Mon Oct 19 14:34:46 2015 +0200

    CLOUDSTACK-7984: Add vm.{disk,network}.stats.interval.min global setting
---
 server/src/com/cloud/configuration/Config.java  |  2 -
 server/src/com/cloud/server/StatsCollector.java | 59 +++++++++++++++++++------
 setup/db/db/schema-480to481.sql                 |  1 +
 3 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index b607502..993f9c5 100644
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -868,8 +868,6 @@ public enum Config {
             "60000",
             "The interval (in milliseconds) when vm stats are retrieved from agents.",
             null),
-    VmDiskStatsInterval("Advanced", ManagementServer.class, Integer.class, "vm.disk.stats.interval",
"0", "Interval (in seconds) to report vm disk statistics.", null),
-    VmNetworkStatsInterval("Advanced", ManagementServer.class, Integer.class, "vm.network.stats.interval",
"0", "Interval (in seconds) to report vm network statistics (for Shared networks).", null),
     VmTransitionWaitInterval(
             "Advanced",
             ManagementServer.class,
diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java
index 0431301..e520867 100644
--- a/server/src/com/cloud/server/StatsCollector.java
+++ b/server/src/com/cloud/server/StatsCollector.java
@@ -47,6 +47,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
@@ -138,7 +140,7 @@ import com.cloud.vm.dao.VMInstanceDao;
  *
  */
 @Component
-public class StatsCollector extends ManagerBase implements ComponentMethodInterceptable {
+public class StatsCollector extends ManagerBase implements ComponentMethodInterceptable,
Configurable {
 
     public static enum ExternalStatsProtocol {
         NONE("none"), GRAPHITE("graphite");
@@ -156,6 +158,15 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
 
     public static final Logger s_logger = Logger.getLogger(StatsCollector.class.getName());
 
+    static final ConfigKey<Integer> vmDiskStatsInterval = new ConfigKey<Integer>("Advanced",
Integer.class, "vm.disk.stats.interval", "0",
+            "Interval (in seconds) to report vm disk statistics. Vm disk statistics will
be disabled if this is set to 0 or less than 0.", false);
+    static final ConfigKey<Integer> vmDiskStatsIntervalMin = new ConfigKey<Integer>("Advanced",
Integer.class, "vm.disk.stats.interval.min", "300",
+            "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);
+    static final ConfigKey<Integer> vmNetworkStatsInterval = new ConfigKey<Integer>("Advanced",
Integer.class, "vm.network.stats.interval", "0",
+            "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);
+    static final ConfigKey<Integer> vmNetworkStatsIntervalMin = new ConfigKey<Integer>("Advanced",
Integer.class, "vm.network.stats.interval.min", "300",
+            "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.",
false);
+
     private static StatsCollector s_instance = null;
 
     private ScheduledExecutorService _executor = null;
@@ -238,8 +249,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
     long storageStatsInterval = -1L;
     long volumeStatsInterval = -1L;
     long autoScaleStatsInterval = -1L;
-    int vmDiskStatsInterval = 0;
-    int vmNetworkStatsInterval = 0;
+
     List<Long> hostIds = null;
     private double _imageStoreCapacityThreshold = 0.90;
 
@@ -286,8 +296,6 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
         storageStatsInterval = NumbersUtil.parseLong(configs.get("storage.stats.interval"),
60000L);
         volumeStatsInterval = NumbersUtil.parseLong(configs.get("volume.stats.interval"),
-1L);
         autoScaleStatsInterval = NumbersUtil.parseLong(configs.get("autoscale.stats.interval"),
60000L);
-        vmDiskStatsInterval = NumbersUtil.parseInt(configs.get("vm.disk.stats.interval"),
0);
-        vmNetworkStatsInterval = NumbersUtil.parseInt(configs.get("vm.network.stats.interval"),
0);
 
         /* URI to send statistics to. Currently only Graphite is supported */
         String externalStatsUri = configs.get("stats.output.uri");
@@ -345,18 +353,26 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
             _executor.scheduleWithFixedDelay(new AutoScaleMonitor(), 15000L, autoScaleStatsInterval,
TimeUnit.MILLISECONDS);
         }
 
-        if (vmDiskStatsInterval > 0) {
-            if (vmDiskStatsInterval < 300)
-                vmDiskStatsInterval = 300;
-            _executor.scheduleAtFixedRate(new VmDiskStatsTask(), vmDiskStatsInterval, vmDiskStatsInterval,
TimeUnit.SECONDS);
+        if (vmDiskStatsInterval.value() > 0) {
+            if (vmDiskStatsInterval.value() < vmDiskStatsIntervalMin.value()) {
+                s_logger.debug("vm.disk.stats.interval - " + vmDiskStatsInterval.value()
+ " is smaller than vm.disk.stats.interval.min - " + vmDiskStatsIntervalMin.value() + ", so
use vm.disk.stats.interval.min");
+                _executor.scheduleAtFixedRate(new VmDiskStatsTask(), vmDiskStatsIntervalMin.value(),
vmDiskStatsIntervalMin.value(), TimeUnit.SECONDS);
+            } else {
+                _executor.scheduleAtFixedRate(new VmDiskStatsTask(), vmDiskStatsInterval.value(),
vmDiskStatsInterval.value(), TimeUnit.SECONDS);
+            }
+        } else {
+            s_logger.debug("vm.disk.stats.interval - " + vmDiskStatsInterval.value() + "
is 0 or less than 0, so not scheduling the vm disk stats thread");
         }
 
-        if (vmNetworkStatsInterval > 0) {
-            if (vmNetworkStatsInterval < 300)
-                vmNetworkStatsInterval = 300;
-            _executor.scheduleAtFixedRate(new VmNetworkStatsTask(), vmNetworkStatsInterval,
vmNetworkStatsInterval, TimeUnit.SECONDS);
+        if (vmNetworkStatsInterval.value() > 0) {
+            if (vmNetworkStatsInterval.value() < vmNetworkStatsIntervalMin.value()) {
+                s_logger.debug("vm.network.stats.interval - " + vmNetworkStatsInterval.value()
+ " is smaller than vm.network.stats.interval.min - " + vmNetworkStatsIntervalMin.value()
+ ", so use vm.network.stats.interval.min");
+                _executor.scheduleAtFixedRate(new VmNetworkStatsTask(), vmNetworkStatsIntervalMin.value(),
vmNetworkStatsIntervalMin.value(), TimeUnit.SECONDS);
+            } else {
+                _executor.scheduleAtFixedRate(new VmNetworkStatsTask(), vmNetworkStatsInterval.value(),
vmNetworkStatsInterval.value(), TimeUnit.SECONDS);
+            }
         } else {
-            s_logger.debug("vm.network.stats.interval - " + vmNetworkStatsInterval + " so
not scheduling the vm network stats thread");
+            s_logger.debug("vm.network.stats.interval - " + vmNetworkStatsInterval.value()
+ " is 0 or less than 0, so not scheduling the vm network stats thread");
         }
 
         //Schedule disk stats update task
@@ -841,6 +857,11 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
                                 if (vmNetworkStats == null)
                                     continue;
                                 UserVmVO userVm = _userVmDao.findById(vmId);
+                                if (userVm == null) {
+                                    s_logger.debug("Cannot find uservm with id: " + vmId
+ " , continue");
+                                    continue;
+                                }
+                                s_logger.debug("Now we are updating the user_statistics table
for VM: " + userVm.getInstanceName() + " after collecting vm network statistics from host:
" + host.getName());
                                 for (VmNetworkStatsEntry vmNetworkStat:vmNetworkStats) {
                                     SearchCriteria<NicVO> sc_nic = _nicDao.createSearchCriteria();
                                     sc_nic.addAnd("macAddress", SearchCriteria.Op.EQ, vmNetworkStat.getMacAddress());
@@ -1279,4 +1300,14 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
     public StorageStats getStoragePoolStats(long id) {
         return _storagePoolStats.get(id);
     }
+
+    @Override
+    public String getConfigComponentName() {
+        return this.getClass().getSimpleName();
+    }
+
+    @Override
+    public ConfigKey<?>[] getConfigKeys() {
+        return new ConfigKey<?>[] { vmDiskStatsInterval, vmDiskStatsIntervalMin, vmNetworkStatsInterval,
vmNetworkStatsIntervalMin };
+    }
 }
diff --git a/setup/db/db/schema-480to481.sql b/setup/db/db/schema-480to481.sql
index 3b2d40b..4c8637b 100644
--- a/setup/db/db/schema-480to481.sql
+++ b/setup/db/db/schema-480to481.sql
@@ -18,3 +18,4 @@
 --;
 -- Schema upgrade from 4.8.0 to 4.8.1;
 --;
+

-- 
To stop receiving notification emails like this one, please contact
"commits@cloudstack.apache.org" <commits@cloudstack.apache.org>.

Mime
View raw message