View a markdown version of this page

Úselo GetServiceGraph con un AWS SDK o CLI - AWS Ejemplos de código de SDK

Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK.

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

Úselo GetServiceGraph con un AWS SDK o CLI

Los siguientes ejemplos de código muestran cómo utilizar GetServiceGraph.

CLI
AWS CLI

Para obtener un gráfico de servicio

En el ejemplo siguiente se muestra un documento dentro de un período de tiempo determinado que describe los servicios que procesan solicitudes entrantes y los servicios posteriores a los que llaman como resultado.

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

Salida:

{ "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 }

Para obtener más información, consulte Uso de la API de AWS X-Ray con la AWS CLI en la Guía para desarrolladores de AWS X-Ray.

  • Para obtener más información sobre la API, consulte GetServiceGraphla Referencia de AWS CLI comandos.

Java
SDK para Java 2.x
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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); } } }
  • Para obtener más información sobre la API, consulta GetServiceGraphla Referencia AWS SDK for Java 2.x de la API.

Kotlin
SDK para Kotlin
nota

Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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}") } } }
  • Para obtener más información sobre la API, consulta GetServiceGraphla referencia sobre el AWS SDK para la API de Kotlin.