From 7945c2018899d60c19adf2fdd31847054d7c2903 Mon Sep 17 00:00:00 2001 From: liuzx Date: Tue, 10 May 2022 17:10:41 +0800 Subject: [PATCH] update --- models/cloudbrain_static.go | 21 +++++-- routers/api/v1/api.go | 1 + routers/api/v1/repo/cloudbrain_dashboard.go | 64 +++++++++++++-------- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/models/cloudbrain_static.go b/models/cloudbrain_static.go index 1876ac121..f4045dd69 100644 --- a/models/cloudbrain_static.go +++ b/models/cloudbrain_static.go @@ -36,7 +36,7 @@ type CloudbrainStatistic struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated" json:"-"` } -func GetJobWaitingCount(beginTime time.Time, endTime time.Time) (int64, error) { +func GetJobWaitingPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + @@ -44,7 +44,7 @@ func GetJobWaitingCount(beginTime time.Time, endTime time.Time) (int64, error) { return x.SQL(countSql).Count() } -func GetJobRunningCount(beginTime time.Time, endTime time.Time) (int64, error) { +func GetJobRunningPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + @@ -52,7 +52,7 @@ func GetJobRunningCount(beginTime time.Time, endTime time.Time) (int64, error) { return x.SQL(countSql).Count() } -func GetJobStoppedCount(beginTime time.Time, endTime time.Time) (int64, error) { +func GetJobStoppedPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + @@ -60,7 +60,7 @@ func GetJobStoppedCount(beginTime time.Time, endTime time.Time) (int64, error) { return x.SQL(countSql).Count() } -func GetJobSucceededCount(beginTime time.Time, endTime time.Time) (int64, error) { +func GetJobSucceededPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + @@ -68,7 +68,7 @@ func GetJobSucceededCount(beginTime time.Time, endTime time.Time) (int64, error) return x.SQL(countSql).Count() } -func GetJobFailedCount(beginTime time.Time, endTime time.Time) (int64, error) { +func GetJobFailedPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { countSql := "SELECT count(*) FROM " + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + @@ -242,6 +242,17 @@ func GetCloudBrainTwoDuration() (int64, error) { return total, nil } +func GetCreatorPeriodCount(beginTime time.Time, endTime time.Time) (int64, error) { + countSql := "SELECT count(distinct user_id) FROM " + + "public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + + " and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + return x.SQL(countSql).Count() +} +func GetCreatorCount() (int64, error) { + countSql := "SELECT count(distinct user_id) FROM public.cloudbrain" + return x.SQL(countSql).Count() +} + func DeleteCloudbrainStatisticDaily(date string) error { sess := xStatistic.NewSession() defer sess.Close() diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index d760fe190..026dae936 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -565,6 +565,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/overview", repo.GetAllCloudbrainsOverview) m.Get("/distribution", repo.GetAllCloudbrainsPeriodDistribution) m.Get("/trend", repo.GetAllCloudbrainsTrend) + m.Get("/status_analysis", repo.GetCloudbrainsStatusAnalysis) }) }, operationReq) diff --git a/routers/api/v1/repo/cloudbrain_dashboard.go b/routers/api/v1/repo/cloudbrain_dashboard.go index dec1c491c..44d7f7c95 100644 --- a/routers/api/v1/repo/cloudbrain_dashboard.go +++ b/routers/api/v1/repo/cloudbrain_dashboard.go @@ -28,15 +28,17 @@ type CloudbrainsPeriodData struct { CloudBrainTwoPeriodCount int64 `json:"cloudBrainTwoPeriodCount"` } type CloudbrainsOverviewData struct { - JobWaitingCount int64 `json:"jobWaitingCount"` - JobRunningCount int64 `json:"jobRunningCount"` - JobStoppedCount int64 `json:"jobStoppedCount"` - JobSucceededCount int64 `json:"jobSucceededCount"` - JobFailedCount int64 `json:"jobFailedCount"` - CloudBrainOneCount int64 `json:"cloudBrainOneCount"` - CloudBrainTwoCount int64 `json:"cloudBrainTwoCount"` - CloudBrainOneDuration int64 `json:"cloudBrainOneDuration"` - CloudBrainTwoDuration int64 `json:"cloudBrainTwoDuration"` + JobWaitingPeriodCount int64 `json:"jobWaitingPeriodCount"` + JobRunningPeriodCount int64 `json:"jobRunningPeriodCount"` + JobStoppedPeriodCount int64 `json:"jobStoppedPeriodCount"` + JobSucceededPeriodCount int64 `json:"jobSucceededPeriodCount"` + JobFailedPeriodCount int64 `json:"jobFailedPeriodCount"` + CloudBrainOneCount int64 `json:"cloudBrainOneCount"` + CloudBrainTwoCount int64 `json:"cloudBrainTwoCount"` + CloudBrainOneDuration int64 `json:"cloudBrainOneDuration"` + CloudBrainTwoDuration int64 `json:"cloudBrainTwoDuration"` + CreatorPeriodCount int64 `json:"creatorPeriodCount"` + CreatorCount int64 `json:"creatorCount"` } type TimeCloudbrainsNum struct { TimeCloudbrainNum []DateCloudbrainNum `json:"dateCloudbrainNum"` @@ -62,27 +64,27 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { log.Info("beginTime:", beginTime) endTime := now log.Info("endTime:", endTime) - jobWaitingCount, err := models.GetJobWaitingCount(beginTime, endTime) + jobWaitingPeriodCount, err := models.GetJobWaitingPeriodCount(beginTime, endTime) if err != nil { log.Error("Can not query jobWaitingCount.", err) return } - jobRunningCount, err := models.GetJobRunningCount(beginTime, endTime) + jobRunningPeriodCount, err := models.GetJobRunningPeriodCount(beginTime, endTime) if err != nil { log.Error("Can not query jobRunningCount.", err) return } - jobStoppedCount, err := models.GetJobStoppedCount(beginTime, endTime) + jobStoppedPeriodCount, err := models.GetJobStoppedPeriodCount(beginTime, endTime) if err != nil { log.Error("Can not query jobStoppedCount.", err) return } - jobSucceededCount, err := models.GetJobSucceededCount(beginTime, endTime) + jobSucceededPeriodCount, err := models.GetJobSucceededPeriodCount(beginTime, endTime) if err != nil { log.Error("Can not query jobSucceededCount.", err) return } - jobFailedCount, err := models.GetJobFailedCount(beginTime, endTime) + jobFailedPeriodCount, err := models.GetJobFailedPeriodCount(beginTime, endTime) if err != nil { log.Error("Can not query jobFailedCount.", err) return @@ -107,17 +109,29 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { log.Error("Can not query cloudBrainTwoDuration.", err) return } + creatorPeriodCount, err := models.GetCreatorPeriodCount(beginTime, endTime) + if err != nil { + log.Error("Can not query creatorPeriodCount.", err) + return + } + creatorCount, err := models.GetCreatorCount() + if err != nil { + log.Error("Can not query creatorCount.", err) + return + } CloudbrainsOverviewData := CloudbrainsOverviewData{ - JobWaitingCount: jobWaitingCount, - JobRunningCount: jobRunningCount, - JobStoppedCount: jobStoppedCount, - JobSucceededCount: jobSucceededCount, - JobFailedCount: jobFailedCount, - CloudBrainOneCount: cloudBrainOneCount, - CloudBrainTwoCount: cloudBrainTwoCount, - CloudBrainOneDuration: cloudBrainOneDuration, - CloudBrainTwoDuration: cloudBrainTwoDuration, + JobWaitingPeriodCount: jobWaitingPeriodCount, + JobRunningPeriodCount: jobRunningPeriodCount, + JobStoppedPeriodCount: jobStoppedPeriodCount, + JobSucceededPeriodCount: jobSucceededPeriodCount, + JobFailedPeriodCount: jobFailedPeriodCount, + CloudBrainOneCount: cloudBrainOneCount, + CloudBrainTwoCount: cloudBrainTwoCount, + CloudBrainOneDuration: cloudBrainOneDuration, + CloudBrainTwoDuration: cloudBrainTwoDuration, + CreatorPeriodCount: creatorPeriodCount, + CreatorCount: creatorCount, } ctx.JSON(http.StatusOK, CloudbrainsOverviewData) @@ -355,6 +369,10 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { ctx.JSON(http.StatusOK, cloudbrainsPeriodData) } +func GetCloudbrainsStatusAnalysis(ctx *context.Context) { + +} + 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 {