使用 Application Discovery 服务示例 Amazon CLI - Amazon Command Line Interface
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 Application Discovery 服务示例 Amazon CLI

以下代码示例向您展示了如何使用与 Application Discovery Service Amazon Command Line Interface 配合使用来执行操作和实现常见场景。

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景和跨服务示例的上下文查看操作。

场景是展示如何通过在同一服务中调用多个函数来完成特定任务任务的代码示例。

每个示例都包含一个指向的链接 GitHub,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 describe-agents

Amazon CLI

描述具有指定收集状态的代理

此示例命令描述了收集状态为 “已启动” 或 “已停止” 的收集代理。

命令:

aws discovery describe-agents --filters name="collectionStatus",values="STARTED","STOPPED",condition="EQUALS" --max-results 3

输出:

{ "Snapshots": [ { "version": "1.0.40.0", "agentType": "EC2", "hostName": "ip-172-31-40-234", "collectionStatus": "STOPPED", "agentNetworkInfoList": [ { "macAddress": "06:b5:97:14:fc:0d", "ipAddress": "172.31.40.234" } ], "health": "UNKNOWN", "agentId": "i-003305c02a776e883", "registeredTime": "2016-12-09T19:05:06Z", "lastHealthPingTime": "2016-12-09T19:05:10Z" }, { "version": "1.0.40.0", "agentType": "EC2", "hostName": "ip-172-31-39-64", "collectionStatus": "STARTED", "agentNetworkInfoList": [ { "macAddress": "06:a1:0e:c7:b2:73", "ipAddress": "172.31.39.64" } ], "health": "SHUTDOWN", "agentId": "i-003a5e5e2b36cf8bd", "registeredTime": "2016-11-16T16:36:25Z", "lastHealthPingTime": "2016-11-16T16:47:37Z" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考DescribeAgents中的。

以下代码示例演示如何使用 describe-configurations

Amazon CLI

描述选定的资产配置

此示例命令描述了两台指定服务器的配置。该操作会从配置 ID 中检测资产的类型。每条命令只允许使用一种类型的资产。

命令:

aws discovery describe-configurations --configuration-ids "d-server-099385097ef9fbcfb" "d-server-0c4f2dd1fee22c6c1"

输出:

{ "configurations": [ { "server.performance.maxCpuUsagePct": "0.0", "server.performance.maxDiskReadIOPS": "0.0", "server.performance.avgCpuUsagePct": "0.0", "server.type": "EC2", "server.performance.maxNetworkReadsPerSecondInKB": "0.19140625", "server.hostName": "ip-172-31-35-152", "server.configurationId": "d-server-0c4f2dd1fee22c6c1", "server.tags.hasMoreValues": "false", "server.performance.minFreeRAMInKB": "1543496.0", "server.osVersion": "3.14.48-33.39.amzn1.x86_64", "server.performance.maxDiskReadsPerSecondInKB": "0.0", "server.applications": "[]", "server.performance.numDisks": "1", "server.performance.numCpus": "1", "server.performance.numCores": "1", "server.performance.maxDiskWriteIOPS": "0.0", "server.performance.maxNetworkWritesPerSecondInKB": "0.82421875", "server.performance.avgDiskWritesPerSecondInKB": "0.0", "server.networkInterfaceInfo": "[{\"name\":\"eth0\",\"macAddress\":\"06:A7:7D:3F:54:57\",\"ipAddress\":\"172.31.35.152\",\"netMask\":\"255.255.240.0\"},{\"name\":\"lo\",\"macAddress\":\"00:00:00:00:00:00\",\"ipAddress\":\"127.0.0.1\",\"netMask\":\"255.0.0.0\"},{\"name\":\"eth0\",\"macAddress\":\"06:A7:7D:3F:54:57\",\"ipAddress\":\"fe80::4a7:7dff:fe3f:5457\"},{\"name\":\"lo\",\"macAddress\":\"00:00:00:00:00:00\",\"ipAddress\":\"::1\"}]", "server.performance.avgNetworkReadsPerSecondInKB": "0.04915364583333333", "server.tags": "[]", "server.applications.hasMoreValues": "false", "server.timeOfCreation": "2016-10-28 23:44:00.0", "server.agentId": "i-4447bc1b", "server.performance.maxDiskWritesPerSecondInKB": "0.0", "server.performance.avgDiskReadIOPS": "0.0", "server.performance.avgFreeRAMInKB": "1547210.1333333333", "server.performance.avgDiskReadsPerSecondInKB": "0.0", "server.performance.avgDiskWriteIOPS": "0.0", "server.performance.numNetworkCards": "2", "server.hypervisor": "xen", "server.networkInterfaceInfo.hasMoreValues": "false", "server.performance.avgNetworkWritesPerSecondInKB": "0.1380859375", "server.osName": "Linux - Amazon Linux AMI release 2015.03", "server.performance.totalRAMInKB": "1694732.0", "server.cpuType": "x64" }, { "server.performance.maxCpuUsagePct": "100.0", "server.performance.maxDiskReadIOPS": "0.0", "server.performance.avgCpuUsagePct": "14.733333333333338", "server.type": "EC2", "server.performance.maxNetworkReadsPerSecondInKB": "13.400390625", "server.hostName": "ip-172-31-42-208", "server.configurationId": "d-server-099385097ef9fbcfb", "server.tags.hasMoreValues": "false", "server.performance.minFreeRAMInKB": "1531104.0", "server.osVersion": "3.14.48-33.39.amzn1.x86_64", "server.performance.maxDiskReadsPerSecondInKB": "0.0", "server.applications": "[]", "server.performance.numDisks": "1", "server.performance.numCpus": "1", "server.performance.numCores": "1", "server.performance.maxDiskWriteIOPS": "1.0", "server.performance.maxNetworkWritesPerSecondInKB": "12.271484375", "server.performance.avgDiskWritesPerSecondInKB": "0.5333333333333334", "server.networkInterfaceInfo": "[{\"name\":\"eth0\",\"macAddress\":\"06:4A:79:60:75:61\",\"ipAddress\":\"172.31.42.208\",\"netMask\":\"255.255.240.0\"},{\"name\":\"eth0\",\"macAddress\":\"06:4A:79:60:75:61\",\"ipAddress\":\"fe80::44a:79ff:fe60:7561\"},{\"name\":\"lo\",\"macAddress\":\"00:00:00:00:00:00\",\"ipAddress\":\"::1\"},{\"name\":\"lo\",\"macAddress\":\"00:00:00:00:00:00\",\"ipAddress\":\"127.0.0.1\",\"netMask\":\"255.0.0.0\"}]", "server.performance.avgNetworkReadsPerSecondInKB": "2.8720052083333334", "server.tags": "[]", "server.applications.hasMoreValues": "false", "server.timeOfCreation": "2016-10-28 23:44:30.0", "server.agentId": "i-c142b99e", "server.performance.maxDiskWritesPerSecondInKB": "4.0", "server.performance.avgDiskReadIOPS": "0.0", "server.performance.avgFreeRAMInKB": "1534946.4", "server.performance.avgDiskReadsPerSecondInKB": "0.0", "server.performance.avgDiskWriteIOPS": "0.13333333333333336", "server.performance.numNetworkCards": "2", "server.hypervisor": "xen", "server.networkInterfaceInfo.hasMoreValues": "false", "server.performance.avgNetworkWritesPerSecondInKB": "1.7977864583333332", "server.osName": "Linux - Amazon Linux AMI release 2015.03", "server.performance.totalRAMInKB": "1694732.0", "server.cpuType": "x64" } ] }

描述选定的资产配置

此示例命令描述了两个指定应用程序的配置。该操作会从配置 ID 中检测资产的类型。每条命令只允许使用一种类型的资产。

命令:

aws discovery describe-configurations --configuration-ids "d-application-0ac39bc0e4fad0e42" "d-application-02444a45288013764q"

输出:

{ "configurations": [ { "application.serverCount": "0", "application.name": "Application-12345", "application.lastModifiedTime": "2016-12-13 23:53:27.0", "application.description": "", "application.timeOfCreation": "2016-12-13 23:53:27.0", "application.configurationId": "d-application-0ac39bc0e4fad0e42" }, { "application.serverCount": "0", "application.name": "Application-67890", "application.lastModifiedTime": "2016-12-13 23:53:33.0", "application.description": "", "application.timeOfCreation": "2016-12-13 23:53:33.0", "application.configurationId": "d-application-02444a45288013764" } ] }

以下代码示例演示如何使用 list-configurations

Amazon CLI

列出所有搜索到的符合一组筛选条件的服务器

此示例命令列出了已发现的与两种主机名模式中的任何一个匹配且未运行 Ubuntu 的服务器。

命令:

aws discovery list-configurations --configuration-type SERVER --filters name="server.hostName",values="172-31-35","172-31-42",condition="CONTAINS" name="server.osName",values="Ubuntu",condition="NOT_CONTAINS"

输出:

{ "configurations": [ { "server.osVersion": "3.14.48-33.39.amzn1.x86_64", "server.type": "EC2", "server.hostName": "ip-172-31-42-208", "server.timeOfCreation": "2016-10-28 23:44:30.0", "server.configurationId": "d-server-099385097ef9fbcfb", "server.osName": "Linux - Amazon Linux AMI release 2015.03", "server.agentId": "i-c142b99e" }, { "server.osVersion": "3.14.48-33.39.amzn1.x86_64", "server.type": "EC2", "server.hostName": "ip-172-31-35-152", "server.timeOfCreation": "2016-10-28 23:44:00.0", "server.configurationId": "d-server-0c4f2dd1fee22c6c1", "server.osName": "Linux - Amazon Linux AMI release 2015.03", "server.agentId": "i-4447bc1b" } ] }
  • 有关 API 的详细信息,请参阅Amazon CLI 命令参考ListConfigurations中的。