【问题标题】:How do I fetch the hourly average CPUUtilization for my cluster?如何获取集群的每小时平均 CPUUtilization?
【发布时间】:2019-02-06 12:43:12
【问题描述】:

我希望能够获取集群的每小时平均 CPUUtilization。但是使用amazonica我得到这个错误:com.amazonaws.services.cloudwatch.model.InvalidParameterValueException: The parameter StartTime must not equal parameter EndTime.

(get-metric-statistics {:metric-name "CPUUtilization"
                        :namespace "AWS/ECS"
                        :dimensions [{:name  "ClusterName" :value "my-cluster"}]
                        :start-time "2018-08-31T12:00:00Z"
                        :end-time "2018-08-31T13:00:00Z"
                        :statistics ["Average"]
                        :period 3600})

运行此 aws cmd 会返回正确的指标,但我想使用 amazonica 来执行此操作。

aws cloudwatch get-metric-statistics \
--metric-name CPUUtilization \
--namespace AWS/ECS \
--dimensions Name=ClusterName,Value=my-cluster \
--start-time 2018-08-31T12:00:00Z \
--end-time 2018-08-31T13:00:00Z \
--statistics Average \
--period 3600

【问题讨论】:

    标签: amazon-web-services clojure amazonica


    【解决方案1】:

    由于documentation :start-time 和 :end-time 必须是 Date 对象。它不适用于您的示例中的字符串。你也可以看看这个example

    (let [date-string (.. (SimpleDateFormat. "MM-dd-yyyy")
                      (format (Date.)))]
       (get-metric-statistics
           ....
           :start-time (.minusDays (DateTime.) 1)
           :end-time date-string
           ...
          ))
    

    【讨论】:

    • 我认为非日期值也可以;其实Freid001发现下面也是一种方法::start-time (t/minus (t/now) (t/hours 1)) :end-time (t/now)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多