|
51 | 51 | import org.apache.commons.collections.CollectionUtils; |
52 | 52 | import org.apache.commons.collections.MapUtils; |
53 | 53 | import org.apache.commons.lang.StringUtils; |
| 54 | +import org.apache.commons.lang3.BooleanUtils; |
54 | 55 | import org.apache.log4j.Logger; |
55 | 56 | import org.influxdb.BatchOptions; |
56 | 57 | import org.influxdb.InfluxDB; |
@@ -221,6 +222,9 @@ public String toString() { |
221 | 222 | private static final ConfigKey<String> statsOutputUri = new ConfigKey<String>("Advanced", String.class, "stats.output.uri", "", |
222 | 223 | "URI to send StatsCollector statistics to. The collector is defined on the URI scheme. Example: graphite://graphite-hostaddress:port or influxdb://influxdb-hostaddress/dbname. Note that the port is optional, if not added the default port for the respective collector (graphite or influxdb) will be used. Additionally, the database name '/dbname' is also optional; default db name is 'cloudstack'. You must create and configure the database if using influxdb.", |
223 | 224 | true); |
| 225 | + private static final ConfigKey<Boolean> VM_STATS_INCREMENT_METRICS_IN_MEMORY = new ConfigKey<Boolean>("Advanced", Boolean.class, "vm.stats.increment.metrics.in.memory", "true", |
| 226 | + "When set to 'true', VM metrics(NetworkReadKBs, NetworkWriteKBs, DiskWriteKBs, DiskReadKBs, DiskReadIOs and DiskWriteIOs) that are collected from the hypervisor are summed and stored in memory. " |
| 227 | + + "On the other hand, when set to 'false', the VM metrics API will just display the latest metrics collected.", true); |
224 | 228 |
|
225 | 229 | private static StatsCollector s_instance = null; |
226 | 230 |
|
@@ -1460,11 +1464,12 @@ private void prepareVmMetricsForGraphite(Map<Object, Object> metrics, VmStatsEnt |
1460 | 1464 | private void storeVirtualMachineStatsInMemory(VmStatsEntry statsForCurrentIteration) { |
1461 | 1465 | VmStatsEntry statsInMemory = (VmStatsEntry)_VmStats.get(statsForCurrentIteration.getVmId()); |
1462 | 1466 |
|
1463 | | - if (statsInMemory == null) { |
1464 | | - //no stats exist for this vm, directly persist |
| 1467 | + boolean vmStatsIncrementMetrics = BooleanUtils.toBoolean(VM_STATS_INCREMENT_METRICS_IN_MEMORY.value()); |
| 1468 | + if (statsInMemory == null || !vmStatsIncrementMetrics) { |
1465 | 1469 | _VmStats.put(statsForCurrentIteration.getVmId(), statsForCurrentIteration); |
1466 | 1470 | } else { |
1467 | | - //update each field |
| 1471 | + s_logger.debug(String.format("Increment saved values of NetworkReadKBs, NetworkWriteKBs, DiskWriteKBs, DiskReadKBs, DiskReadIOs, DiskWriteIOs, with current metrics for VM with ID [%s]. " |
| 1472 | + + "To change this process, check value of 'vm.stats.increment.metrics.in.memory' configuration.", statsForCurrentIteration.getVmId())); |
1468 | 1473 | statsInMemory.setCPUUtilization(statsForCurrentIteration.getCPUUtilization()); |
1469 | 1474 | statsInMemory.setNumCPUs(statsForCurrentIteration.getNumCPUs()); |
1470 | 1475 | statsInMemory.setNetworkReadKBs(statsInMemory.getNetworkReadKBs() + statsForCurrentIteration.getNetworkReadKBs()); |
@@ -1625,7 +1630,7 @@ public String getConfigComponentName() { |
1625 | 1630 |
|
1626 | 1631 | @Override |
1627 | 1632 | public ConfigKey<?>[] getConfigKeys() { |
1628 | | - return new ConfigKey<?>[] {vmDiskStatsInterval, vmDiskStatsIntervalMin, vmNetworkStatsInterval, vmNetworkStatsIntervalMin, StatsTimeout, statsOutputUri}; |
| 1633 | + return new ConfigKey<?>[] {vmDiskStatsInterval, vmDiskStatsIntervalMin, vmNetworkStatsInterval, vmNetworkStatsIntervalMin, StatsTimeout, statsOutputUri, VM_STATS_INCREMENT_METRICS_IN_MEMORY}; |
1629 | 1634 | } |
1630 | 1635 |
|
1631 | 1636 | public double getImageStoreCapacityThreshold() { |
|
0 commit comments