Skip to content

Commit 9ec5487

Browse files
committed
Rename the volume size metric to volume used and add volume used percent
1 parent 42ae679 commit 9ec5487

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

‎plugins/resource-alerts/src/main/java/org/apache/cloudstack/resourcealert/ResourceAlertManagerImpl.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,15 @@ private Double getMetricValue(ResourceAlertRule.ResourceType type, ResourceAlert
499499
StorageStats pool = statsCollector.getStoragePoolStats(resourceId);
500500
return pool != null && pool.getUsedIops() != null ? pool.getUsedIops().doubleValue() : null;
501501
}
502-
case VOLUME_SIZE_GB: {
502+
case VOLUME_USED_GB: {
503503
VolumeStats s = getVolumeStats(resourceId);
504504
return s != null ? s.getPhysicalSize() / (1024.0 * 1024.0 * 1024.0) : null;
505505
}
506+
case VOLUME_UTILIZATION: {
507+
VolumeStats s = getVolumeStats(resourceId);
508+
if (s == null || s.getVirtualSize() <= 0) return null;
509+
return ((double) s.getPhysicalSize() / s.getVirtualSize()) * 100.0;
510+
}
506511
case LOAD_AVERAGE: {
507512
HostStats s = statsCollector.getHostStats(resourceId);
508513
return s != null ? s.getLoadAverage() : null;

‎plugins/resource-alerts/src/main/java/org/apache/cloudstack/resourcealert/ResourceAlertMetric.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public enum ResourceAlertMetric {
3232
NETWORK_READ_KBPS(ResourceAlertRule.ResourceType.VirtualMachine, ResourceAlertRule.ResourceType.Host),
3333
NETWORK_WRITE_KBPS(ResourceAlertRule.ResourceType.VirtualMachine, ResourceAlertRule.ResourceType.Host),
3434
LOAD_AVERAGE(ResourceAlertRule.ResourceType.Host),
35-
VOLUME_SIZE_GB(ResourceAlertRule.ResourceType.Volume),
35+
VOLUME_USED_GB(ResourceAlertRule.ResourceType.Volume),
36+
VOLUME_UTILIZATION(ResourceAlertRule.ResourceType.Volume),
3637
STORAGE_USED_IOPS(ResourceAlertRule.ResourceType.StoragePool);
3738

3839
private final Set<ResourceAlertRule.ResourceType> applicableTypes;
@@ -46,6 +47,6 @@ public boolean appliesTo(ResourceAlertRule.ResourceType type) {
4647
}
4748

4849
public boolean isPercentage() {
49-
return this == CPU_UTILIZATION || this == MEMORY_UTILIZATION || this == STORAGE_UTILIZATION;
50+
return this == CPU_UTILIZATION || this == MEMORY_UTILIZATION || this == STORAGE_UTILIZATION || this == VOLUME_UTILIZATION;
5051
}
5152
}

‎plugins/resource-alerts/src/test/java/org/apache/cloudstack/resourcealert/ResourceAlertManagerImplTest.java‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,12 @@ public void testHostNetworkWriteRuleDoesNotFireBelowThreshold() {
736736

737737
private ResourceAlertRuleVO volumeSizeRule(double thresholdGb) {
738738
return new ResourceAlertRuleVO("vol", ResourceAlertRule.ResourceType.Volume,
739-
VOLUME_ID, 1L, 1L, "VOLUME_SIZE_GB", AlertCondition.GT, thresholdGb,
739+
VOLUME_ID, 1L, 1L, "VOLUME_USED_GB", AlertCondition.GT, thresholdGb,
740740
AlertSeverity.MEDIUM, null, false, 600);
741741
}
742742

743743
@Test
744-
public void testVolumeSizeRuleUsesPhysicalSizeByPath() {
744+
public void testVolumeUsedRuleUsesPhysicalSizeByPath() {
745745
when(ruleDao.listActive()).thenReturn(Collections.singletonList(volumeSizeRule(10.0)));
746746
VolumeVO vol = mock(VolumeVO.class);
747747
when(vol.getFormat()).thenReturn(Storage.ImageFormat.QCOW2);
@@ -759,7 +759,29 @@ public void testVolumeSizeRuleUsesPhysicalSizeByPath() {
759759
}
760760

761761
@Test
762-
public void testVolumeSizeRuleUsesChainInfoForOva() {
762+
public void testVolumeUtilizationIsUsedOverDiskSize() {
763+
ResourceAlertRuleVO rule = new ResourceAlertRuleVO("vol-pct", ResourceAlertRule.ResourceType.Volume,
764+
VOLUME_ID, 1L, 1L, "VOLUME_UTILIZATION", AlertCondition.GT, 50.0,
765+
AlertSeverity.MEDIUM, null, false, 600);
766+
when(ruleDao.listActive()).thenReturn(Collections.singletonList(rule));
767+
VolumeVO vol = mock(VolumeVO.class);
768+
when(vol.getFormat()).thenReturn(Storage.ImageFormat.QCOW2);
769+
when(vol.getState()).thenReturn(Volume.State.Ready);
770+
when(vol.getPath()).thenReturn("vol-path");
771+
when(volumeDao.findById(VOLUME_ID)).thenReturn(vol);
772+
VolumeStats stats = mock(VolumeStats.class);
773+
when(stats.getPhysicalSize()).thenReturn(6L * 1024 * 1024 * 1024);
774+
when(stats.getVirtualSize()).thenReturn(8L * 1024 * 1024 * 1024);
775+
when(statsCollector.getVolumeStats("vol-path")).thenReturn(stats);
776+
777+
manager.evaluateRules();
778+
779+
verify(alertDao).persist(alertCaptor.capture());
780+
assertEquals(75.0, alertCaptor.getValue().getMetricValue(), 0.001);
781+
}
782+
783+
@Test
784+
public void testVolumeUsedRuleUsesChainInfoForOva() {
763785
when(ruleDao.listActive()).thenReturn(Collections.singletonList(volumeSizeRule(10.0)));
764786
VolumeVO vol = mock(VolumeVO.class);
765787
when(vol.getFormat()).thenReturn(Storage.ImageFormat.OVA);
@@ -847,7 +869,7 @@ public void testGenericRuleScopeForUserIsOwnAccount() {
847869
@Test
848870
public void testGenericVolumeRuleForRootAdminListsReadyVolumesCloudWide() {
849871
ResourceAlertRuleVO rule = new ResourceAlertRuleVO("vol", ResourceAlertRule.ResourceType.Volume,
850-
null, 1L, 1L, "VOLUME_SIZE_GB", AlertCondition.GT, 10.0, AlertSeverity.LOW, null, false, 600);
872+
null, 1L, 1L, "VOLUME_USED_GB", AlertCondition.GT, 10.0, AlertSeverity.LOW, null, false, 600);
851873
when(ruleDao.listActive()).thenReturn(Collections.singletonList(rule));
852874
stubOwner(Account.Type.ADMIN);
853875

‎plugins/resource-alerts/src/test/java/org/apache/cloudstack/resourcealert/ResourceAlertMetricTest.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ public void testLoadAverageAppliesToHostOnly() {
8080
}
8181

8282
@Test
83-
public void testVolumeSizeAppliesToVolumeOnly() {
84-
assertTrue(ResourceAlertMetric.VOLUME_SIZE_GB.appliesTo(ResourceAlertRule.ResourceType.Volume));
85-
assertFalse(ResourceAlertMetric.VOLUME_SIZE_GB.appliesTo(ResourceAlertRule.ResourceType.VirtualMachine));
86-
assertFalse(ResourceAlertMetric.VOLUME_SIZE_GB.appliesTo(ResourceAlertRule.ResourceType.Host));
87-
assertFalse(ResourceAlertMetric.VOLUME_SIZE_GB.appliesTo(ResourceAlertRule.ResourceType.StoragePool));
83+
public void testVolumeUsedAppliesToVolumeOnly() {
84+
assertTrue(ResourceAlertMetric.VOLUME_USED_GB.appliesTo(ResourceAlertRule.ResourceType.Volume));
85+
assertFalse(ResourceAlertMetric.VOLUME_USED_GB.appliesTo(ResourceAlertRule.ResourceType.VirtualMachine));
86+
assertFalse(ResourceAlertMetric.VOLUME_USED_GB.appliesTo(ResourceAlertRule.ResourceType.Host));
87+
assertFalse(ResourceAlertMetric.VOLUME_USED_GB.appliesTo(ResourceAlertRule.ResourceType.StoragePool));
88+
assertTrue(ResourceAlertMetric.VOLUME_UTILIZATION.appliesTo(ResourceAlertRule.ResourceType.Volume));
89+
assertFalse(ResourceAlertMetric.VOLUME_UTILIZATION.appliesTo(ResourceAlertRule.ResourceType.VirtualMachine));
8890
}
8991

9092
@Test
@@ -101,6 +103,7 @@ public void testPercentageMetrics() {
101103
assertTrue(ResourceAlertMetric.MEMORY_UTILIZATION.isPercentage());
102104
assertTrue(ResourceAlertMetric.STORAGE_UTILIZATION.isPercentage());
103105
assertFalse(ResourceAlertMetric.DISK_READ_IOPS.isPercentage());
104-
assertFalse(ResourceAlertMetric.VOLUME_SIZE_GB.isPercentage());
106+
assertTrue(ResourceAlertMetric.VOLUME_UTILIZATION.isPercentage());
107+
assertFalse(ResourceAlertMetric.VOLUME_USED_GB.isPercentage());
105108
}
106109
}

‎ui/src/views/resourcealert/resourceAlertOptions.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
export const METRICS_BY_TYPE = {
1919
VirtualMachine: ['CPU_UTILIZATION', 'MEMORY_UTILIZATION', 'DISK_READ_IOPS', 'DISK_WRITE_IOPS', 'DISK_READ_KBPS', 'DISK_WRITE_KBPS', 'NETWORK_READ_KBPS', 'NETWORK_WRITE_KBPS'],
2020
Host: ['CPU_UTILIZATION', 'MEMORY_UTILIZATION', 'LOAD_AVERAGE', 'NETWORK_READ_KBPS', 'NETWORK_WRITE_KBPS'],
21-
Volume: ['VOLUME_SIZE_GB'],
21+
Volume: ['VOLUME_USED_GB', 'VOLUME_UTILIZATION'],
2222
StoragePool: ['STORAGE_UTILIZATION', 'STORAGE_USED_IOPS']
2323
}
2424

@@ -44,7 +44,8 @@ export const METRIC_LABELS = {
4444
NETWORK_WRITE_KBPS: 'Network Out KB/s',
4545
STORAGE_UTILIZATION: 'Storage Utilization %',
4646
LOAD_AVERAGE: 'Load Average',
47-
VOLUME_SIZE_GB: 'Volume Size (GB)',
47+
VOLUME_USED_GB: 'Volume Used (GB)',
48+
VOLUME_UTILIZATION: 'Volume Used %',
4849
STORAGE_USED_IOPS: 'Storage Used IOPS'
4950
}
5051

0 commit comments

Comments
 (0)