如何获取EC2实例的CloudWatch指标数据 [英] How to fetch the CloudWatch metrics data for EC2 instances

查看:624
本文介绍了如何获取EC2实例的CloudWatch指标数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取EC2实例的Cloudmetrics数据,以便我可以使用这些数据绘制图形并将其显示在我的Android设备上。我怎么做?是否有相同的示例程序或教程?

I want to fetch the Cloudmetrics data for my EC2 instance so that I can draw graphs using those data and display it on my android device. How do I do that? Is there any sample program or tutorial for the same?

提前致谢。

这就是我的意思做:

private static void findCloudWatchData()  {

    AmazonCloudWatchClient cloudWatch = new AmazonCloudWatchClient(new BasicAWSCredentials(AccessKey, SecretKey));
    cloudWatch.setEndpoint("monitoring.us-east-1.amazonaws.com");
    long offsetInMilliseconds = 1000 * 60 * 60 * 24;
    Dimension instanceDimension = new Dimension();
    instanceDimension.setName("instanceid");
    instanceDimension.setValue(instanceid);

    GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
            .withStartTime(new Date(new Date().getTime() - offsetInMilliseconds))
            .withNamespace("AWS/EC2")
            .withPeriod(60 * 60)
            .withMetricName("CPUUtilization")
            .withStatistics("Average")
            .withDimensions(Arrays.asList(instanceDimension))
            .withEndTime(new Date());

    GetMetricStatisticsResult getMetricStatisticsResult = cloudWatch.getMetricStatistics(request);
    }


推荐答案

正如您已标记了您的问题使用 android 我假设您要在 Android-App 中为您的EC2实例获取CloudWatch-Metrics。
所以这可能是一个很好的起点:

As you have tagged your question with android I assume that you want to fetch CloudWatch-Metrics for your EC2 Instances in an Android-App. So this might be a good starting point for you:

  • Getting Started with the AWS SDK for Android .

您需要:


  1. 下载适用于Android的AWS开发工具包

  2. 为AWS创建访问密钥(通过IAM)

  3. 读取 aws-android-sdk-VERSION-cloudwatch.jar 的文档

  4. 开始使用CloudWatch中提取的数据

  1. download AWS SDK for Android
  2. create your access keys for AWS (via IAM)
  3. read the documentation for aws-android-sdk-VERSION-cloudwatch.jar
  4. start using the fetched data from CloudWatch

问候

Tom

这篇关于如何获取EC2实例的CloudWatch指标数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