AWS SDK 또는 MonitorInstances CLI와 함께 사용 - Amazon Elastic Compute Cloud

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AWS SDK 또는 MonitorInstances CLI와 함께 사용

다음 코드 예제는 MonitorInstances의 사용 방법을 보여줍니다.

C++
SDK for C++
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

Aws::EC2::EC2Client ec2Client(clientConfiguration); Aws::EC2::Model::MonitorInstancesRequest request; request.AddInstanceIds(instanceId); request.SetDryRun(true); auto dry_run_outcome = ec2Client.MonitorInstances(request); if (dry_run_outcome.IsSuccess()) { std::cerr << "Failed dry run to enable monitoring on instance. A dry run should trigger an error." << std::endl; return false; } else if (dry_run_outcome.GetError().GetErrorType() != Aws::EC2::EC2Errors::DRY_RUN_OPERATION) { std::cerr << "Failed dry run to enable monitoring on instance " << instanceId << ": " << dry_run_outcome.GetError().GetMessage() << std::endl; return false; } request.SetDryRun(false); auto monitorInstancesOutcome = ec2Client.MonitorInstances(request); if (!monitorInstancesOutcome.IsSuccess()) { std::cerr << "Failed to enable monitoring on instance " << instanceId << ": " << monitorInstancesOutcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully enabled monitoring on instance " << instanceId << std::endl; }
  • API 세부 정보는 AWS SDK for C++ API MonitorInstances참조를 참조하십시오.

CLI
AWS CLI

인스턴스에 대한 세부 모니터링을 활성화하는 방법

이 예제 명령은 지정된 인스턴스에 대한 세부 모니터링을 활성화합니다.

명령:

aws ec2 monitor-instances --instance-ids i-1234567890abcdef0

출력:

{ "InstanceMonitorings": [ { "InstanceId": "i-1234567890abcdef0", "Monitoring": { "State": "pending" } } ] }
  • API 세부 정보는 AWS CLI 명령 MonitorInstances참조를 참조하십시오.

JavaScript
JavaScript (v3) 용 SDK
참고

더 많은 내용이 있습니다. GitHub AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

import { MonitorInstancesCommand } from "@aws-sdk/client-ec2"; import { client } from "../libs/client.js"; // Turn on detailed monitoring for the selected instance. // By default, metrics are sent to Amazon CloudWatch every 5 minutes. // For a cost you can enable detailed monitoring which sends metrics every minute. export const main = async () => { const command = new MonitorInstancesCommand({ InstanceIds: ["INSTANCE_ID"], }); try { const { InstanceMonitorings } = await client.send(command); const instancesBeingMonitored = InstanceMonitorings.map( (im) => ` • Detailed monitoring state for ${im.InstanceId} is ${im.Monitoring.State}.`, ); console.log("Monitoring status:"); console.log(instancesBeingMonitored.join("\n")); } catch (err) { console.error(err); } };
  • API 세부 정보는 AWS SDK for JavaScript API MonitorInstances참조를 참조하십시오.

PowerShell
다음을 위한 도구 PowerShell

예 1: 이 예제는 지정된 인스턴스에 대한 세부 모니터링을 활성화합니다.

Start-EC2InstanceMonitoring -InstanceId i-12345678

출력:

InstanceId Monitoring ---------- ---------- i-12345678 Amazon.EC2.Model.Monitoring
  • API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조를 참조하십시오 MonitorInstances.

SAP ABAP
SDK for SAP ABAP
참고

자세한 내용은 다음과 같습니다. GitHub AWS 코드 예제 리포지토리에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요.

DATA lt_instance_ids TYPE /aws1/cl_ec2instidstringlist_w=>tt_instanceidstringlist. APPEND NEW /aws1/cl_ec2instidstringlist_w( iv_value = iv_instance_id ) TO lt_instance_ids. "Perform dry run" TRY. " DryRun is set to true. This checks for the required permissions to monitor the instance without actually making the request. " lo_ec2->monitorinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_true ). CATCH /aws1/cx_rt_service_generic INTO DATA(lo_exception). " If the error code returned is `DryRunOperation`, then you have the required permissions to monitor this instance. " IF lo_exception->av_err_code = 'DryRunOperation'. MESSAGE 'Dry run to enable detailed monitoring completed.' TYPE 'I'. " DryRun is set to false to enable detailed monitoring. " lo_ec2->monitorinstances( it_instanceids = lt_instance_ids iv_dryrun = abap_false ). MESSAGE 'Detailed monitoring enabled.' TYPE 'I'. " If the error code returned is `UnauthorizedOperation`, then you don't have the required permissions to monitor this instance. " ELSEIF lo_exception->av_err_code = 'UnauthorizedOperation'. MESSAGE 'Dry run to enable detailed monitoring failed. User does not have the permissions to monitor the instance.' TYPE 'E'. ELSE. DATA(lv_error) = |"{ lo_exception->av_err_code }" - { lo_exception->av_err_msg }|. MESSAGE lv_error TYPE 'E'. ENDIF. ENDTRY.
  • API 세부 정보는 SAP용AWS SDK ABAP API 참조를 참조하십시오 MonitorInstances.

AWS SDK 개발자 가이드 및 코드 예제의 전체 목록은 을 참조하십시오. SDK를 사용하여 Amazon EC2 리소스 생성 AWS 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.