AdSense

網頁

2024/4/11

AWS CLI 取得TargetGroup UnHealthyHostCount cloudwatch metrics統計資料

使用AWS CLI取得TargetGroup UnHealthyHostCount cloudWatch metrics統計資料。。


範例環境:

  • AWS CLI version 2 (aws-cli/2.9.19)


事前要求

參考「AWS 建立Target Group (instance type)」建立Target Group。

參考「AWS 建立Load Balancer (Application Load Balancer)」建立Load Balancer。


取得TargetGroup UnHealthyHostCount metric統計資料

在命令列輸入AWS CLI命令aws cloudwatch get-metric-statistics --metric-name UnHealthyHostCount --start-time [START_TIME] --end-time [END_TIME] --period [PERIOD] --namespace AWS/ApplicationELB --statistics Maximum --dimensions Name=TargetGroup,Value=[RESOURCE_TYPE/RESOURCE_ID] Name=LoadBalancer,Value=[RESOURCE_ID]即可取得metrics資料,Dimension TargetGroupLoadBalancer的資源名稱參考這裡。例如:

% aws cloudwatch get-metric-statistics --metric-name UnHealthyHostCount --start-time 2024-04-11T08:00:00Z --end-time 2024-04-11T23:00:00Z --period 600 --namespace AWS/ApplicationELB --statistics Maximum --dimensions Name=TargetGroup,Value=targetgroup/targetgroup-1/64ca88052f98efc2 Name=LoadBalancer,Value=app/loadbalancer-1/8999f3ae6828336b

結果回傳如下:

{
    "Label": "UnHealthyHostCount",
    "Datapoints": [
        {
            "Timestamp": "2024-04-11T09:10:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2024-04-11T09:00:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2024-04-11T08:50:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2024-04-11T09:30:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2024-04-11T08:40:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        },
        {
            "Timestamp": "2024-04-11T09:20:00+00:00",
            "Maximum": 2.0,
            "Unit": "Count"
        }
    ]
}


沒有留言:

AdSense