com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest.withPeriod()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest.withPeriod()方法的一些代码示例,展示了GetMetricStatisticsRequest.withPeriod()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GetMetricStatisticsRequest.withPeriod()方法的具体详情如下:
包路径:com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest
类名称:GetMetricStatisticsRequest
方法名:withPeriod

GetMetricStatisticsRequest.withPeriod介绍

[英]The granularity, in seconds, of the returned data points. For metrics with regular resolution, a period can be as short as one minute (60 seconds) and must be a multiple of 60. For high-resolution metrics that are collected at intervals of less than one minute, the period can be 1, 5, 10, 30, 60, or any multiple of 60. High-resolution metrics are those metrics stored by a PutMetricData call that includes a StorageResolution of 1 second.

If the StartTime parameter specifies a time stamp that is greater than 3 hours ago, you must specify the period as follows or no data points in that time range is returned:

  • Start time between 3 hours and 15 days ago - Use a multiple of 60 seconds (1 minute).
  • Start time between 15 and 63 days ago - Use a multiple of 300 seconds (5 minutes).
  • Start time greater than 63 days ago - Use a multiple of 3600 seconds (1 hour).
    [中]返回的数据点的粒度(以秒为单位)。对于具有常规分辨率的度量,周期可以短至一分钟(60秒),并且必须是60的倍数。对于以少于一分钟的间隔收集的高分辨率度量,周期可以是1、5、10、30、60或60的任意倍数。高分辨率指标是由PutMetricData调用存储的指标,该调用包括1秒的StorageResolution
    如果StartTime参数指定的时间戳大于3小时前,则必须按以下方式指定时间段,否则将不返回该时间范围内的数据点:
    *开始时间在3小时到15天前-使用60秒(1分钟)的倍数。
    *开始时间在15到63天前-使用300秒(5分钟)的倍数。
    *开始时间大于63天前-使用3600秒(1小时)的倍数。

代码示例

代码示例来源:origin: tmobile/pacbot

private static GetMetricStatisticsRequest request(
    final String funcationValue, int hours) {
  final long twentyFourHrs = 1000 * 60 * 60l * hours;
  final int oneHour = 60 * 60 * hours;
  return new GetMetricStatisticsRequest()
      .withStartTime(new Date(new Date().getTime() - twentyFourHrs))
      .withNamespace(PacmanRuleConstants.AWS_LAMBDA)
      .withPeriod(oneHour)
      .withDimensions(
          new Dimension().withName("FunctionName").withValue(
              funcationValue))
      .withMetricName(PacmanRuleConstants.INVOCATIONS)
      .withStatistics("Sum").withEndTime(new Date());
}

代码示例来源:origin: tmobile/pacbot

private static GetMetricStatisticsRequest request(
    final String funcationValue) {
  final int fiveMin = 60 * 60 * 24;
  return new GetMetricStatisticsRequest()
      .withStartTime(new Date(new Date().getTime() - TWENTYFOURHOURS))
      .withNamespace(PacmanRuleConstants.AWS_LAMBDA)
      .withPeriod(fiveMin)
      .withDimensions(
          new Dimension().withName(
              PacmanRuleConstants.FUNCTION_NAME).withValue(
              funcationValue))
      .withMetricName(PacmanRuleConstants.THROTTLES)
      .withStatistics(PacmanRuleConstants.SUM)
      .withEndTime(new Date());
}

代码示例来源:origin: awslabs/amazon-kinesis-scaling-utils

public StreamMetricManager(String streamName, List<KinesisOperationType> types, AmazonCloudWatch cloudWatchClient,
    AmazonKinesisClient kinesisClient) {
  this.streamName = streamName;
  this.trackedOperations.addAll(types);
  this.cloudWatchClient = cloudWatchClient;
  this.kinesisClient = kinesisClient;
  for (KinesisOperationType op : this.trackedOperations) {
    // create CloudWatch request templates for the information we have
    // at this point
    for (String metricName : op.getMetricsToFetch()) {
      GetMetricStatisticsRequest cwRequest = new GetMetricStatisticsRequest();
      cwRequest.withNamespace(CW_NAMESPACE)
          .withDimensions(new Dimension().withName("StreamName").withValue(this.streamName))
          .withPeriod(StreamMonitor.CLOUDWATCH_PERIOD).withStatistics(Statistic.Sum)
          .withMetricName(metricName);
      if (!this.cloudwatchRequestTemplates.containsKey(op)) {
        this.cloudwatchRequestTemplates.put(op, new ArrayList<GetMetricStatisticsRequest>() {
          {
            add(cwRequest);
          }
        });
      } else {
        this.cloudwatchRequestTemplates.get(op).add(cwRequest);
      }
    }
  }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-kinesis

GetMetricStatisticsRequest createMetricStatisticsRequest(
  String streamName, Instant countSince, Instant countTo, Minutes period) {
 return new GetMetricStatisticsRequest()
   .withNamespace(KINESIS_NAMESPACE)
   .withMetricName(INCOMING_RECORDS_METRIC)
   .withPeriod(period.getMinutes() * PERIOD_GRANULARITY_IN_SECONDS)
   .withStartTime(countSince.toDate())
   .withEndTime(countTo.toDate())
   .withStatistics(Collections.singletonList(SUM_STATISTIC))
   .withDimensions(
     Collections.singletonList(
       new Dimension().withName(STREAM_NAME_DIMENSION).withValue(streamName)));
}

代码示例来源:origin: classmethod/gradle-aws-plugin

public GetMetricStatisticsResult getMetricStatistics(String metricName, String namespace, String statistics,
    String extendedStatistics, String unit) throws AmazonServiceException {
  AwsCloudWatchPluginExtension ext = getProject().getExtensions().getByType(AwsCloudWatchPluginExtension.class);
  AmazonCloudWatch cw = ext.getClient();
  GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
    .withMetricName(metricName)
    .withNamespace(namespace)
    .withStatistics(statistics)
    .withExtendedStatistics(extendedStatistics)
    .withUnit(unit)
    .withEndTime(getEndTime())
    .withStartTime(getStartTime())
    .withPeriod(getPeriod());
  
  if (getDimensions() != null) {
    request.withDimensions(getDimensions().entrySet().stream()
      .map(it -> new Dimension()
        .withName(it.getKey().toString())
        .withValue(it.getValue()))
      .collect(Collectors.toList()));
  }
  
  GetMetricStatisticsResult response = cw.getMetricStatistics(request);
  for (Datapoint metric : response.getDatapoints()) {
    getLogger().debug("Retrieved metric %s", metric.getAverage());
  }
  return response;
}

代码示例来源:origin: yegor256/s3auth

@Override
  @Cacheable(lifetime = Tv.THIRTY, unit = TimeUnit.MINUTES)
  public long bytesTransferred() {
    final Date now = new Date();
    final List<Datapoint> datapoints =
      DefaultHost.this.cloudwatch.get().getMetricStatistics(
        new GetMetricStatisticsRequest()
          .withMetricName("BytesTransferred")
          .withNamespace("S3Auth")
          .withStatistics("Sum")
          .withDimensions(
            new Dimension()
              .withName("Bucket")
              .withValue(this.bucket)
          )
          .withUnit(StandardUnit.Bytes)
          .withPeriod((int) TimeUnit.DAYS.toSeconds(Tv.SEVEN))
          .withStartTime(DateUtils.addWeeks(now, -1))
          .withEndTime(now)
      ).getDatapoints();
    long sum = 0L;
    for (final Datapoint datapoint : datapoints) {
      sum += datapoint.getSum();
    }
    return sum;
  }
}

相关文章

微信公众号

最新文章

更多