简体   繁体   中英

How do I fetch the hourly average CPUUtilization for my cluster?

I would like to be able to fetch the hourly average CPUUtilization for my cluster. But using amazonica I get this error: 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})

Running this aws cmd returns the correct metric, but I want to use amazonica to do this.

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

Due to the documentation :start-time and :end-time must be a Date object. It does not work with string in your example. You can also take a look at this example

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM