parse duration

This commit is contained in:
Mitsuhiro Tanda 2017-09-07 15:56:16 +09:00
parent c6607f3fa7
commit 110f157621
1 changed files with 13 additions and 3 deletions

View File

@ -254,9 +254,19 @@ func parseQuery(model *simplejson.Json) (*CloudWatchQuery, error) {
p = "60"
}
}
period, err := strconv.Atoi(p)
if err != nil {
return nil, err
period := 300
if regexp.MustCompile(`^\d+$`).Match([]byte(p)) {
period, err = strconv.Atoi(p)
if err != nil {
return nil, err
}
} else {
d, err := time.ParseDuration(p)
if err != nil {
return nil, err
}
period = int(d.Seconds())
}
alias := model.Get("alias").MustString("{{metric}}_{{stat}}")