监控模块撰写
Former-commit-id: 3e97406e761be8328f84760a2e52791f36e5789e
This commit is contained in:
parent
363e40f4ff
commit
3f5950b7c6
|
@ -229,22 +229,40 @@ type (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 任务列表参数
|
||||||
type (
|
type (
|
||||||
|
taskListReq {
|
||||||
|
PageNum int `form:"pageNum"`
|
||||||
|
PageSize int `form:"pageSize"`
|
||||||
|
}
|
||||||
taskListResp {
|
taskListResp {
|
||||||
TotalCount int `json:"totalCount"`
|
TotalCount int64 `json:"totalCount"` // 任务总数
|
||||||
CardTime float32 `json:"cardTime"`
|
NormalCount int64 `json:"normalCount"` // 正常任务数
|
||||||
TotalRunTime float32 `json:"totalRunTime"`
|
AlarmCount int64 `json:"alarmCount"` // 任务告警数
|
||||||
Tasks []Task `json:"tasks"`
|
Tasks []Task `json:"tasks"`
|
||||||
}
|
}
|
||||||
Task {
|
Task {
|
||||||
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Strategy int `json:"strategy"`
|
TaskType string `json:"taskType"`
|
||||||
|
StartTime string `json:"startTime"`
|
||||||
|
EndTime string `json:"endTime"`
|
||||||
|
ParticipantStatus string `json:"participantStatus"`
|
||||||
|
ParticipantId int64 `json:"participantId"`
|
||||||
ParticipantName string `json:"participantName"`
|
ParticipantName string `json:"participantName"`
|
||||||
SynergyStatus string `json:"synergyStatus"`
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 任务列表参数
|
||||||
|
type (
|
||||||
|
taskDetailReq {
|
||||||
|
TaskId int64 `path:"taskId"`
|
||||||
|
}
|
||||||
|
taskDetailResp {
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
type (
|
type (
|
||||||
listCenterResp {
|
listCenterResp {
|
||||||
Code int32 `json:"code"`
|
Code int32 `json:"code"`
|
||||||
|
|
|
@ -36,8 +36,13 @@ service pcm {
|
||||||
@handler scheduleTaskHandler
|
@handler scheduleTaskHandler
|
||||||
post /core/scheduleTask (scheduleTaskReq)
|
post /core/scheduleTask (scheduleTaskReq)
|
||||||
|
|
||||||
|
// 任务列表接口
|
||||||
@handler TaskListHandler
|
@handler TaskListHandler
|
||||||
get /core/taskList returns (taskListResp)
|
get /core/taskList (taskListReq)returns (taskListResp)
|
||||||
|
|
||||||
|
// 任务详情接口
|
||||||
|
@handler TaskDetailHandler
|
||||||
|
get /core/taskDetail (taskDetailReq) returns (taskDetailResp)
|
||||||
|
|
||||||
@handler JobTotalHandler
|
@handler JobTotalHandler
|
||||||
get /core/jobTotal returns (jobTotalResp)
|
get /core/jobTotal returns (jobTotalResp)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ScheduleTaskByYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ScheduleTaskByYamlReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := core.NewScheduleTaskByYamlLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ScheduleTaskByYaml(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/repository/result"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TaskDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.TaskDetailReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := core.NewTaskDetailLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.TaskDetail(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +0,0 @@
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"gitlink.org.cn/jcce-pcm/utils/result"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/core"
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TaskListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
l := core.NewTaskListLogic(r.Context(), svcCtx)
|
|
||||||
resp, err := l.TaskList()
|
|
||||||
result.HttpResult(r, w, resp, err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,6 +45,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/core/taskList",
|
Path: "/core/taskList",
|
||||||
Handler: core.TaskListHandler(serverCtx),
|
Handler: core.TaskListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/core/taskDetail",
|
||||||
|
Handler: core.TaskDetailHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/core/jobTotal",
|
Path: "/core/jobTotal",
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ScheduleTaskByYamlLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewScheduleTaskByYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ScheduleTaskByYamlLogic {
|
||||||
|
return &ScheduleTaskByYamlLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ScheduleTaskByYamlLogic) ScheduleTaskByYaml(req *types.ScheduleTaskByYamlReq) (resp *types.ScheduleTaskByYamlResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
|
@ -43,7 +43,7 @@ func (l *ScheduleTaskLogic) ScheduleTask(req *types.ScheduleTaskReq) (err error)
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
YamlString: string(bytes),
|
YamlString: string(bytes),
|
||||||
CommitTime: time.Now(),
|
CommitTime: time.Now().String(),
|
||||||
}
|
}
|
||||||
// save the task in mysql and return id
|
// save the task in mysql and return id
|
||||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TaskDetailLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTaskDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskDetailLogic {
|
||||||
|
return &TaskDetailLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *TaskDetailLogic) TaskDetail(req *types.TaskDetailReq) (resp *types.TaskDetailResp, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
|
@ -1,73 +0,0 @@
|
||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
|
||||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
|
||||||
models2 "gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
|
||||||
"gitlink.org.cn/jcce-pcm/utils/enum"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
|
||||||
|
|
||||||
type TaskListLogic struct {
|
|
||||||
logx.Logger
|
|
||||||
ctx context.Context
|
|
||||||
svcCtx *svc.ServiceContext
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskListLogic {
|
|
||||||
return &TaskListLogic{
|
|
||||||
Logger: logx.WithContext(ctx),
|
|
||||||
ctx: ctx,
|
|
||||||
svcCtx: svcCtx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *TaskListLogic) TaskList() (resp *types.TaskListResp, err error) {
|
|
||||||
resp = &types.TaskListResp{}
|
|
||||||
|
|
||||||
// 查询任务数据
|
|
||||||
var tasks []models2.Task
|
|
||||||
tx := l.svcCtx.DbEngin.Find(&tasks)
|
|
||||||
if tx.Error != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
|
||||||
if len(tasks) == 0 {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
for _, task := range tasks {
|
|
||||||
var participantName string
|
|
||||||
tx := l.svcCtx.DbEngin.Raw("SELECT name from sc_participant_phy_info where id in (SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.participant_id) ,GROUP_CONCAT(DISTINCT a.participant_id) ,GROUP_CONCAT(DISTINCT c.participant_id))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?)", task.Id).Scan(&participantName)
|
|
||||||
if tx.Error != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
|
||||||
// 承接方转义
|
|
||||||
|
|
||||||
resp.Tasks = append(resp.Tasks, types.Task{
|
|
||||||
ParticipantName: participantName,
|
|
||||||
Name: task.Name,
|
|
||||||
Strategy: int(task.Strategy),
|
|
||||||
SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(),
|
|
||||||
Status: task.Status,
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
// 查询总运行时长
|
|
||||||
tx = l.svcCtx.DbEngin.Raw("select sum(running_time)/3600 as total_run_time from (select sum(running_time) as running_time from hpc union all select sum(running_time) as running_time from cloud union all select sum(running_time) as running_time from ai) runtime").Scan(&resp.TotalRunTime)
|
|
||||||
if tx.Error != nil {
|
|
||||||
logx.Error(err)
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
|
||||||
// 运行卡时数
|
|
||||||
tx = l.svcCtx.DbEngin.Model(&models2.Hpc{}).Select("(CASE WHEN SUM(running_time * card_count)/3600 IS NULL THEN 0 ELSE SUM(running_time * card_count)/3600 END )as cardTime").Find(&resp.CardTime)
|
|
||||||
if tx.Error != nil {
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
|
||||||
|
|
||||||
// 运行任务合计数
|
|
||||||
resp.TotalCount = len(tasks)
|
|
||||||
return resp, nil
|
|
||||||
}
|
|
|
@ -207,19 +207,35 @@ type TrainJob struct {
|
||||||
Strategy int `json:"strategy"`
|
Strategy int `json:"strategy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TaskListReq struct {
|
||||||
|
PageNum int `form:"pageNum"`
|
||||||
|
PageSize int `form:"pageSize"`
|
||||||
|
}
|
||||||
|
|
||||||
type TaskListResp struct {
|
type TaskListResp struct {
|
||||||
TotalCount int `json:"totalCount"`
|
TotalCount int64 `json:"totalCount"` // 任务总数
|
||||||
CardTime float32 `json:"cardTime"`
|
NormalCount int64 `json:"normalCount"` // 正常任务数
|
||||||
TotalRunTime float32 `json:"totalRunTime"`
|
AlarmCount int64 `json:"alarmCount"` // 任务告警数
|
||||||
Tasks []Task `json:"tasks"`
|
Tasks []Task `json:"tasks"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Name string `json:"name"`
|
Id int64 `json:"id"`
|
||||||
Status string `json:"status"`
|
Name string `json:"name"`
|
||||||
Strategy int `json:"strategy"`
|
Status string `json:"status"`
|
||||||
ParticipantName string `json:"participantName"`
|
TaskType string `json:"taskType"`
|
||||||
SynergyStatus string `json:"synergyStatus"`
|
StartTime string `json:"startTime"`
|
||||||
|
EndTime string `json:"endTime"`
|
||||||
|
ParticipantStatus string `json:"participantStatus"`
|
||||||
|
ParticipantId int64 `json:"participantId"`
|
||||||
|
ParticipantName string `json:"participantName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskDetailReq struct {
|
||||||
|
TaskId int64 `path:"taskId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskDetailResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCenterResp struct {
|
type ListCenterResp struct {
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
@ -41,7 +40,8 @@ type (
|
||||||
Status string `db:"status"` // 作业状态
|
Status string `db:"status"` // 作业状态
|
||||||
Strategy int64 `db:"strategy"` // 策略
|
Strategy int64 `db:"strategy"` // 策略
|
||||||
SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同)
|
||||||
CommitTime time.Time `db:"commit_time"` // 提交时间
|
CommitTime string `db:"commit_time"` // 提交时间
|
||||||
|
StartTime string `db:"start_time"` // 开始时间
|
||||||
EndTime string `db:"end_time"` // 结束运行时间
|
EndTime string `db:"end_time"` // 结束运行时间
|
||||||
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
|
RunningTime int64 `db:"running_time"` // 已运行时间(单位秒)
|
||||||
YamlString string `db:"yaml_string"`
|
YamlString string `db:"yaml_string"`
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package tracker
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright 2020 KubeSphere Authors
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
type Interface interface {
|
||||||
|
//GetMetric(expr string, time time.Time) Metric
|
||||||
|
//GetMetricOverTime(expr string, start, end time.Time, step time.Duration) Metric
|
||||||
|
//GetNamedMetrics(metrics []string, time time.Time, opt QueryOption) []Metric
|
||||||
|
//GetNamedMetricsOverTime(metrics []string, start, end time.Time, step time.Duration, opt QueryOption) []Metric
|
||||||
|
//GetMetadata(namespace string) []Metadata
|
||||||
|
//GetMetricLabelSet(expr string, start, end time.Time) []map[string]string
|
||||||
|
//
|
||||||
|
//// meter
|
||||||
|
//GetNamedMeters(meters []string, time time.Time, opts []QueryOption) []Metric
|
||||||
|
//GetNamedMetersOverTime(metrics []string, start, end time.Time, step time.Duration, opts []QueryOption) []Metric
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package tracker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/prometheus/client_golang/api"
|
||||||
|
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
type prometheus struct {
|
||||||
|
client v1.API
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPrometheus(address string) (Interface, error) {
|
||||||
|
cfg := api.Config{
|
||||||
|
Address: address,
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := api.NewClient(cfg)
|
||||||
|
return prometheus{client: v1.NewAPI(client)}, err
|
||||||
|
}
|
Loading…
Reference in New Issue