Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
20c5dde750
3 changed files with 42 additions and 0 deletions
  1. +9
    -0
      models/cloudbrain_static.go
  2. +1
    -0
      routers/api/v1/api.go
  3. +32
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 9
- 0
models/cloudbrain_static.go View File

@@ -314,3 +314,12 @@ func GetJobRunningCount() (int64, error) {
countSql := "SELECT count(*) FROM " + "public.cloudbrain where status ='" + string(JobRunning) + "'"
return x.SQL(countSql).Count()
}

func GetHourPeriodCount(dateBeginTime string, dateEndTime string, hourBeginTime string, hourEndTime string) (int64, error) {
countSql := "SELECT count(*) FROM " +
"public.cloudbrain where to_char(to_timestamp(created_unix), 'YYYY-MM-DD') >=" + dateBeginTime +
" and to_char(to_timestamp(created_unix), 'YYYY-MM-DD') <" + dateEndTime +
" and to_char(to_timestamp(created_unix), ' HH24:MI:SS') >=" + hourBeginTime +
" and to_char(to_timestamp(created_unix), 'HH24:MI:SS') <=" + hourEndTime
return x.SQL(countSql).Count()
}

+ 1
- 0
routers/api/v1/api.go View File

@@ -566,6 +566,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/trend", repo.GetAllCloudbrainsTrend)
m.Get("/status_analysis", repo.GetCloudbrainsStatusAnalysis)
m.Get("/detail_data", repo.GetCloudbrainsDetailData)
m.Get("/hours_data", repo.GetCloudbrainsHoursData)
})
}, operationReq)



+ 32
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -302,6 +302,7 @@ func GetAllCloudbrainsTrend(ctx *context.Context) {
}

func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) {

recordBeginTime, err := getBrainRecordBeginTime()
if err != nil {
log.Error("Can not get record begin time", err)
@@ -489,6 +490,37 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
})
}

func GetCloudbrainsHoursData(ctx *context.Context) {
var debugOnePeriodCount int64
brainRecordBeginTime, err := getBrainRecordBeginTime()
if err != nil {
log.Error("Can not get brain record begin time", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.brain_record_begintime_get_err"))
return
}
queryType := ctx.QueryTrim("type")
now := time.Now()
if queryType != "" {
if queryType == "all" {
beginTime := brainRecordBeginTime
endTime := now
timeLayoutStr := "2006-01-02"
dateBeginTime := beginTime.Format(timeLayoutStr)
dateEndTime := endTime.Format(timeLayoutStr)
debugOnePeriodCount, err := models.GetHourPeriodCount(dateBeginTime, dateEndTime)
if err != nil {
log.Error("Can not query debugOneCount.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("debugOneCount_get_error"))
return
}
}
}
ctx.JSON(http.StatusOK, map[string]interface{}{
"debugOnePeriodCount": debugOnePeriodCount,
})

}

func getCloudbrainCount(beginTime time.Time, endTime time.Time) (int64, int64, int64, int64, int64, int64, int64, int64, int64, error) {
debugOneCount, err := models.GetDebugOnePeriodCount(beginTime, endTime)
if err != nil {


Loading…
Cancel
Save