@@ -128,10 +128,18 @@ private StatsCollector(Map<String, String> configs) {
128128 hostAndVmStatsInterval = NumbersUtil .parseLong (configs .get ("vm.stats.interval" ), 60000L );
129129 storageStatsInterval = NumbersUtil .parseLong (configs .get ("storage.stats.interval" ), 60000L );
130130 volumeStatsInterval = NumbersUtil .parseLong (configs .get ("volume.stats.interval" ), -1L );
131-
132- _executor .scheduleWithFixedDelay (new HostCollector (), 15000L , hostStatsInterval , TimeUnit .MILLISECONDS );
133- _executor .scheduleWithFixedDelay (new VmStatsCollector (), 15000L , hostAndVmStatsInterval , TimeUnit .MILLISECONDS );
134- _executor .scheduleWithFixedDelay (new StorageCollector (), 15000L , storageStatsInterval , TimeUnit .MILLISECONDS );
131+
132+ if (hostStatsInterval > 0 ) {
133+ _executor .scheduleWithFixedDelay (new HostCollector (), 15000L , hostStatsInterval , TimeUnit .MILLISECONDS );
134+ }
135+
136+ if (hostAndVmStatsInterval > 0 ) {
137+ _executor .scheduleWithFixedDelay (new VmStatsCollector (), 15000L , hostAndVmStatsInterval , TimeUnit .MILLISECONDS );
138+ }
139+
140+ if (storageStatsInterval > 0 ) {
141+ _executor .scheduleWithFixedDelay (new StorageCollector (), 15000L , storageStatsInterval , TimeUnit .MILLISECONDS );
142+ }
135143
136144 // -1 means we don't even start this thread to pick up any data.
137145 if (volumeStatsInterval > 0 ) {
@@ -199,7 +207,7 @@ public void run() {
199207 vmIds .add (vm .getId ());
200208 }
201209
202- try
210+ try
203211 {
204212 HashMap <Long , VmStatsEntry > vmStatsById = _userVmMgr .getVirtualMachineStatistics (host .getId (), host .getName (), vmIds );
205213
@@ -250,7 +258,7 @@ public VmStats getVmStats(long id) {
250258 class StorageCollector implements Runnable {
251259 @ Override
252260 public void run () {
253- try {
261+ try {
254262 List <HostVO > hosts = _hostDao .listSecondaryStorageHosts ();
255263 ConcurrentHashMap <Long , StorageStats > storageStats = new ConcurrentHashMap <Long , StorageStats >();
256264 for (HostVO host : hosts ) {
@@ -260,13 +268,13 @@ public void run() {
260268 if (answer != null && answer .getResult ()) {
261269 storageStats .put (hostId , (StorageStats )answer );
262270 //Seems like we have dynamically updated the sec. storage as prev. size and the current do not match
263- if (_storageStats .get (hostId )!=null &&
264- _storageStats .get (hostId ).getCapacityBytes () != ((StorageStats )answer ).getCapacityBytes ()){
271+ if (_storageStats .get (hostId )!=null &&
272+ _storageStats .get (hostId ).getCapacityBytes () != ((StorageStats )answer ).getCapacityBytes ()){
265273 host .setTotalSize (((StorageStats )answer ).getCapacityBytes ());
266274 _hostDao .update (hostId , host );
267- }
275+ }
268276 }
269- }
277+ }
270278 _storageStats = storageStats ;
271279 ConcurrentHashMap <Long , StorageStats > storagePoolStats = new ConcurrentHashMap <Long , StorageStats >();
272280
@@ -279,19 +287,19 @@ public void run() {
279287 if (answer != null && answer .getResult ()) {
280288 storagePoolStats .put (pool .getId (), (StorageStats )answer );
281289
282- // Seems like we have dynamically updated the pool size since the prev. size and the current do not match
290+ // Seems like we have dynamically updated the pool size since the prev. size and the current do not match
283291 if (_storagePoolStats .get (poolId )!= null &&
284- _storagePoolStats .get (poolId ).getCapacityBytes () != ((StorageStats )answer ).getCapacityBytes ()){
285- pool .setCapacityBytes (((StorageStats )answer ).getCapacityBytes ());
286- _storagePoolDao .update (pool .getId (), pool );
292+ _storagePoolStats .get (poolId ).getCapacityBytes () != ((StorageStats )answer ).getCapacityBytes ()){
293+ pool .setCapacityBytes (((StorageStats )answer ).getCapacityBytes ());
294+ _storagePoolDao .update (pool .getId (), pool );
287295 }
288296 }
289297 } catch (StorageUnavailableException e ) {
290298 s_logger .info ("Unable to reach " + pool );
291299 } catch (Exception e ) {
292300 s_logger .warn ("Unable to get stats for " + pool );
293301 }
294- }
302+ }
295303 _storagePoolStats = storagePoolStats ;
296304 } catch (Throwable t ) {
297305 s_logger .error ("Error trying to retrieve storage stats" , t );
0 commit comments