You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cloudbrain_statistic.go 4.4 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package repo
  2. import (
  3. "time"
  4. "code.gitea.io/gitea/models"
  5. "code.gitea.io/gitea/modules/log"
  6. "code.gitea.io/gitea/modules/setting"
  7. "code.gitea.io/gitea/services/mailer"
  8. )
  9. func CloudbrainStatisticAuto() {
  10. yesterday := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  11. CloudbrainStatisticDaily(yesterday)
  12. }
  13. func CloudbrainStatisticDaily(date string) {
  14. log.Info("%s", date)
  15. log.Info("begin Cloudbrain Statistic")
  16. warnEmailMessage := "云脑任务统计信息入库失败,请尽快定位。"
  17. if err := models.DeleteCloudbrainStatisticDaily(date); err != nil {
  18. log.Error("DeleteCloudbrainStatisticDaily failed: %v", err.Error())
  19. mailer.SendWarnNotifyMail(setting.Warn_Notify_Mails, warnEmailMessage)
  20. return
  21. }
  22. //0 to 23 for each hour, 25 for all 24 hours
  23. var WhichHour [25]int64 = [25]int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25}
  24. for _, whichHour := range WhichHour {
  25. log.Info("start statistic: %s", date)
  26. var beginTime, endTime time.Time
  27. beginTime, endTime = models.GetHourStatTime(date, whichHour)
  28. if whichHour == 25 {
  29. beginTime, endTime = models.GetDayStatTime(date)
  30. }
  31. numDubugOne, err := models.GetDebugOneCount(beginTime, endTime)
  32. if err != nil {
  33. log.Error("GetDebugOneCount failed(%s): %v", numDubugOne, err)
  34. }
  35. numBenchmarkOne, err := models.GetBenchmarkOneCount(beginTime, endTime)
  36. if err != nil {
  37. log.Error("GetBenchmarkOneCount failed(%s): %v", numBenchmarkOne, err)
  38. }
  39. numTrainOne, err := models.GetTrainOneCount(beginTime, endTime)
  40. if err != nil {
  41. log.Error("GetTrainOneCount failed(%s): %v", numTrainOne, err)
  42. }
  43. numDebugTwo, err := models.GetDebugTwoCount(beginTime, endTime)
  44. if err != nil {
  45. log.Error("GetDebugTwoCount failed(%s): %v", numDebugTwo, err)
  46. }
  47. numTrainTwo, err := models.GetTrainTwoCount(beginTime, endTime)
  48. if err != nil {
  49. log.Error("GetTrainTwoCount failed(%s): %v", numTrainTwo, err)
  50. }
  51. numInferenceTwo, err := models.GetInferenceTwoCount(beginTime, endTime)
  52. if err != nil {
  53. log.Error("GetInferenceTwoCount failed(%s): %v", numInferenceTwo, err)
  54. }
  55. numCloudOneAll := numDubugOne + numBenchmarkOne + numTrainOne
  56. numCloudTwoAll := numDebugTwo + numTrainTwo + numInferenceTwo
  57. durationDubugOne, err := models.GetDebugOneDuration(beginTime, endTime)
  58. if err != nil {
  59. log.Error("GetDebugOneDuration failed(%s): %v", durationDubugOne, err)
  60. }
  61. durationBenchmarkOne, err := models.GetBenchmarkOneDuration(beginTime, endTime)
  62. if err != nil {
  63. log.Error("GetBenchmarkOneDuration failed(%s): %v", durationBenchmarkOne, err)
  64. }
  65. durationTrainOne, err := models.GetTrainOneDuration(beginTime, endTime)
  66. if err != nil {
  67. log.Error("GetTrainOneDuration failed(%s): %v", durationTrainOne, err)
  68. }
  69. durationDebugTwo, err := models.GetDebugTwoDuration(beginTime, endTime)
  70. if err != nil {
  71. log.Error("GetDebugTwoDuration failed(%s): %v", durationDebugTwo, err)
  72. }
  73. durationTrainTwo, err := models.GetTrainTwoDuration(beginTime, endTime)
  74. if err != nil {
  75. log.Error("GetTrainTwoDuration failed(%s): %v", durationTrainTwo, err)
  76. }
  77. durationInferenceTwo, err := models.GetInferenceTwoDuration(beginTime, endTime)
  78. if err != nil {
  79. log.Error("GetInferenceTwoDuration failed(%s): %v", durationInferenceTwo, err)
  80. }
  81. durationCloudOneAll := durationDubugOne + durationBenchmarkOne + durationTrainOne
  82. durationCloudTwoAll := durationDebugTwo + durationTrainTwo + durationInferenceTwo
  83. err = models.CreateCloudbrainStatistic(&models.CloudbrainStatistic{
  84. Date: date,
  85. WhichHour: whichHour,
  86. NumDubugOne: numDubugOne,
  87. NumBenchmarkOne: numBenchmarkOne,
  88. NumTrainOne: numTrainOne,
  89. NumDubugTwo: numDebugTwo,
  90. NumTrainTwo: numTrainTwo,
  91. NumInferenceTwo: numInferenceTwo,
  92. NumCloudOneAll: numCloudOneAll,
  93. NumCloudTwoAll: numCloudTwoAll,
  94. DurationDubugOne: durationDubugOne,
  95. DurationBenchmarkOne: durationBenchmarkOne,
  96. DurationTrainOne: durationTrainOne,
  97. DurationDebugTwo: durationDebugTwo,
  98. DurationTrainTwo: durationTrainTwo,
  99. DurationInferenceTwo: durationInferenceTwo,
  100. DurationCloudOneAll: durationCloudOneAll,
  101. DurationCloudTwoAll: durationCloudTwoAll,
  102. })
  103. if err != nil {
  104. log.Error("CreateCloudbrainStatistic(%s) failed:%v", date, err.Error())
  105. return
  106. }
  107. }
  108. }