@@ -192,6 +192,10 @@ public String toString() {
192192 private static final String DISK_WRITE_IOPS_FIELD = "disk_write_iops" ;
193193 private static final String DISK_WRITE_KBS_FIELD = "disk_write_kbs" ;
194194
195+ private static final int HOURLY_TIME = 60 ;
196+ private static final int DAILY_TIME = HOURLY_TIME * 24 ;
197+ private static final Long ONE_MINUTE_IN_MILLISCONDS = 60000L ;
198+
195199 private static final String DEFAULT_DATABASE_NAME = "cloudstack" ;
196200 private static final String INFLUXDB_HOST_MEASUREMENT = "host_stats" ;
197201 private static final String INFLUXDB_VM_MEASUREMENT = "vm_stats" ;
@@ -328,11 +332,11 @@ public boolean start() {
328332 protected void init (Map <String , String > configs ) {
329333 _executor = Executors .newScheduledThreadPool (6 , new NamedThreadFactory ("StatsCollector" ));
330334
331- hostStatsInterval = NumbersUtil .parseLong (configs .get ("host.stats.interval" ), 60000L );
332- hostAndVmStatsInterval = NumbersUtil .parseLong (configs .get ("vm.stats.interval" ), 60000L );
333- storageStatsInterval = NumbersUtil .parseLong (configs .get ("storage.stats.interval" ), 60000L );
334- volumeStatsInterval = NumbersUtil .parseLong (configs .get ("volume.stats.interval" ), 600000L );
335- autoScaleStatsInterval = NumbersUtil .parseLong (configs .get ("autoscale.stats.interval" ), 60000L );
335+ hostStatsInterval = NumbersUtil .parseLong (configs .get ("host.stats.interval" ), ONE_MINUTE_IN_MILLISCONDS );
336+ hostAndVmStatsInterval = NumbersUtil .parseLong (configs .get ("vm.stats.interval" ), ONE_MINUTE_IN_MILLISCONDS );
337+ storageStatsInterval = NumbersUtil .parseLong (configs .get ("storage.stats.interval" ), ONE_MINUTE_IN_MILLISCONDS );
338+ volumeStatsInterval = NumbersUtil .parseLong (configs .get ("volume.stats.interval" ), ONE_MINUTE_IN_MILLISCONDS );
339+ autoScaleStatsInterval = NumbersUtil .parseLong (configs .get ("autoscale.stats.interval" ), ONE_MINUTE_IN_MILLISCONDS );
336340
337341 String statsUri = statsOutputUri .value ();
338342 if (StringUtils .isNotBlank (statsUri )) {
@@ -427,8 +431,6 @@ protected void init(Map<String, String> configs) {
427431 Calendar cal = Calendar .getInstance (usageTimezone );
428432 cal .setTime (new Date ());
429433 long endDate = 0 ;
430- int HOURLY_TIME = 60 ;
431- final int DAILY_TIME = 60 * 24 ;
432434 if (_usageAggregationRange == DAILY_TIME ) {
433435 cal .set (Calendar .HOUR_OF_DAY , 0 );
434436 cal .set (Calendar .MINUTE , 0 );
@@ -454,9 +456,9 @@ protected void init(Map<String, String> configs) {
454456 s_logger .warn ("Usage stats job aggregation range is to small, using the minimum value of " + UsageUtils .USAGE_AGGREGATION_RANGE_MIN );
455457 _usageAggregationRange = UsageUtils .USAGE_AGGREGATION_RANGE_MIN ;
456458 }
457- _diskStatsUpdateExecutor .scheduleAtFixedRate (new VmDiskStatsUpdaterTask (), (endDate - System .currentTimeMillis ()), (_usageAggregationRange * 60 * 1000 ),
458- TimeUnit .MILLISECONDS );
459459
460+ long period = _usageAggregationRange * ONE_MINUTE_IN_MILLISCONDS ;
461+ _diskStatsUpdateExecutor .scheduleAtFixedRate (new VmDiskStatsUpdaterTask (), (endDate - System .currentTimeMillis ()), period , TimeUnit .MILLISECONDS );
460462 }
461463
462464 /**
@@ -1209,7 +1211,7 @@ private String getAutoscaleAction(HashMap<Long, Double> avgCounter, long groupId
12091211 for (AutoScaleVmGroupPolicyMapVO asVmgPmap : listMap ) {
12101212 AutoScalePolicyVO policyVO = _asPolicyDao .findById (asVmgPmap .getPolicyId ());
12111213 if (policyVO != null ) {
1212- Integer quitetime = policyVO .getQuietTime ();
1214+ int quitetime = policyVO .getQuietTime ();
12131215 Date quitetimeDate = policyVO .getLastQuiteTime ();
12141216 long last_quitetime = 0L ;
12151217 if (quitetimeDate != null ) {
@@ -1236,7 +1238,7 @@ private String getAutoscaleAction(HashMap<Long, Double> avgCounter, long groupId
12361238 if (counter_param .equals (counter_source .toString ()))
12371239 break ;
12381240 counter_count ++;
1239- } while (1 == 1 );
1241+ } while (true );
12401242
12411243 Double sum = avgCounter .get (counter_count );
12421244 Double avg = sum / currentVM ;
@@ -1540,9 +1542,6 @@ protected boolean isCurrentVmDiskStatsDifferentFromPrevious(VmDiskStatisticsVO p
15401542 boolean ioWriteDifferentFromPrevious = previousVmDiskStats .getCurrentIOWrite () != currentVmDiskStats .getCurrentIOWrite ();
15411543 return bytesReadDifferentFromPrevious || bytesWriteDifferentFromPrevious || ioReadDifferentFromPrevious || ioWriteDifferentFromPrevious ;
15421544 }
1543- if (currentVmDiskStats == null ) {
1544- return false ;
1545- }
15461545 return true ;
15471546 }
15481547
0 commit comments