簡體   English   中英

為什么與jclouds一起使用的CloudWatch API getMetricStatisticsInRegion會引發UndeclaredThrowableException?

[英]Why does the CloudWatch API getMetricStatisticsInRegion used with jclouds throw an UndeclaredThrowableException?

我正在嘗試獲取CloudWatch指標,但出現以下錯誤:

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

重要的代碼段如下:

    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------");

    }

最終版本的Cloudwatch為不同的語法。 請查看cloudwatch-basics示例並使用jclouds 1.5.3+版本,看看是否仍然遇到問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM