

• 2026 年 4 月 30 日之後將不再提供 AWS Systems Manager CloudWatch Dashboard。客戶可以繼續使用 Amazon CloudWatch 主控台來檢視、建立和管理其 Amazon CloudWatch 儀表板，就像現在一樣。如需詳細資訊，請參閱 [Amazon CloudWatch Dashboard 文件](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 彙總庫存資料
<a name="inventory-aggregate"></a>

為 AWS Systems Manager 庫存設定受管節點後，您可以檢視庫存資料的彙總計數。例如，假設您配置了數十或數百個受管節點來收集 `AWS:Application` 庫存類型。透過本節涵蓋的資訊，您能夠查看經過設定用於收集此資料的節點確切計數。

您也可以彙整資料類型，以查看特定庫存詳細資訊。例如：`AWS:InstanceInformation` 庫存類型會收集包含 `Platform` 資料類型的作業系統平台資訊。透過彙總 `Platform` 資料類型的相關資料，您可以快速查看執行 Windows Server、執行 Linux 和執行 macOS 的節點數量。

本節中的程序說明如何使用 AWS Command Line Interface () 檢視庫存資料的彙總計數AWS CLI。您也可以在**庫存**頁面的 AWS Systems Manager 主控台中檢視預先設定的彙總計數。這些預先設定的儀表板通稱為「庫存詳情」。只需按一下，即可修正庫存組態問題。

檢視庫存資料彙整計數時，請注意以下重要詳細資訊：
+ 如果您終止設定為收集庫存資料的受管節點，Systems Manager 會保留庫存資料 30 天，然後將其刪除。對於執行中的節點，系統會刪除超過 30 天的庫存資料。如果您需要存放庫存資料超過 30 天，您可以使用 AWS Config 記錄歷史記錄或定期查詢，並將資料上傳至 Amazon Simple Storage Service (Amazon S3) 儲存貯體。
+ 如果您先前將節點設定成報告特定庫存資料類型 (如 `AWS:Network`)，之後為了停止收集該類型而變更組態，則彙整計數仍會顯示 `AWS:Network` 資料，直到節點終止且 30 天過去。

如需有關如何快速設定和收集特定 AWS 帳戶 （以及可能在該帳戶中建立的任何未來節點） 中所有節點庫存資料的資訊，請參閱 [清查 中的所有受管節點 AWS 帳戶](inventory-collection.md#inventory-management-inventory-all)。

**Topics**
+ [彙總庫存資料以查看收集特定資料類型的節點計數](#inventory-aggregate-type)
+ [使用群組彙總庫存資料，以查看哪些節點已設定和未設定成收集某個庫存類型](#inventory-aggregate-groups)

## 彙總庫存資料以查看收集特定資料類型的節點計數
<a name="inventory-aggregate-type"></a>

您可以使用 AWS Systems Manager [GetInventory](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_GetInventory.html) API 操作來檢視收集一或多個庫存類型和資料類型的節點彙總計數。例如，`AWS:InstanceInformation` 庫存類型可讓您將 GetInventory API 操作與 `AWS:InstanceInformation.PlatformType` 資料類型搭配使用，檢視作業系統的彙總。下方為 AWS CLI 命令和輸出的範例。

```
aws ssm get-inventory --aggregators "Expression=AWS:InstanceInformation.PlatformType"
```

系統會傳回如下資訊。

```
{
   "Entities":[
      {
         "Data":{
            "AWS:InstanceInformation":{
               "Content":[
                  {
                     "Count":"7",
                     "PlatformType":"windows"
                  },
                  {
                     "Count":"5",
                     "PlatformType":"linux"
                  }
               ]
            }
         }
      }
   ]
}
```

**開始使用**  
決定要檢視其計數的庫存類型和資料類型。如需檢視支援彙整功能的庫存類型和資料類型，請在 AWS CLI中執行以下命令。

```
aws ssm get-inventory-schema --aggregator
```

該命令會針對支援彙整功能的庫存類型和資料類型，傳回一份 JSON 清單。**TypeName** 欄位會顯示支援的庫存類型。**Name (名稱)** 欄位則會顯示每個資料類型。以以下清單為例，`AWS:Application` 庫存類型包含 `Name` 和 `Version` 的資料類型。

```
{
    "Schemas": [
        {
            "TypeName": "AWS:Application",
            "Version": "1.1",
            "DisplayName": "Application",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "Version"
                }
            ]
        },
        {
            "TypeName": "AWS:InstanceInformation",
            "Version": "1.0",
            "DisplayName": "Platform",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "PlatformName"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformType"
                },
                {
                    "DataType": "STRING",
                    "Name": "PlatformVersion"
                }
            ]
        },
        {
            "TypeName": "AWS:ResourceGroup",
            "Version": "1.0",
            "DisplayName": "ResourceGroup",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                }
            ]
        },
        {
            "TypeName": "AWS:Service",
            "Version": "1.0",
            "DisplayName": "Service",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "DisplayName"
                },
                {
                    "DataType": "STRING",
                    "Name": "ServiceType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Status"
                },
                {
                    "DataType": "STRING",
                    "Name": "StartType"
                }
            ]
        },
        {
            "TypeName": "AWS:WindowsRole",
            "Version": "1.0",
            "DisplayName": "WindowsRole",
            "Attributes": [
                {
                    "DataType": "STRING",
                    "Name": "Name"
                },
                {
                    "DataType": "STRING",
                    "Name": "DisplayName"
                },
                {
                    "DataType": "STRING",
                    "Name": "FeatureType"
                },
                {
                    "DataType": "STRING",
                    "Name": "Installed"
                }
            ]
        }
    ]
}
```

使用以下語法建立命令，即可彙整任何列出的庫存類型資料。

```
aws ssm get-inventory --aggregators "Expression={{InventoryType}}.{{DataType}}"
```

請見下方範例。

**範例 1**

此範例彙總了節點使用的 Windows 角色計數。

```
aws ssm get-inventory --aggregators "Expression=AWS:WindowsRole.Name"
```

**範例 2**

此範例彙總了節點上安裝的應用程式計數。

```
aws ssm get-inventory --aggregators "Expression=AWS:Application.Name"
```

**結合多個彙總工具**  
您還能在一個命令中結合多個庫存類型與資料類型，有助於更全面了解相關資料。請見下方範例。

**範例 1**

此範例彙總了節點使用的作業系統類型計數。此命令亦可傳回特定的作業系統名稱。

```
aws ssm get-inventory --aggregators '[{"Expression": "AWS:InstanceInformation.PlatformType", "Aggregators":[{"Expression": "AWS:InstanceInformation.PlatformName"}]}]'
```

**範例 2**

此範例彙總了節點上執行的應用程式計數，以及每個應用程式的特定版本。

```
aws ssm get-inventory --aggregators '[{"Expression": "AWS:Application.Name", "Aggregators":[{"Expression": "AWS:Application.Version"}]}]'
```

如果您願意，還可以在 JSON 檔案中利用一個或多個庫存類型和資料類型來建立彙總表達式，並從 AWS CLI呼叫該檔案。檔案中的 JSON 物件必須採用以下語法。

```
[
       {
           "Expression": "string",
           "Aggregators": [
               {
                  "Expression": "string"
               }
           ]
       }
]
```

請務必使用 .json 副檔名儲存檔案。

以下是運用多個庫存類型和資料類型的範例。

```
[
       {
           "Expression": "AWS:Application.Name",
           "Aggregators": [
               {
                   "Expression": "AWS:Application.Version",
                   "Aggregators": [
                     {
                     "Expression": "AWS:InstanceInformation.PlatformType"
                     }
                   ]
               }
           ]
       }
]
```

使用下列命令，即可從 AWS CLI呼叫檔案。

```
aws ssm get-inventory --aggregators file://{{file_name}}.json
```

該命令會傳回相關資訊，如以下所示。

```
{"Entities": 
 [
   {"Data": 
     {"AWS:Application": 
       {"Content": 
         [
           {"Count": "3", 
            "PlatformType": "linux", 
            "Version": "2.6.5", 
            "Name": "audit-libs"}, 
           {"Count": "2", 
            "PlatformType": "windows", 
            "Version": "2.6.5", 
            "Name": "audit-libs"}, 
           {"Count": "4", 
            "PlatformType": "windows", 
            "Version": "6.2.8", 
            "Name": "microsoft office"}, 
           {"Count": "2", 
            "PlatformType": "windows", 
            "Version": "2.6.5", 
            "Name": "chrome"}, 
           {"Count": "1", 
            "PlatformType": "linux", 
            "Version": "2.6.5", 
            "Name": "chrome"}, 
           {"Count": "2", 
            "PlatformType": "linux", 
            "Version": "6.3", 
            "Name": "authconfig"}
         ]
       }
     }, 
    "ResourceType": "ManagedInstance"}
 ]
}
```

## 使用群組彙總庫存資料，以查看哪些節點已設定和未設定成收集某個庫存類型
<a name="inventory-aggregate-groups"></a>

Systems Manager 庫存中的群組可供您快速查看設定成收集一個或多個庫存類型的受管節點計數，以及未進行設定的執行個體數。透過群組功能，您可以指定一個或多個庫存類型，並使用 `exists` 運算子做為篩選條件。

例如，假設您分別設定四個受管節點，以收集下列庫存類型：
+ 節點 1：`AWS:Application`
+ 節點 2：`AWS:File`
+ 節點 3：`AWS:Application`、`AWS:File`
+ 節點 4：`AWS:Network`

您可以從 執行下列命令 AWS CLI ，以查看有多少節點設定為同時收集 `AWS:Application`和 `AWS:File inventory`類型。同時，回應還會傳回未設定成收集這兩種庫存類型的節點數。

```
aws ssm get-inventory --aggregators 'Groups=[{Name=ApplicationAndFile,Filters=[{Key=TypeName,Values=[AWS:Application],Type=Exists},{Key=TypeName,Values=[AWS:File],Type=Exists}]}]'
```

該命令回應顯示僅有一個受管節點經過設定，會同時收集 `AWS:Application` 與 `AWS:File` 庫存類型。

```
{
   "Entities":[
      {
         "Data":{
            "ApplicationAndFile":{
               "Content":[
                  {
                     "notMatchingCount":"3"
                  },
                  {
                     "matchingCount":"1"
                  }
               ]
            }
         }
      }
   ]
}
```

**注意**  
群組不會傳回資料類型計數。您也無法深入檢視結果，以查看已設定或未設定成收集庫存類型的節點 ID。

如果您願意，還可以在 JSON 檔案中利用一或多個庫存類型來建立彙整表達式，並從 AWS CLI呼叫該檔案。檔案中的 JSON 物件必須採用以下語法：

```
{
   "Aggregators":[
      {
         "Groups":[
            {
               "Name":"{{Name}}",
               "Filters":[
                  {
                     "Key":"TypeName",
                     "Values":[
                        "{{Inventory_type}}"
                     ],
                     "Type":"Exists"
                  },
                  {
                     "Key":"TypeName",
                     "Values":[
                        "{{Inventory_type}}"
                     ],
                     "Type":"Exists"
                  }
               ]
            }
         ]
      }
   ]
}
```

請務必使用 .json 副檔名儲存檔案。

使用下列命令，即可從 AWS CLI呼叫檔案。

```
aws ssm get-inventory --cli-input-json file://{{file_name}}.json
```

**其他範例**  
下列範例會示範彙整庫存資料的方式，使您能查看設定成收集特定庫存類型的受管節點，以及未設定的受管節點。這些範例皆是採用 AWS CLI。每個範例均包含具備篩選功能的完整命令。如此一來，當您想在檔案中輸入資訊時，便能從命令列和範例 input.json 檔案中執行該命令。

**範例 1**

此範例會彙整設定成收集 `AWS:Application` 或 `AWS:File` 庫存類型的節點計數，以及未經過設定的執行個體數。

從 AWS CLI執行下列命令。

```
aws ssm get-inventory --aggregators 'Groups=[{Name=ApplicationORFile,Filters=[{Key=TypeName,Values=[AWS:Application, AWS:File],Type=Exists}]}]'
```

若您偏好使用檔案，則可複製下方範例並貼至檔案，接著將其儲存為 input.json。

```
{
   "Aggregators":[
      {
         "Groups":[
            {
               "Name":"ApplicationORFile",
               "Filters":[
                  {
                     "Key":"TypeName",
                     "Values":[
                        "AWS:Application",
                        "AWS:File"
                     ],
                     "Type":"Exists"
                  }
               ]
            }
         ]
      }
   ]
}
```

從 AWS CLI執行下列命令。

```
aws ssm get-inventory --cli-input-json file://input.json
```

該命令會傳回相關資訊，如以下所示。

```
{
   "Entities":[
      {
         "Data":{
            "ApplicationORFile":{
               "Content":[
                  {
                     "notMatchingCount":"1"
                  },
                  {
                     "matchingCount":"3"
                  }
               ]
            }
         }
      }
   ]
}
```

**範例 2**

此範例會彙總設定成收集 `AWS:Application`、`AWS:File` 或 `AWS:Network` 庫存類型的節點計數，以及未經過設定的節點數。

從 AWS CLI執行下列命令。

```
aws ssm get-inventory --aggregators 'Groups=[{Name=Application,Filters=[{Key=TypeName,Values=[AWS:Application],Type=Exists}]}, {Name=File,Filters=[{Key=TypeName,Values=[AWS:File],Type=Exists}]}, {Name=Network,Filters=[{Key=TypeName,Values=[AWS:Network],Type=Exists}]}]'
```

若您偏好使用檔案，則可複製下方範例並貼至檔案，接著將其儲存為 input.json。

```
{
   "Aggregators":[
      {
         "Groups":[
            {
               "Name":"Application",
               "Filters":[
                  {
                     "Key":"TypeName",
                     "Values":[
                        "AWS:Application"
                     ],
                     "Type":"Exists"
                  }
               ]
            },
            {
               "Name":"File",
               "Filters":[
                  {
                     "Key":"TypeName",
                     "Values":[
                        "AWS:File"
                     ],
                     "Type":"Exists"
                  }
               ]
            },
            {
               "Name":"Network",
               "Filters":[
                  {
                     "Key":"TypeName",
                     "Values":[
                        "AWS:Network"
                     ],
                     "Type":"Exists"
                  }
               ]
            }
         ]
      }
   ]
}
```

從 AWS CLI執行下列命令。

```
aws ssm get-inventory --cli-input-json file://input.json
```

該命令會傳回相關資訊，如以下所示。

```
{
   "Entities":[
      {
         "Data":{
            "Application":{
               "Content":[
                  {
                     "notMatchingCount":"2"
                  },
                  {
                     "matchingCount":"2"
                  }
               ]
            },
            "File":{
               "Content":[
                  {
                     "notMatchingCount":"2"
                  },
                  {
                     "matchingCount":"2"
                  }
               ]
            },
            "Network":{
               "Content":[
                  {
                     "notMatchingCount":"3"
                  },
                  {
                     "matchingCount":"1"
                  }
               ]
            }
         }
      }
   ]
}
```