View a markdown version of this page

AWS SDK 또는 CLI와 GetServiceGraph 함께 사용 - AWS SDK 코드 예제

Doc AWS SDK 예제 GitHub 리포지토리에서 더 많은 SDK 예제를 사용할 수 있습니다. AWS

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

AWS SDK 또는 CLI와 GetServiceGraph 함께 사용

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

CLI
AWS CLI

서비스 그래프 가져오기

다음 예제에서는 수신 요청을 처리하는 서비스와 그 결과로 호출하는 다운스트림 서비스를 설명하는 지정된 기간 내의 문서를 표시합니다.

aws xray get-service-graph \ --start-time 1568835392.0 --end-time 1568835446.0

출력:

{ "Services": [ { "ReferenceId": 0, "Name": "Scorekeep", "Names": [ "Scorekeep" ], "Root": true, "Type": "AWS::ElasticBeanstalk::Environment", "State": "active", "StartTime": 1568835392.0, "EndTime": 1568835446.0, "Edges": [ { "ReferenceId": 1, "StartTime": 1568835392.0, "EndTime": 1568835446.0, "SummaryStatistics": { "OkCount": 14, "ErrorStatistics": { "ThrottleCount": 0, "OtherCount": 0, "TotalCount": 0 }, "FaultStatistics": { "OtherCount": 0, "TotalCount": 0 }, "TotalCount": 14, "TotalResponseTime": 0.13 }, "ResponseTimeHistogram": [ { "Value": 0.008, "Count": 1 }, { "Value": 0.005, "Count": 7 }, { "Value": 0.009, "Count": 1 }, { "Value": 0.021, "Count": 1 }, { "Value": 0.038, "Count": 1 }, { "Value": 0.007, "Count": 1 }, { "Value": 0.006, "Count": 2 } ], "Aliases": [] }, ... TRUNCATED FOR BREVITY ... ] } ], "StartTime": 1568835392.0, "EndTime": 1568835446.0, "ContainsOldGroupVersions": false }

자세한 내용은 AWS X-Ray 개발자 안내서의 AWS CLI에서 X-Ray API 사용을 참조하세요. AWS

  • API 세부 정보는 AWS CLI 명령 참조의 GetServiceGraph 섹션을 참조하세요.

Java
SDK for Java 2.x
참고

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

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.xray.XRayClient; import software.amazon.awssdk.services.xray.model.GetServiceGraphRequest; import software.amazon.awssdk.services.xray.model.GetServiceGraphResponse; import software.amazon.awssdk.services.xray.model.Service; import software.amazon.awssdk.services.xray.model.XRayException; import java.time.LocalDateTime; import java.time.Instant; import java.time.ZoneId; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class GetServiceGraph { public static void main(String[] args) { final String usage = """ Usage: <groupName> Where: groupName - The name of a group based on which you want to generate a graph. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String groupName = args[0]; Region region = Region.US_EAST_1; XRayClient xRayClient = XRayClient.builder() .region(region) .build(); getGraph(xRayClient, groupName); } public static void getGraph(XRayClient xRayClient, String groupName) { try { // The Instant values have to be 6 hours apart. LocalDateTime localDateTime = LocalDateTime.parse("2022-03-09T06:00:00"); Instant start = localDateTime.atZone(ZoneId.of("America/New_York")).toInstant(); LocalDateTime localDateTime2 = LocalDateTime.parse("2022-03-09T12:00:00"); Instant end = localDateTime2.atZone(ZoneId.of("America/New_York")).toInstant(); GetServiceGraphRequest getServiceGraphRequest = GetServiceGraphRequest.builder() .groupName(groupName) .startTime(start) .endTime(end) .build(); GetServiceGraphResponse graphResponse = xRayClient.getServiceGraph(getServiceGraphRequest); List<Service> services = graphResponse.services(); for (Service service : services) { System.out.println("The name of the service is " + service.name()); } } catch (XRayException e) { System.err.println(e.getMessage()); System.exit(1); } } }
  • API 세부 정보는 API 참조의 GetServiceGraphAWS SDK for Java 2.x 를 참조하세요.

Kotlin
SDK for Kotlin
참고

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

suspend fun getGraph(groupNameVal: String?) { val time = aws.smithy.kotlin.runtime.time.Instant val getServiceGraphRequest = GetServiceGraphRequest { groupName = groupNameVal this.startTime = time.now() endTime = time.now() } XRayClient.fromEnvironment { region = "us-east-1" }.use { xRayClient -> val response = xRayClient.getServiceGraph(getServiceGraphRequest) response.services?.forEach { service -> println("The name of the service is ${service.name}") } } }
  • API 세부 정보는 SDK for Kotlin API 참조의 GetServiceGraph를 참조하세요. AWS