Skip to content

Commit 2fc5cc7

Browse files
bug 10945: Start using the new alert system. Also introduce secondarystorage.capacity.threshold
1 parent 10ea88a commit 2fc5cc7

2 files changed

Lines changed: 14 additions & 121 deletions

File tree

‎server/src/com/cloud/alert/AlertManagerImpl.java‎

Lines changed: 13 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public class AlertManagerImpl implements AlertManager {
113113
private double _storageAllocCapacityThreshold = 0.75;
114114
private double _publicIPCapacityThreshold = 0.75;
115115
private double _privateIPCapacityThreshold = 0.75;
116-
Map<Short,Double> _capacityTypeThresholdMap = new HashMap<Short, Double>();
116+
private double _secondaryStorageCapacityThreshold = 0.75;
117+
Map<Short,Double> _capacityTypeThresholdMap = new HashMap<Short, Double>();
117118

118119
@Override
119120
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -155,7 +156,8 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
155156
String memoryCapacityThreshold = configs.get("memory.capacity.threshold");
156157
String storageAllocCapacityThreshold = configs.get("storage.allocated.capacity.threshold");
157158
String publicIPCapacityThreshold = configs.get("public.ip.capacity.threshold");
158-
String privateIPCapacityThreshold = configs.get("private.ip.capacity.threshold");
159+
String privateIPCapacityThreshold = configs.get("private.ip.capacity.threshold");
160+
String secondaryStorageCapacityThreshold = configs.get("secondarystorage.capacity.threshold");
159161

160162
if (storageCapacityThreshold != null) {
161163
_storageCapacityThreshold = Double.parseDouble(storageCapacityThreshold);
@@ -175,12 +177,17 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
175177
if (privateIPCapacityThreshold != null) {
176178
_privateIPCapacityThreshold = Double.parseDouble(privateIPCapacityThreshold);
177179
}
180+
if (secondaryStorageCapacityThreshold != null) {
181+
_secondaryStorageCapacityThreshold = Double.parseDouble(secondaryStorageCapacityThreshold);
182+
}
183+
178184
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_STORAGE, _storageCapacityThreshold);
179185
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, _storageAllocCapacityThreshold);
180186
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_CPU, _cpuCapacityThreshold);
181187
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_MEMORY, _memoryCapacityThreshold);
182188
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_PUBLIC_IP, _publicIPCapacityThreshold);
183189
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_PRIVATE_IP, _privateIPCapacityThreshold);
190+
_capacityTypeThresholdMap.put(Capacity.CAPACITY_TYPE_SECONDARY_STORAGE, _secondaryStorageCapacityThreshold);
184191

