.withValue(instanceId); PutMetricAlarmRequest request = new PutMetricAlarmRequest() .withAlarmName(alarmName) .withComparisonOperator( ComparisonOperator.GreaterThanThreshold) .withEvaluationPeriods(1) .withMetricName("CPUUtilization") .withNamespace("AWS/EC2") .withPeriod(60) .withStatistic(Statistic.Average) .withThreshold(70.0) .withActionsEnabled(false) .withAlarmDescription( "Alarm when server CPU utilization exceeds 70%") .withUnit(StandardUnit.Seconds) .withDimensions(dimension);
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAlarmName() == null) ? 0 : getAlarmName().hashCode()); hashCode = prime * hashCode + ((getAlarmDescription() == null) ? 0 : getAlarmDescription().hashCode()); hashCode = prime * hashCode + ((getActionsEnabled() == null) ? 0 : getActionsEnabled().hashCode()); hashCode = prime * hashCode + ((getOKActions() == null) ? 0 : getOKActions().hashCode()); hashCode = prime * hashCode + ((getAlarmActions() == null) ? 0 : getAlarmActions().hashCode()); hashCode = prime * hashCode + ((getInsufficientDataActions() == null) ? 0 : getInsufficientDataActions().hashCode()); hashCode = prime * hashCode + ((getMetricName() == null) ? 0 : getMetricName().hashCode()); hashCode = prime * hashCode + ((getNamespace() == null) ? 0 : getNamespace().hashCode()); hashCode = prime * hashCode + ((getStatistic() == null) ? 0 : getStatistic().hashCode()); hashCode = prime * hashCode + ((getExtendedStatistic() == null) ? 0 : getExtendedStatistic().hashCode()); hashCode = prime * hashCode + ((getDimensions() == null) ? 0 : getDimensions().hashCode()); hashCode = prime * hashCode + ((getPeriod() == null) ? 0 : getPeriod().hashCode()); hashCode = prime * hashCode + ((getUnit() == null) ? 0 : getUnit().hashCode()); hashCode = prime * hashCode + ((getEvaluationPeriods() == null) ? 0 : getEvaluationPeriods().hashCode()); hashCode = prime * hashCode + ((getDatapointsToAlarm() == null) ? 0 : getDatapointsToAlarm().hashCode()); hashCode = prime * hashCode + ((getThreshold() == null) ? 0 : getThreshold().hashCode()); hashCode = prime * hashCode + ((getComparisonOperator() == null) ? 0 : getComparisonOperator().hashCode()); hashCode = prime * hashCode + ((getTreatMissingData() == null) ? 0 : getTreatMissingData().hashCode()); hashCode = prime * hashCode + ((getEvaluateLowSampleCountPercentile() == null) ? 0 : getEvaluateLowSampleCountPercentile().hashCode()); hashCode = prime * hashCode + ((getMetrics() == null) ? 0 : getMetrics().hashCode()); return hashCode; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAlarmName() == null) ? 0 : getAlarmName().hashCode()); hashCode = prime * hashCode + ((getAlarmDescription() == null) ? 0 : getAlarmDescription().hashCode()); hashCode = prime * hashCode + ((getActionsEnabled() == null) ? 0 : getActionsEnabled().hashCode()); hashCode = prime * hashCode + ((getOKActions() == null) ? 0 : getOKActions().hashCode()); hashCode = prime * hashCode + ((getAlarmActions() == null) ? 0 : getAlarmActions().hashCode()); hashCode = prime * hashCode + ((getInsufficientDataActions() == null) ? 0 : getInsufficientDataActions() .hashCode()); hashCode = prime * hashCode + ((getMetricName() == null) ? 0 : getMetricName().hashCode()); hashCode = prime * hashCode + ((getNamespace() == null) ? 0 : getNamespace().hashCode()); hashCode = prime * hashCode + ((getStatistic() == null) ? 0 : getStatistic().hashCode()); hashCode = prime * hashCode + ((getDimensions() == null) ? 0 : getDimensions().hashCode()); hashCode = prime * hashCode + ((getPeriod() == null) ? 0 : getPeriod().hashCode()); hashCode = prime * hashCode + ((getUnit() == null) ? 0 : getUnit().hashCode()); hashCode = prime * hashCode + ((getEvaluationPeriods() == null) ? 0 : getEvaluationPeriods().hashCode()); hashCode = prime * hashCode + ((getThreshold() == null) ? 0 : getThreshold().hashCode()); hashCode = prime * hashCode + ((getComparisonOperator() == null) ? 0 : getComparisonOperator().hashCode()); return hashCode; }
/** * <p> * The arithmetic operation to use when comparing the specified statistic and threshold. The specified statistic * value is used as the first operand. * </p> * * @param comparisonOperator * The arithmetic operation to use when comparing the specified statistic and threshold. The specified * statistic value is used as the first operand. * @see ComparisonOperator */ public void setComparisonOperator(ComparisonOperator comparisonOperator) { withComparisonOperator(comparisonOperator); }
/** * <p> * The statistic for the metric specified in <code>MetricName</code>, other than percentile. For percentile * statistics, use <code>ExtendedStatistic</code>. When you call <code>PutMetricAlarm</code> and specify a * <code>MetricName</code>, you must specify either <code>Statistic</code> or <code>ExtendedStatistic,</code> but * not both. * </p> * * @param statistic * The statistic for the metric specified in <code>MetricName</code>, other than percentile. For percentile * statistics, use <code>ExtendedStatistic</code>. When you call <code>PutMetricAlarm</code> and specify a * <code>MetricName</code>, you must specify either <code>Statistic</code> or <code>ExtendedStatistic,</code> * but not both. * @see Statistic */ public void setStatistic(Statistic statistic) { withStatistic(statistic); }
/** * <p> * The unit of measure for the statistic. For example, the units for the Amazon EC2 NetworkIn metric are Bytes * because NetworkIn tracks the number of bytes that an instance receives on all network interfaces. You can also * specify a unit when you create a custom metric. Units help provide conceptual meaning to your data. Metric data * points that specify a unit of measure, such as Percent, are aggregated separately. * </p> * <p> * If you specify a unit, you must use a unit that is appropriate for the metric. Otherwise, the CloudWatch alarm * can get stuck in the <code>INSUFFICIENT DATA</code> state. * </p> * * @param unit * The unit of measure for the statistic. For example, the units for the Amazon EC2 NetworkIn metric are * Bytes because NetworkIn tracks the number of bytes that an instance receives on all network interfaces. * You can also specify a unit when you create a custom metric. Units help provide conceptual meaning to your * data. Metric data points that specify a unit of measure, such as Percent, are aggregated separately.</p> * <p> * If you specify a unit, you must use a unit that is appropriate for the metric. Otherwise, the CloudWatch * alarm can get stuck in the <code>INSUFFICIENT DATA</code> state. * @see StandardUnit */ public void setUnit(StandardUnit unit) { withUnit(unit); }
/** * <p> * The dimensions for the alarm's associated metric. * </p> * <p> * Returns a reference to this object so that method calls can be chained * together. * * @param dimensions <p> * The dimensions for the alarm's associated metric. * </p> * @return A reference to this updated object so that method calls can be * chained together. */ public PutMetricAlarmRequest withDimensions(Dimension... dimensions) { if (getDimensions() == null) { this.dimensions = new java.util.ArrayList<Dimension>(dimensions.length); } for (Dimension value : dimensions) { this.dimensions.add(value); } return this; }
if (getAlarmActions() == null) { this.alarmActions = new java.util.ArrayList<String>(alarmActions.length);
StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAlarmName() != null) sb.append("AlarmName: " + getAlarmName() + ","); if (getAlarmDescription() != null) sb.append("AlarmDescription: " + getAlarmDescription() + ","); if (getActionsEnabled() != null) sb.append("ActionsEnabled: " + getActionsEnabled() + ","); if (getOKActions() != null) sb.append("OKActions: " + getOKActions() + ","); if (getAlarmActions() != null) sb.append("AlarmActions: " + getAlarmActions() + ","); if (getInsufficientDataActions() != null) sb.append("InsufficientDataActions: " + getInsufficientDataActions() + ","); if (getMetricName() != null) sb.append("MetricName: " + getMetricName() + ","); if (getNamespace() != null) sb.append("Namespace: " + getNamespace() + ","); if (getStatistic() != null) sb.append("Statistic: " + getStatistic() + ","); if (getDimensions() != null) sb.append("Dimensions: " + getDimensions() + ","); if (getPeriod() != null) sb.append("Period: " + getPeriod() + ","); if (getUnit() != null) sb.append("Unit: " + getUnit() + ","); if (getEvaluationPeriods() != null) sb.append("EvaluationPeriods: " + getEvaluationPeriods() + ","); if (getThreshold() != null)
return false; PutMetricAlarmRequest other = (PutMetricAlarmRequest) obj; if (other.getAlarmName() == null ^ this.getAlarmName() == null) return false; if (other.getAlarmName() != null && other.getAlarmName().equals(this.getAlarmName()) == false) return false; if (other.getAlarmDescription() == null ^ this.getAlarmDescription() == null) return false; if (other.getAlarmDescription() != null && other.getAlarmDescription().equals(this.getAlarmDescription()) == false) return false; if (other.getActionsEnabled() == null ^ this.getActionsEnabled() == null) return false; if (other.getActionsEnabled() != null && other.getActionsEnabled().equals(this.getActionsEnabled()) == false) return false; if (other.getOKActions() == null ^ this.getOKActions() == null) return false; if (other.getOKActions() != null && other.getOKActions().equals(this.getOKActions()) == false) return false; if (other.getAlarmActions() == null ^ this.getAlarmActions() == null) return false; if (other.getAlarmActions() != null && other.getAlarmActions().equals(this.getAlarmActions()) == false) return false; if (other.getInsufficientDataActions() == null ^ this.getInsufficientDataActions() == null) return false; if (other.getInsufficientDataActions() != null && other.getInsufficientDataActions().equals(this.getInsufficientDataActions()) == false) return false; if (other.getMetricName() == null ^ this.getMetricName() == null) return false; if (other.getMetricName() != null && other.getMetricName().equals(this.getMetricName()) == false)
if (other.getAlarmName() == null ^ this.getAlarmName() == null) return false; if (other.getAlarmName() != null && other.getAlarmName().equals(this.getAlarmName()) == false) return false; if (other.getAlarmDescription() == null ^ this.getAlarmDescription() == null) return false; if (other.getAlarmDescription() != null && other.getAlarmDescription().equals(this.getAlarmDescription()) == false) return false; if (other.getActionsEnabled() == null ^ this.getActionsEnabled() == null) return false; if (other.getActionsEnabled() != null && other.getActionsEnabled().equals(this.getActionsEnabled()) == false) return false; if (other.getOKActions() == null ^ this.getOKActions() == null) return false; if (other.getOKActions() != null && other.getOKActions().equals(this.getOKActions()) == false) return false; if (other.getAlarmActions() == null ^ this.getAlarmActions() == null) return false; if (other.getAlarmActions() != null && other.getAlarmActions().equals(this.getAlarmActions()) == false) return false; if (other.getInsufficientDataActions() == null ^ this.getInsufficientDataActions() == null) return false; if (other.getInsufficientDataActions() != null && other.getInsufficientDataActions().equals(this.getInsufficientDataActions()) == false)
/** * A high-resolution alarm is one that is configured to fire on threshold breaches of high-resolution metrics. See * this [announcement](https://aws.amazon.com/about-aws/whats-new/2017/07/amazon-cloudwatch-introduces-high-resolution-custom-metrics-and-alarms/). * DynamoDB only publishes 1 minute consumed capacity metrics. By publishing high resolution consumed capacity * metrics on the client side, you can react and alarm on spikes in load much quicker. * @param alarmName name of the high resolution alarm to create * @param metricName name of the metric to alarm on * @param threshold threshold at which to alarm on after 5 breaches of the threshold */ private void createHighResolutionAlarm(String alarmName, String metricName, double threshold) { putMetricAlarm.apply(new PutMetricAlarmRequest() .withNamespace(CUSTOM_TABLE_METRICS_NAMESPACE) .withDimensions(tableDimension) .withMetricName(metricName) .withAlarmName(alarmName) .withStatistic(Statistic.Sum) .withUnit(StandardUnit.Count) .withComparisonOperator(ComparisonOperator.GreaterThanThreshold) .withDatapointsToAlarm(5).withEvaluationPeriods(5) //alarm when 5 out of 5 consecutive measurements are high .withActionsEnabled(false) //TODO add actions in a later PR .withPeriod(10) //high resolution alarm .withThreshold(10 * threshold)); }
StringBuilder sb = new StringBuilder(); sb.append("{"); if (getAlarmName() != null) sb.append("AlarmName: ").append(getAlarmName()).append(","); if (getAlarmDescription() != null) sb.append("AlarmDescription: ").append(getAlarmDescription()).append(","); if (getActionsEnabled() != null) sb.append("ActionsEnabled: ").append(getActionsEnabled()).append(","); if (getOKActions() != null) sb.append("OKActions: ").append(getOKActions()).append(","); if (getAlarmActions() != null) sb.append("AlarmActions: ").append(getAlarmActions()).append(","); if (getInsufficientDataActions() != null) sb.append("InsufficientDataActions: ").append(getInsufficientDataActions()).append(","); if (getMetricName() != null) sb.append("MetricName: ").append(getMetricName()).append(","); if (getNamespace() != null) sb.append("Namespace: ").append(getNamespace()).append(","); if (getStatistic() != null) sb.append("Statistic: ").append(getStatistic()).append(","); if (getExtendedStatistic() != null) sb.append("ExtendedStatistic: ").append(getExtendedStatistic()).append(","); if (getDimensions() != null) sb.append("Dimensions: ").append(getDimensions()).append(","); if (getPeriod() != null) sb.append("Period: ").append(getPeriod()).append(","); if (getUnit() != null) sb.append("Unit: ").append(getUnit()).append(","); if (getEvaluationPeriods() != null)
if (putMetricAlarmRequest.getAlarmName() != null) { prefix = "AlarmName"; String alarmName = putMetricAlarmRequest.getAlarmName(); request.addParameter(prefix, StringUtils.fromString(alarmName)); if (putMetricAlarmRequest.getAlarmDescription() != null) { prefix = "AlarmDescription"; String alarmDescription = putMetricAlarmRequest.getAlarmDescription(); request.addParameter(prefix, StringUtils.fromString(alarmDescription)); if (putMetricAlarmRequest.getActionsEnabled() != null) { prefix = "ActionsEnabled"; Boolean actionsEnabled = putMetricAlarmRequest.getActionsEnabled(); request.addParameter(prefix, StringUtils.fromBoolean(actionsEnabled)); if (putMetricAlarmRequest.getOKActions() != null) { prefix = "OKActions"; java.util.List<String> oKActions = putMetricAlarmRequest.getOKActions(); int oKActionsIndex = 1; String oKActionsPrefix = prefix; if (putMetricAlarmRequest.getAlarmActions() != null) { prefix = "AlarmActions"; java.util.List<String> alarmActions = putMetricAlarmRequest.getAlarmActions(); int alarmActionsIndex = 1; String alarmActionsPrefix = prefix; if (putMetricAlarmRequest.getInsufficientDataActions() != null) { prefix = "InsufficientDataActions";
if (putMetricAlarmRequest.getAlarmName() != null) { request.addParameter("AlarmName", StringUtils.fromString(putMetricAlarmRequest.getAlarmName())); if (putMetricAlarmRequest.getAlarmDescription() != null) { request.addParameter("AlarmDescription", StringUtils.fromString(putMetricAlarmRequest.getAlarmDescription())); if (putMetricAlarmRequest.getActionsEnabled() != null) { request.addParameter("ActionsEnabled", StringUtils.fromBoolean(putMetricAlarmRequest.getActionsEnabled())); if (!putMetricAlarmRequest.getOKActions().isEmpty() || !((com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest.getOKActions()).isAutoConstruct()) { com.amazonaws.internal.SdkInternalList<String> oKActionsList = (com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest .getOKActions(); int oKActionsListIndex = 1; if (!putMetricAlarmRequest.getAlarmActions().isEmpty() || !((com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest.getAlarmActions()).isAutoConstruct()) { com.amazonaws.internal.SdkInternalList<String> alarmActionsList = (com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest .getAlarmActions(); int alarmActionsListIndex = 1; if (!putMetricAlarmRequest.getInsufficientDataActions().isEmpty() || !((com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest.getInsufficientDataActions()).isAutoConstruct()) { com.amazonaws.internal.SdkInternalList<String> insufficientDataActionsList = (com.amazonaws.internal.SdkInternalList<String>) putMetricAlarmRequest .getInsufficientDataActions(); int insufficientDataActionsListIndex = 1; if (putMetricAlarmRequest.getMetricName() != null) { request.addParameter("MetricName", StringUtils.fromString(putMetricAlarmRequest.getMetricName()));