private createFleetAlarms()

in packages/aws-rfdk/lib/core/lib/health-monitor.ts [431:487]


  private createFleetAlarms(
    monitorableFleet: IMonitorableFleet,
    healthCheckConfig: HealthCheckConfig,
    loadBalancer: ApplicationLoadBalancer,
    targetGroup: ApplicationTargetGroup) {

    monitorableFleet.connections.allowFrom(loadBalancer,
      Port.tcp(healthCheckConfig.port || HealthMonitor.LOAD_BALANCER_LISTENING_PORT));

    const percentMetric = new MathExpression({
      label: 'UnhealthyHostPercent',
      expression: 'IF(fleetCapacity, 100*(unhealthyHostCount/fleetCapacity), 0)',
      usingMetrics: {
        unhealthyHostCount: targetGroup.metrics.unhealthyHostCount({
          statistic: 'max',
        }),
        fleetCapacity: monitorableFleet.targetCapacityMetric,
      },
      period: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_HARD,
    });

    // When unhealthy fleet is more than healthyFleetThresholdPercent or 35% at any given period of 5 minutes
    const immediateTerminationAlarm = percentMetric.createAlarm(monitorableFleet.targetScope, 'UnhealthyFleetTermination', {
      treatMissingData: TreatMissingData.NOT_BREACHING,
      threshold: 100 - (healthCheckConfig.healthyFleetThresholdPercent || HealthMonitor.DEFAULT_HEALTHY_FLEET_THRESHOLD_PERCENT_HARD),
      comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
      evaluationPeriods: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_THRESHOLD_HARD,
      datapointsToAlarm: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_THRESHOLD_HARD,
      actionsEnabled: true,
    });
    immediateTerminationAlarm.addAlarmAction(this.alarmTopicAction);

    // When at least one node is unhealthy over a period of 2 hours
    const percentMetricGracePeriod = new MathExpression({
      label: 'UnhealthyHostPercent',
      expression: 'IF(fleetCapacity, 100*(unhealthyHostCount/fleetCapacity), 0)',
      usingMetrics: {
        unhealthyHostCount: targetGroup.metrics.unhealthyHostCount({
          statistic: 'max',
        }),
        fleetCapacity: monitorableFleet.targetCapacityMetric,
      },
      period: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_GRACE,
    });

    const gracePeriodTerminationAlarm = percentMetricGracePeriod.createAlarm(monitorableFleet.targetScope, 'UnhealthyFleetGracePeriod', {
      treatMissingData: TreatMissingData.NOT_BREACHING,
      threshold: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_THRESHOLD_PERCENT_GRACE,
      comparisonOperator: ComparisonOperator.GREATER_THAN_THRESHOLD,
      evaluationPeriods: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_THRESHOLD_GRACE,
      datapointsToAlarm: HealthMonitor.DEFAULT_UNHEALTHY_FLEET_ALARM_PERIOD_THRESHOLD_GRACE,
      actionsEnabled: true,
    });
    gracePeriodTerminationAlarm.addAlarmAction(this.alarmTopicAction);

    (monitorableFleet.targetUpdatePolicy as Policy).attachToRole(this.unhealthyFleetActionLambda.role as IRole);
  }