Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
7945c20188
3 changed files with 58 additions and 28 deletions
  1. +16
    -5
      models/cloudbrain_static.go
  2. +1
    -0
      routers/api/v1/api.go
  3. +41
    -23
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 16
- 5
models/cloudbrain_static.go View File

@@ -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()


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

@@ -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)



+ 41
- 23
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -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 {


Loading…
Cancel
Save