diff --git a/.gitignore b/.gitignore index 62633b8..c6283b8 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,5 @@ log/* conf/install.lock conf/app.ini conf/ansible_hosts.ini +profile/* public/js/vue.js diff --git a/cmd/web.go b/cmd/web.go index 2895614..434f02b 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -14,6 +14,7 @@ import ( "os/exec" "syscall" "github.com/ouqiang/gocron/modules/logger" + "github.com/go-macaron/toolbox" ) // 1号进程id @@ -86,6 +87,7 @@ func registerMiddleware(m *macaron.Macaron) { })) m.Use(session.Sessioner()) m.Use(csrf.Csrfer()) + m.Use(toolbox.Toolboxer(m)) } // 解析端口 diff --git a/routers/host/host.go b/routers/host/host.go index 9a59054..388cc82 100644 --- a/routers/host/host.go +++ b/routers/host/host.go @@ -16,11 +16,13 @@ func Index(ctx *macaron.Context) { } ctx.Data["Title"] = "主机列表" ctx.Data["Hosts"] = hosts + ctx.Data["URI"] = "/host" ctx.HTML(200, "host/index") } func Create(ctx *macaron.Context) { ctx.Data["Title"] = "添加主机" + ctx.Data["URI"] = "/host/create" ctx.HTML(200, "host/create") } diff --git a/routers/routers.go b/routers/routers.go index ea9ed50..ca413bb 100644 --- a/routers/routers.go +++ b/routers/routers.go @@ -7,6 +7,8 @@ import ( "github.com/ouqiang/gocron/routers/task" "github.com/ouqiang/gocron/routers/host" "github.com/ouqiang/gocron/routers/tasklog" + "runtime" + "strconv" ) // 路由注册 @@ -36,6 +38,13 @@ func Register(m *macaron.Macaron) { }) + // 监控 + m.Group("/monitor", func() { + m.Any("/goroutine-num", func(ctx *macaron.Context) string { + return "goroutine数量-" + strconv.Itoa(runtime.NumGoroutine()) + }) + }) + // 任务 m.Group("/task", func() { m.Get("/create", task.Create) diff --git a/routers/task/task.go b/routers/task/task.go index c963255..6af8f60 100644 --- a/routers/task/task.go +++ b/routers/task/task.go @@ -50,10 +50,11 @@ type TaskForm struct { // 保存任务 func Store(ctx *macaron.Context, form TaskForm) string { + json := utils.Json{} hosts := ctx.Req.Form["hosts[]"] taskModel := models.Task{} taskModel.Name = form.Name - taskModel.Spec = form.Spec + taskModel.Spec = strings.Replace(form.Spec, "\n", "|||", 100) taskModel.Protocol = form.Protocol taskModel.Type = form.Type taskModel.Command = form.Command @@ -62,7 +63,6 @@ func Store(ctx *macaron.Context, form TaskForm) string { taskModel.Remark = form.Remark taskModel.SshHosts = strings.Join(hosts, ",") _, err := taskModel.Create() - json := utils.Json{} if err != nil { logger.Error(err) return json.Failure(utils.ResponseFailure, "保存失败") diff --git a/templates/host/index.html b/templates/host/index.html index 4abb455..1173101 100644 --- a/templates/host/index.html +++ b/templates/host/index.html @@ -1,16 +1,15 @@ {{{ template "common/header" . }}}
任务名称 | -cron表达式 | -协议 | -任务类型 | -命令 | -超时时间(秒) | -延迟时间(秒) | -主机 | -开始时间 | -结束时间 | -状态 | -执行结果 | +任务名称 | +cron表达式 | +协议 | +任务类型 | +命令 | +超时时间(秒) | +延迟时间(秒) | +主机 | +开始时间 | +结束时间 | +状态 | +执行结果 |
---|