Skip to content

Commit

Permalink
feat(autoscaling): add instanceMonitoring option
Browse files Browse the repository at this point in the history
Gives users the option to choose between detailed and basic monitoring.
Defaults to detailed when not specified, maintaining current behavior.

fixes aws#8212
  • Loading branch information
rbobrowicz committed Jun 1, 2020
1 parent 46a1eaa commit 3142a98
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ To enable the max instance lifetime support, specify `maxInstanceLifetime` prope
for the `AutoscalingGroup` resource. The value must be between 7 and 365 days(inclusive).
To clear a previously set value, just leave this property undefinied.

### Instance Monitoring

To disable detailed instance monitoring, specify `instanceMonitoring` property
for the `AutoscalingGroup` resource as `Monitoring.BASIC`. Otherwise detailed monitoring
will be enabled.


### Future work
Expand Down
28 changes: 28 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ import { BlockDevice, BlockDeviceVolume, EbsDeviceVolumeType } from './volume';
*/
const NAME_TAG: string = 'Name';

/**
* The monitoring mode for instances launched in an autoscaling group
*/
export enum Monitoring {
/**
* Generates metrics every 5 minutes
*/
BASIC,

/**
* Generates metrics every minute
*/
DETAILED,
}

/**
* Basic properties of an AutoScalingGroup, except the exact machines to run and where they should run
*
Expand Down Expand Up @@ -199,6 +214,18 @@ export interface CommonAutoScalingGroupProps {
* @default none
*/
readonly maxInstanceLifetime?: Duration;

/**
* Controls whether instances in this group are launched with detailed or basic monitoring.
*
* When detailed monitoring is enabled, Amazon CloudWatch generates metrics every minute and your account
* is charged a fee. When you disable detailed monitoring, CloudWatch generates metrics every 5 minutes.
*
* @see https://docs.aws.amazon.com/autoscaling/latest/userguide/as-instance-monitoring.html#enable-as-instance-metrics
*
* @default Monitoring.DETAILED
*/
readonly instanceMonitoring?: Monitoring;
}

/**
Expand Down Expand Up @@ -468,6 +495,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements
imageId: imageConfig.imageId,
keyName: props.keyName,
instanceType: props.instanceType.toString(),
instanceMonitoring: props.instanceMonitoring !== undefined ? (props.instanceMonitoring === Monitoring.DETAILED) : undefined
securityGroups: securityGroupsToken,
iamInstanceProfile: iamProfile.ref,
userData: userDataToken,
Expand Down
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,26 @@ export = {
test.done();
},

'can configure instance monitoring'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = mockVpc(stack);

// WHEN
new autoscaling.AutoScalingGroup(stack, 'MyStack', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M4, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage(),
vpc,
instanceMonitoring: autoscaling.Monitoring.BASIC,
});

// THEN
expect(stack).to(haveResource('AWS::AutoScaling::LaunchConfiguration', {
InstanceMonitoring: false,
}));
test.done();
},

'throws if ephemeral volumeIndex < 0'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 3142a98

Please sign in to comment.