func.go 956 B

12345678910111213141516171819202122232425262728293031
  1. package utils
  2. import (
  3. "time"
  4. "github.com/go-admin-team/go-admin-core/sdk/config"
  5. )
  6. func MetricTableName(prefix string, startTime, endTime int64) (string, time.Time, time.Time) {
  7. diff := endTime - startTime
  8. suffix := "_15s"
  9. start, end := time.Unix(startTime, 0), time.Unix(endTime, 0)
  10. if diff == 300 {
  11. suffix = "_5m"
  12. start = time.Unix(startTime, 0).Truncate(5 * time.Minute)
  13. end = start.Add(time.Duration(diff) * time.Second)
  14. } else if diff == 1200 {
  15. suffix = "_20m"
  16. start = time.Unix(startTime, 0).Truncate(20 * time.Minute)
  17. end = start.Add(time.Duration(diff) * time.Second)
  18. } else if diff >= 3600 {
  19. suffix = "_1h"
  20. start = time.Unix(startTime, 0).Truncate(time.Hour)
  21. end = start.Add(time.Duration(diff) * time.Second)
  22. }
  23. if config.ApplicationConfig.Mode == "dev" { // 由于当前只有_15s的有数据
  24. suffix = "_15s"
  25. start, end = time.Unix(startTime, 0), time.Unix(endTime, 0)
  26. }
  27. return prefix + suffix, start, end
  28. }