add listconf fix #351
Showing
3 changed files
with
151 additions
and
42 deletions
| ... | @@ -33,9 +33,10 @@ func init() { | ... | @@ -33,9 +33,10 @@ func init() { |
| 33 | BeeAdminApp.Route("/", AdminIndex) | 33 | BeeAdminApp.Route("/", AdminIndex) |
| 34 | BeeAdminApp.Route("/qps", QpsIndex) | 34 | BeeAdminApp.Route("/qps", QpsIndex) |
| 35 | BeeAdminApp.Route("/prof", ProfIndex) | 35 | BeeAdminApp.Route("/prof", ProfIndex) |
| 36 | BeeAdminApp.Route("/healthcheck", toolbox.Healthcheck) | 36 | BeeAdminApp.Route("/healthcheck", Healthcheck) |
| 37 | BeeAdminApp.Route("/task", toolbox.TaskStatus) | 37 | BeeAdminApp.Route("/task", TaskStatus) |
| 38 | BeeAdminApp.Route("/runtask", toolbox.RunTask) | 38 | BeeAdminApp.Route("/runtask", RunTask) |
| 39 | BeeAdminApp.Route("/listconf", ListConf) | ||
| 39 | FilterMonitorFunc = func(string, string, time.Duration) bool { return true } | 40 | FilterMonitorFunc = func(string, string, time.Duration) bool { return true } |
| 40 | } | 41 | } |
| 41 | 42 | ||
| ... | @@ -54,6 +55,121 @@ func QpsIndex(rw http.ResponseWriter, r *http.Request) { | ... | @@ -54,6 +55,121 @@ func QpsIndex(rw http.ResponseWriter, r *http.Request) { |
| 54 | toolbox.StatisticsMap.GetMap(rw) | 55 | toolbox.StatisticsMap.GetMap(rw) |
| 55 | } | 56 | } |
| 56 | 57 | ||
| 58 | func ListConf(rw http.ResponseWriter, r *http.Request) { | ||
| 59 | r.ParseForm() | ||
| 60 | command := r.Form.Get("command") | ||
| 61 | if command != "" { | ||
| 62 | switch command { | ||
| 63 | case "conf": | ||
| 64 | fmt.Fprintln(rw, "list all beego's conf:") | ||
| 65 | fmt.Fprintln(rw, "AppName:", AppName) | ||
| 66 | fmt.Fprintln(rw, "AppPath:", AppPath) | ||
| 67 | fmt.Fprintln(rw, "AppConfigPath:", AppConfigPath) | ||
| 68 | fmt.Fprintln(rw, "StaticDir:", StaticDir) | ||
| 69 | fmt.Fprintln(rw, "StaticExtensionsToGzip:", StaticExtensionsToGzip) | ||
| 70 | fmt.Fprintln(rw, "HttpAddr:", HttpAddr) | ||
| 71 | fmt.Fprintln(rw, "HttpPort:", HttpPort) | ||
| 72 | fmt.Fprintln(rw, "HttpTLS:", HttpTLS) | ||
| 73 | fmt.Fprintln(rw, "HttpCertFile:", HttpCertFile) | ||
| 74 | fmt.Fprintln(rw, "HttpKeyFile:", HttpKeyFile) | ||
| 75 | fmt.Fprintln(rw, "RecoverPanic:", RecoverPanic) | ||
| 76 | fmt.Fprintln(rw, "AutoRender:", AutoRender) | ||
| 77 | fmt.Fprintln(rw, "ViewsPath:", ViewsPath) | ||
| 78 | fmt.Fprintln(rw, "RunMode:", RunMode) | ||
| 79 | fmt.Fprintln(rw, "SessionOn:", SessionOn) | ||
| 80 | fmt.Fprintln(rw, "SessionProvider:", SessionProvider) | ||
| 81 | fmt.Fprintln(rw, "SessionName:", SessionName) | ||
| 82 | fmt.Fprintln(rw, "SessionGCMaxLifetime:", SessionGCMaxLifetime) | ||
| 83 | fmt.Fprintln(rw, "SessionSavePath:", SessionSavePath) | ||
| 84 | fmt.Fprintln(rw, "SessionHashFunc:", SessionHashFunc) | ||
| 85 | fmt.Fprintln(rw, "SessionHashKey:", SessionHashKey) | ||
| 86 | fmt.Fprintln(rw, "SessionCookieLifeTime:", SessionCookieLifeTime) | ||
| 87 | fmt.Fprintln(rw, "UseFcgi:", UseFcgi) | ||
| 88 | fmt.Fprintln(rw, "MaxMemory:", MaxMemory) | ||
| 89 | fmt.Fprintln(rw, "EnableGzip:", EnableGzip) | ||
| 90 | fmt.Fprintln(rw, "DirectoryIndex:", DirectoryIndex) | ||
| 91 | fmt.Fprintln(rw, "EnableHotUpdate:", EnableHotUpdate) | ||
| 92 | fmt.Fprintln(rw, "HttpServerTimeOut:", HttpServerTimeOut) | ||
| 93 | fmt.Fprintln(rw, "ErrorsShow:", ErrorsShow) | ||
| 94 | fmt.Fprintln(rw, "XSRFKEY:", XSRFKEY) | ||
| 95 | fmt.Fprintln(rw, "EnableXSRF:", EnableXSRF) | ||
| 96 | fmt.Fprintln(rw, "XSRFExpire:", XSRFExpire) | ||
| 97 | fmt.Fprintln(rw, "CopyRequestBody:", CopyRequestBody) | ||
| 98 | fmt.Fprintln(rw, "TemplateLeft:", TemplateLeft) | ||
| 99 | fmt.Fprintln(rw, "TemplateRight:", TemplateRight) | ||
| 100 | fmt.Fprintln(rw, "BeegoServerName:", BeegoServerName) | ||
| 101 | fmt.Fprintln(rw, "EnableAdmin:", EnableAdmin) | ||
| 102 | fmt.Fprintln(rw, "AdminHttpAddr:", AdminHttpAddr) | ||
| 103 | fmt.Fprintln(rw, "AdminHttpPort:", AdminHttpPort) | ||
| 104 | case "router": | ||
| 105 | fmt.Fprintln(rw, "Print all router infomation:") | ||
| 106 | for _, router := range BeeApp.Handlers.fixrouters { | ||
| 107 | if router.hasMethod { | ||
| 108 | fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name()) | ||
| 109 | } else { | ||
| 110 | fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name()) | ||
| 111 | } | ||
| 112 | } | ||
| 113 | for _, router := range BeeApp.Handlers.routers { | ||
| 114 | if router.hasMethod { | ||
| 115 | fmt.Fprintln(rw, router.pattern, "----", router.methods, "----", router.controllerType.Name()) | ||
| 116 | } else { | ||
| 117 | fmt.Fprintln(rw, router.pattern, "----", router.controllerType.Name()) | ||
| 118 | } | ||
| 119 | } | ||
| 120 | if BeeApp.Handlers.enableAuto { | ||
| 121 | for controllerName, methodObj := range BeeApp.Handlers.autoRouter { | ||
| 122 | fmt.Fprintln(rw, controllerName, "----") | ||
| 123 | for methodName, obj := range methodObj { | ||
| 124 | fmt.Fprintln(rw, " ", methodName, "-----", obj.Name()) | ||
| 125 | } | ||
| 126 | } | ||
| 127 | } | ||
| 128 | case "filter": | ||
| 129 | fmt.Fprintln(rw, "Print all filter infomation:") | ||
| 130 | if BeeApp.Handlers.enableFilter { | ||
| 131 | fmt.Fprintln(rw, "BeforeRouter:") | ||
| 132 | if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok { | ||
| 133 | for _, f := range bf { | ||
| 134 | fmt.Fprintln(rw, f.pattern, f.filterFunc) | ||
| 135 | } | ||
| 136 | } | ||
| 137 | fmt.Fprintln(rw, "AfterStatic:") | ||
| 138 | if bf, ok := BeeApp.Handlers.filters[AfterStatic]; ok { | ||
| 139 | for _, f := range bf { | ||
| 140 | fmt.Fprintln(rw, f.pattern, f.filterFunc) | ||
| 141 | } | ||
| 142 | } | ||
| 143 | fmt.Fprintln(rw, "BeforeExec:") | ||
| 144 | if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok { | ||
| 145 | for _, f := range bf { | ||
| 146 | fmt.Fprintln(rw, f.pattern, f.filterFunc) | ||
| 147 | } | ||
| 148 | } | ||
| 149 | fmt.Fprintln(rw, "AfterExec:") | ||
| 150 | if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok { | ||
| 151 | for _, f := range bf { | ||
| 152 | fmt.Fprintln(rw, f.pattern, f.filterFunc) | ||
| 153 | } | ||
| 154 | } | ||
| 155 | fmt.Fprintln(rw, "FinishRouter:") | ||
| 156 | if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok { | ||
| 157 | for _, f := range bf { | ||
| 158 | fmt.Fprintln(rw, f.pattern, f.filterFunc) | ||
| 159 | } | ||
| 160 | } | ||
| 161 | } | ||
| 162 | default: | ||
| 163 | rw.Write([]byte("command not support")) | ||
| 164 | } | ||
| 165 | } else { | ||
| 166 | rw.Write([]byte("ListConf support this command:\n")) | ||
| 167 | rw.Write([]byte("1. command=conf\n")) | ||
| 168 | rw.Write([]byte("2. command=router\n")) | ||
| 169 | rw.Write([]byte("3. command=filter\n")) | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 57 | func ProfIndex(rw http.ResponseWriter, r *http.Request) { | 173 | func ProfIndex(rw http.ResponseWriter, r *http.Request) { |
| 58 | r.ParseForm() | 174 | r.ParseForm() |
| 59 | command := r.Form.Get("command") | 175 | command := r.Form.Get("command") |
| ... | @@ -73,6 +189,38 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) { | ... | @@ -73,6 +189,38 @@ func ProfIndex(rw http.ResponseWriter, r *http.Request) { |
| 73 | } | 189 | } |
| 74 | } | 190 | } |
| 75 | 191 | ||
| 192 | func Healthcheck(rw http.ResponseWriter, req *http.Request) { | ||
| 193 | for name, h := range toolbox.AdminCheckList { | ||
| 194 | if err := h.Check(); err != nil { | ||
| 195 | fmt.Fprintf(rw, "%s : ok\n", name) | ||
| 196 | } else { | ||
| 197 | fmt.Fprintf(rw, "%s : %s\n", name, err.Error()) | ||
| 198 | } | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | func TaskStatus(rw http.ResponseWriter, req *http.Request) { | ||
| 203 | for tname, tk := range toolbox.AdminTaskList { | ||
| 204 | fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String()) | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | //to run a Task by http from the querystring taskname | ||
| 209 | //url like /task?taskname=sendmail | ||
| 210 | func RunTask(rw http.ResponseWriter, req *http.Request) { | ||
| 211 | req.ParseForm() | ||
| 212 | taskname := req.Form.Get("taskname") | ||
| 213 | if t, ok := toolbox.AdminTaskList[taskname]; ok { | ||
| 214 | err := t.Run() | ||
| 215 | if err != nil { | ||
| 216 | fmt.Fprintf(rw, "%v", err) | ||
| 217 | } | ||
| 218 | fmt.Fprintf(rw, "%s run success,Now the Status is %s", t.GetStatus()) | ||
| 219 | } else { | ||
| 220 | fmt.Fprintf(rw, "there's no task which named:%s", taskname) | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 76 | type AdminApp struct { | 224 | type AdminApp struct { |
| 77 | routers map[string]http.HandlerFunc | 225 | routers map[string]http.HandlerFunc |
| 78 | } | 226 | } | ... | ... |
| 1 | package toolbox | 1 | package toolbox |
| 2 | 2 | ||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "net/http" | ||
| 6 | ) | ||
| 7 | |||
| 8 | //type DatabaseCheck struct { | 3 | //type DatabaseCheck struct { |
| 9 | //} | 4 | //} |
| 10 | 5 | ||
| ... | @@ -28,16 +23,6 @@ func AddHealthCheck(name string, hc HealthChecker) { | ... | @@ -28,16 +23,6 @@ func AddHealthCheck(name string, hc HealthChecker) { |
| 28 | AdminCheckList[name] = hc | 23 | AdminCheckList[name] = hc |
| 29 | } | 24 | } |
| 30 | 25 | ||
| 31 | func Healthcheck(rw http.ResponseWriter, req *http.Request) { | ||
| 32 | for name, h := range AdminCheckList { | ||
| 33 | if err := h.Check(); err != nil { | ||
| 34 | fmt.Fprintf(rw, "%s : ok\n", name) | ||
| 35 | } else { | ||
| 36 | fmt.Fprintf(rw, "%s : %s\n", name, err.Error()) | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | func init() { | 26 | func init() { |
| 42 | AdminCheckList = make(map[string]HealthChecker) | 27 | AdminCheckList = make(map[string]HealthChecker) |
| 43 | } | 28 | } | ... | ... |
| 1 | package toolbox | 1 | package toolbox |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | ||
| 5 | "log" | 4 | "log" |
| 6 | "math" | 5 | "math" |
| 7 | "net/http" | ||
| 8 | "sort" | 6 | "sort" |
| 9 | "strconv" | 7 | "strconv" |
| 10 | "strings" | 8 | "strings" |
| ... | @@ -398,28 +396,6 @@ func AddTask(taskname string, t Tasker) { | ... | @@ -398,28 +396,6 @@ func AddTask(taskname string, t Tasker) { |
| 398 | AdminTaskList[taskname] = t | 396 | AdminTaskList[taskname] = t |
| 399 | } | 397 | } |
| 400 | 398 | ||
| 401 | func TaskStatus(rw http.ResponseWriter, req *http.Request) { | ||
| 402 | for tname, tk := range AdminTaskList { | ||
| 403 | fmt.Fprintf(rw, "%s:%s:%s", tname, tk.GetStatus(), tk.GetPrev().String()) | ||
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | //to run a Task by http from the querystring taskname | ||
| 408 | //url like /task?taskname=sendmail | ||
| 409 | func RunTask(rw http.ResponseWriter, req *http.Request) { | ||
| 410 | req.ParseForm() | ||
| 411 | taskname := req.Form.Get("taskname") | ||
| 412 | if t, ok := AdminTaskList[taskname]; ok { | ||
| 413 | err := t.Run() | ||
| 414 | if err != nil { | ||
| 415 | fmt.Fprintf(rw, "%v", err) | ||
| 416 | } | ||
| 417 | fmt.Fprintf(rw, "%s run success,Now the Status is %s", t.GetStatus()) | ||
| 418 | } else { | ||
| 419 | fmt.Fprintf(rw, "there's no task which named:%s", taskname) | ||
| 420 | } | ||
| 421 | } | ||
| 422 | |||
| 423 | //sort map for tasker | 399 | //sort map for tasker |
| 424 | type MapSorter struct { | 400 | type MapSorter struct { |
| 425 | Keys []string | 401 | Keys []string | ... | ... |
-
Please register or sign in to post a comment