185192
String capacityCheckPeriodStr = configs.get("capacity.check.period");
186193
if (capacityCheckPeriodStr != null) {
@@ -378,132 +385,17 @@ public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
378385
class CapacityChecker extends TimerTask {
379386
@Override
380387
public void run() {
381-
recalculateCapacity();
382-
383-
// abort if we can't possibly send an alert...
384-
if (_emailAlert == null) {
385-
return;
386-
}
387-
388-
try {
389-
List<CapacityVO> capacityList = _capacityDao.listAllIncludingRemoved();
390-
Map<String, List<CapacityVO>> capacityDcTypeMap = new HashMap<String, List<CapacityVO>>();
391-
/*CapacityVO storagePoolStats = _storageMgr.getStoragePoolUsedStats(null, null, null, null);
392-
393-
if (capacityList == null){
394-
capacityList = storagePoolStatsList;
395-
}else {
396-
capacityList.addAll(storagePoolStatsList);
397-
}*/
398-
399-
for (CapacityVO capacity : capacityList) {
400-
long dataCenterId = capacity.getDataCenterId();
401-
Long podId = capacity.getPodId();
402-
short type = capacity.getCapacityType();
403-
String key = null;
404-
if((type == CapacityVO.CAPACITY_TYPE_PUBLIC_IP) || (type == CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE)){
405-
key = "dc" + dataCenterId + "t" + type;
406-
} else {
407-
key = "pod" + podId + "t" + type;
408-
}
409-
410-
List<CapacityVO> list = capacityDcTypeMap.get(key);
411-
if (list == null) {
412-
list = new ArrayList<CapacityVO>();
413-
}
414-
list.add(capacity);
415-
capacityDcTypeMap.put(key, list);
416-
}
417-
418-
for (String keyValue : capacityDcTypeMap.keySet()) {
419-
List<CapacityVO> capacities = capacityDcTypeMap.get(keyValue);
420-
double totalCapacity = 0d;
421-
double usedCapacity = 0d;
422-
CapacityVO cap = capacities.get(0);
423-
short capacityType = cap.getCapacityType();
424-
long dataCenterId = cap.getDataCenterId();
425-
Long podId = cap.getPodId();
426-
427-
for (CapacityVO capacity : capacities) {
428-
totalCapacity += capacity.getTotalCapacity();
429-
usedCapacity += capacity.getUsedCapacity();
430-
}
431-
432-
double capacityPct = (usedCapacity / totalCapacity);
433-
double thresholdLimit = 1.0;
434-
DataCenterVO dcVO = _dcDao.findById(dataCenterId);
435-
String dcName = ((dcVO == null) ? "unknown" : dcVO.getName());
436-
String podName = "";
437-
if( podId != null){
438-
HostPodVO pod = _podDao.findById(podId);
439-
podName = ((pod == null) ? "unknown" : pod.getName());
440-
}
441-
String msgSubject = "";
442-
String msgContent = "";
443-
String totalStr = "";
444-
String usedStr = "";
445-
String pctStr = formatPercent(capacityPct);
446-
447-
// check for over threshold
448-
switch (capacityType) {
449-
case CapacityVO.CAPACITY_TYPE_MEMORY:
450-
thresholdLimit = _memoryCapacityThreshold;
451-
msgSubject = "System Alert: Low Available Memory in pod "+podName+" of availablity zone " + dcName;
452-
totalStr = formatBytesToMegabytes(totalCapacity);
453-
usedStr = formatBytesToMegabytes(usedCapacity);
454-
msgContent = "System memory is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
455-
break;
456-
case CapacityVO.CAPACITY_TYPE_CPU:
457-
thresholdLimit = _cpuCapacityThreshold;
458-
msgSubject = "System Alert: Low Unallocated CPU in pod "+podName+" of availablity zone " + dcName;
459-
totalStr = _dfWhole.format(totalCapacity);
460-
usedStr = _dfWhole.format(usedCapacity);
461-
msgContent = "Unallocated CPU is low, total: " + totalStr + " Mhz, used: " + usedStr + " Mhz (" + pctStr + "%)";
462-
break;
463-
case CapacityVO.CAPACITY_TYPE_STORAGE:
464-
thresholdLimit = _storageCapacityThreshold;
465-
msgSubject = "System Alert: Low Available Storage in pod "+podName+" of availablity zone " + dcName;
466-
totalStr = formatBytesToMegabytes(totalCapacity);
467-
usedStr = formatBytesToMegabytes(usedCapacity);
468-
msgContent = "Available storage space is low, total: " + totalStr + " MB, used: " + usedStr + " MB (" + pctStr + "%)";
469-
break;
470-
case CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED:
471-
thresholdLimit = _storageAllocCapacityThreshold;
472-
msgSubject = "System Alert: Remaining unallocated Storage is low in pod "+podName+" of availablity zone " + dcName;
473-
totalStr = formatBytesToMegabytes(totalCapacity);
474-
usedStr = formatBytesToMegabytes(usedCapacity);
475-
msgContent = "Unallocated storage space is low, total: " + totalStr + " MB, allocated: " + usedStr + " MB (" + pctStr + "%)";
476-
break;
477-
case CapacityVO.CAPACITY_TYPE_PUBLIC_IP:
478-
thresholdLimit = _publicIPCapacityThreshold;
479-
msgSubject = "System Alert: Number of unallocated public IPs is low in availablity zone " + dcName;
480-
totalStr = Double.toString(totalCapacity);
481-
usedStr = Double.toString(usedCapacity);
482-
msgContent = "Number of unallocated public IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
483-
break;
484-
case CapacityVO.CAPACITY_TYPE_PRIVATE_IP:
485-
thresholdLimit = _privateIPCapacityThreshold;
486-
msgSubject = "System Alert: Number of unallocated private IPs is low in pod "+podName+" of availablity zone " + dcName;
487-
totalStr = Double.toString(totalCapacity);
488-
usedStr = Double.toString(usedCapacity);
489-
msgContent = "Number of unallocated private IPs is low, total: " + totalStr + ", allocated: " + usedStr + " (" + pctStr + "%)";
490-
break;
491-
}
492-
493-
if (capacityPct > thresholdLimit) {
494-
_emailAlert.sendAlert(capacityType, dataCenterId, null, msgSubject, msgContent);
495-
} else {
496-
_emailAlert.clearAlert(capacityType, dataCenterId, null);
497-
}
498-
}
388+
try {
389+
checkForAlerts();
499390
} catch (Exception ex) {
500391
s_logger.error("Exception in CapacityChecker", ex);
501392
}
502393
}
503394
}
504395

505396

506-
public void newAlertSystem(){
397+
public void checkForAlerts(){
398+
507399
recalculateCapacity();
508400

509401
// abort if we can't possibly send an alert...

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public enum Config {
100100
MemoryCapacityThreshold("Usage", ManagementServer.class, Float.class, "memory.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of memory utilization above which alerts will be sent about low memory available.", null),
101101
PublicIpCapacityThreshold("Usage", ManagementServer.class, Float.class, "public.ip.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of public IP address space utilization above which alerts will be sent.", null),
102102
PrivateIpCapacityThreshold("Usage", ManagementServer.class, Float.class, "private.ip.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of private IP address space utilization above which alerts will be sent.", null),
103+
SecondaryStorageCapacityThreshold("Usage", ManagementServer.class, Float.class, "secondarystorage.capacity.threshold", "0.85", "Percentage (as a value between 0 and 1) of secondary storage utilization above which alerts will be sent about low storage available.", null),
103104

104105
// Console Proxy
105106
ConsoleProxyCapacityStandby("Console Proxy", AgentManager.class, String.class, "consoleproxy.capacity.standby", "10", "The minimal number of console proxy viewer sessions that system is able to serve immediately(standby capacity)", null),

0 commit comments

Comments
 (0)