Browse Source

parse duration

Mitsuhiro Tanda 8 năm trước cách đây
mục cha
commit
110f157621
1 tập tin đã thay đổi với 13 bổ sung3 xóa
  1. 13 3
      pkg/tsdb/cloudwatch/cloudwatch.go

+ 13 - 3
pkg/tsdb/cloudwatch/cloudwatch.go

@@ -254,9 +254,19 @@ func parseQuery(model *simplejson.Json) (*CloudWatchQuery, error) {
 			p = "60"
 			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}}")
 	alias := model.Get("alias").MustString("{{metric}}_{{stat}}")