0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AutoScaling - EnableMetricsパラメータ

Last updated at Posted at 2015-07-29

ManagementConsoleの画面にあるので存在は何となく知っていましたが、
よく把握していなかったのでaws-cliで試してみました。

(初投稿になります。宜しくお願い致します。)

EnableMetricsパラメータ

1.概要

  • 説明: AutoScalingのメトリクスを追加生成するためのパラメータ
  • 使いどころ: AutoScalingGroupのインスタンス数の推移などをCloudWatchに記録したい場合
  • 値に登録するもの: 生成するAutoScalingのメトリクス名
"EnabledMetrics": [
                      {
                          "Metric": "GroupPendingInstances",  #生成するメトリクス名
                          "Granularity": "1Minute"             #メトリクスのデータの送信間隔(粒度) / 1Minute固定
                      },
             ]
  • 表示コマンド
$ aws autoscaling describe-auto-scaling-groups
  • 設定コマンド
$ aws autoscaling enable-metrics-collection
  • 注意点
    • LaunchConfigurationのDetailed Monitoringの有効化が必須
    • メトリクスを追加生成すると課金が発生(恐らくカスタムメトリクスとして扱われるのかと…。)

2. 設定状況の確認

$ aws autoscaling describe-auto-scaling-groups
{
    "AutoScalingGroups": [
        {
            "AutoScalingGroupARN": "arn:aws:autoscaling:ap-northeast-1:111111111111111111:autoScalingGroupName/ASG1",
            "HealthCheckGracePeriod": 0,
            "SuspendedProcesses": [],
            "DesiredCapacity": 2,
            "Tags": [],
            "EnabledMetrics": [],  #デフォルトは値が空
            "LoadBalancerNames": [],
            "AutoScalingGroupName": "ASG1",
            "DefaultCooldown": 300,
            "MinSize": 2,
            "Instances": [
                {
                    "InstanceId": "i-xxxxxxx",
                    "AvailabilityZone": "ap-northeast-1c",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "InService",
                    "LaunchConfigurationName": "LC1"
                },
                {
                    "InstanceId": "i-yyyyyyy",
                    "AvailabilityZone": "ap-northeast-1a",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "Pending",
                    "LaunchConfigurationName": "LC1"
                }
            ],
            "MaxSize": 4,
            "VPCZoneIdentifier": "subnet-xxxxxxxxx,subnet-yyyyyyyy",
            "TerminationPolicies": [
                "Default"
            ],
            "LaunchConfigurationName": "LC1",
            "CreatedTime": "2015-07-29T05:40:52.323Z",
            "AvailabilityZones": [
                "ap-northeast-1c",
                "ap-northeast-1a"
            ],
            "HealthCheckType": "EC2"
        }
    ]
}

3. EnableMetricsの値に設定できるものの一覧表示

$ aws autoscaling describe-metric-collection-types
{
    "Metrics": [                          #値に設定できるものの一覧
        {
            "Metric": "GroupMinSize"
        },
        {
            "Metric": "GroupMaxSize"
        },
        {
            "Metric": "GroupDesiredCapacity"
        },
        {
            "Metric": "GroupInServiceInstances"
        },
        {
            "Metric": "GroupPendingInstances"
        },
        {
            "Metric": "GroupTerminatingInstances"
        },
        {
            "Metric": "GroupStandbyInstances"
        },
        {
            "Metric": "GroupTotalInstances"
        }
    ],
    "Granularities": [     #粒度に設定できるものの一覧
        {
            "Granularity": "1Minute"
        }
    ]
}

4. EnableMetricsの有効化(すべてのメトリクスを生成)

--metricsオプションを指定しないと、生成可能なすべてのメトリクスを作ることができます。

$ aws autoscaling enable-metrics-collection --auto-scaling-group-name MyAutoScalingGroup --granularity "1Minute"

参考:EnableMetricsに値を設定するには、LaunchConfigurationのDetailedMonitoringをEnableが必須です

AutoScalingのメトリクスに送られる情報の粒度が1Minute固定なので、enableにしていないと怒られます。

$ aws autoscaling enable-metrics-collection --auto-scaling-group-name ASG1 --granularity "1Minute"

A client error (ValidationError) occurred when calling the EnableMetricsCollection operation: Your group must use a launch configuration with 'InstanceMonitoring' enabled to be able to use group metrics.

5-1. 確認(aws-cli / autoscaling)

$ aws autoscaling  describe-auto-scaling-groups
{
    "AutoScalingGroups": [
        {
            "AutoScalingGroupARN": "arn:aws:autoscaling:ap-northeast-1:xxxxxxxx:autoScalingGroup:yyyyyyy:autoScalingGroupName/ASG1",
            "HealthCheckGracePeriod": 0,
            "SuspendedProcesses": [],
            "DesiredCapacity": 2,
            "Tags": [],
            "EnabledMetrics": [
                {
                    "Metric": "GroupPendingInstances", #Pending中のインスタンス
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupMaxSize",     #maxの設定値
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupDesiredCapacity",  #Desiredの値
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupInServiceInstances", #InServiceのインスタンス数
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupTerminatingInstances",  #Terminate中のインスタンス数
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupMinSize",  #minの設定値
                    "Granularity": "1Minute"
                },
                {
                    "Metric": "GroupTotalInstances",  #In Service+Pending+Terminatingの合計値
                    "Granularity": "1Minute"  #粒度
                }
            ],
            "LoadBalancerNames": [],
            "AutoScalingGroupName": "ASG1",
            "DefaultCooldown": 300,
            "MinSize": 2,
            "Instances": [
                {
                    "InstanceId": "i-xxxxxxxx",
                    "AvailabilityZone": "ap-northeast-1c",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "InService",
                    "LaunchConfigurationName": "LC1"
                },
                {
                    "InstanceId": "i-yyyyyyyyy",
                    "AvailabilityZone": "ap-northeast-1a",
                    "HealthStatus": "Healthy",
                    "LifecycleState": "InService",
                    "LaunchConfigurationName": "LC1"
                }
            ],
            "MaxSize": 4,
            "VPCZoneIdentifier": "subnet-xxxxxxxx,subnet-yyyyyyyy",
            "TerminationPolicies": [
                "Default"
            ],
            "LaunchConfigurationName": "LC1",
            "CreatedTime": "2015-07-29T05:40:52.323Z",
            "AvailabilityZones": [
                "ap-northeast-1c",
                "ap-northeast-1a"
            ],
            "HealthCheckType": "EC2"
        }
    ]
}

5-2. 確認(ManagementConsole / CloudWatch)

CloudWatchに新しく「Auto Scaling」のネームスペースと、登録したメトリクスが見えています。

WS000187.JPG

6. まとめ

  • 課金は発生しますが、値に追加生成するメトリクスを登録するとCloudWatchからAutoScalingGroup内のインスタンスの動作履歴をグラフで追うことができ、とても便利です。
  • 料金面がクリアされれば、AutoScaling使用時はマストでONという認識でもいいのではないかと個人的には思っています。
  • やっぱり機能をしっかり把握するにはaws-cliやSDKの方が分かりやすいですね。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?