1

Ich versuche, Cloudwatch-Metriken zu erhalten, aber die folgende Fehlermeldung erhalten:Warum verursacht die CloudWatch-API getMetricStatisticsInRegion, die mit jclouds verwendet wird, eine UndeclaredThrowableException?

Exception in thread "main" java.lang.reflect.UndeclaredThrowableException 
    at $Proxy85.getMetricStatisticsInRegion(Unknown Source) 
    at GetStats.main(GetStats.java:73) 
Caused by: java.util.concurrent.ExecutionException: task submitted from the following trace 
    at org.jclouds.concurrent.config.ExecutorServiceModule$DescribedFuture.ensureCauseHasSubmissionTrace(ExecutorServiceModule.java:272) 
    at org.jclouds.concurrent.config.ExecutorServiceModule$DescribedFuture.get(ExecutorServiceModule.java:256) 
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69) 
    at com.google.common.util.concurrent.Futures$ChainingListenableFuture.get(Futures.java:661) 
    at org.jclouds.concurrent.ExceptionParsingListenableFuture.get(ExceptionParsingListenableFuture.java:76) 
    at org.jclouds.concurrent.internal.SyncProxy.invoke(SyncProxy.java:159) 
    ... 2 more 

Wichtige Code-Schnipsel wie folgt:

ComputeServiceContext EC2context = 
      new ComputeServiceContextFactory().createContext("aws-ec2", 
      accesskeyid, 
      secretkey, 
      ImmutableSet.<Module> of(new Log4JLoggingModule(), 
      new SshjSshClientModule())); 

    ComputeService ec2 = EC2context.getComputeService(); 

    for (ComputeMetadata c : ec2.listNodes()){ 
     NodeMetadata w = ec2.getNodeMetadata(c.getId()); 
     System.out.println(String.format("---node: %s(%s) status: %s---", 
       w.getId(), w.getName(),w.getState())); 

     RestContext<CloudWatchClient, CloudWatchAsyncClient> cloudWatchContext = 
         new RestContextFactory().createContext("aws-cloudwatch", 
                   accesskeyid, 
                   secretkey); 
     String region = w.getLocation().getParent().getId(); 


     Date startday = new Date(); 
     Date today = new Date(); 
     Calendar calendar; 
     calendar = Calendar.getInstance(); 
     calendar.setTime(today); 
     calendar.add(Calendar.DATE, -1); 
     startday = calendar.getTime(); 
     System.out.println("Today : " + today.toString()); 
     System.out.println("Startday: " + startday.toString()); 
     System.out.println("--going to fetch Average CPU--"); 

     CloudWatchClient client = cloudWatchContext.getApi(); 

     Set<Datapoint> datapoints = client.getMetricStatisticsInRegion(
        region, 
        "CPUUtilization", 
        "AWS/EC2", 
        startday, 
        today, 
        60, 
        Statistics.AVERAGE, 
        GetMetricStatisticsOptions.Builder.unit(Unit.PERCENT)); 
     System.out.println(String.format("---datapoint for %s---",c.getId())); 
     System.out.print(datapoints); 
     System.out.println("------end------"); 

    } 
+1

Ich habe Ihren Code ausgeführt und versucht, das Problem zu reproduzieren, aber es funktioniert für mich. Ich habe jclouds 1.3.2, 1.4.0 und 1.5.0-SNAPSHOT ausprobiert und alles funktioniert. Könnten Sie mehr Informationen über Ihre jclouds-Version und Ihre Umgebung geben? –

Antwort

0

Die endgültige Version von Cloudwatch als eine andere Syntax. Bitte schauen Sie sich das cloudwatch-basics Beispiel an und verwenden Sie jclouds Version 1.5.3+ und sehen Sie, ob Sie weiterhin auf Probleme stoßen.

Verwandte Themen