Added data table admin ui
Showing
3 changed files
with
161 additions
and
149 deletions
| ... | @@ -137,121 +137,116 @@ func listConf(rw http.ResponseWriter, r *http.Request) { | ... | @@ -137,121 +137,116 @@ func listConf(rw http.ResponseWriter, r *http.Request) { |
| 137 | tmpl.Execute(rw, data) | 137 | tmpl.Execute(rw, data) |
| 138 | 138 | ||
| 139 | case "router": | 139 | case "router": |
| 140 | resultList := new([][]string) | 140 | content := make(map[string]interface{}) |
| 141 | 141 | ||
| 142 | var result = []string{ | 142 | var fields = []string{ |
| 143 | fmt.Sprintf("header"), | ||
| 144 | fmt.Sprintf("Router Pattern"), | 143 | fmt.Sprintf("Router Pattern"), |
| 145 | fmt.Sprintf("Methods"), | 144 | fmt.Sprintf("Methods"), |
| 146 | fmt.Sprintf("Controller"), | 145 | fmt.Sprintf("Controller"), |
| 147 | } | 146 | } |
| 148 | *resultList = append(*resultList, result) | 147 | content["Fields"] = fields |
| 149 | 148 | ||
| 149 | methods := []string{} | ||
| 150 | methodsData := make(map[string]interface{}) | ||
| 150 | for method, t := range BeeApp.Handlers.routers { | 151 | for method, t := range BeeApp.Handlers.routers { |
| 151 | var result = []string{ | 152 | |
| 152 | fmt.Sprintf("success"), | 153 | resultList := new([][]string) |
| 153 | fmt.Sprintf("Method: %s", method), | ||
| 154 | fmt.Sprintf(""), | ||
| 155 | fmt.Sprintf(""), | ||
| 156 | } | ||
| 157 | *resultList = append(*resultList, result) | ||
| 158 | 154 | ||
| 159 | printTree(resultList, t) | 155 | printTree(resultList, t) |
| 156 | |||
| 157 | methods = append(methods, method) | ||
| 158 | methodsData[method] = resultList | ||
| 160 | } | 159 | } |
| 161 | data["Content"] = resultList | 160 | |
| 161 | content["Data"] = methodsData | ||
| 162 | content["Methods"] = methods | ||
| 163 | data["Content"] = content | ||
| 162 | data["Title"] = "Routers" | 164 | data["Title"] = "Routers" |
| 165 | |||
| 163 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) | 166 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) |
| 164 | tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) | 167 | tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) |
| 165 | tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) | 168 | tmpl = template.Must(tmpl.Parse(defaultScriptsTpl)) |
| 166 | tmpl.Execute(rw, data) | 169 | tmpl.Execute(rw, data) |
| 167 | case "filter": | 170 | case "filter": |
| 168 | resultList := new([][]string) | 171 | content := make(map[string]interface{}) |
| 169 | 172 | ||
| 170 | var result = []string{ | 173 | var fields = []string{ |
| 171 | fmt.Sprintf("header"), | ||
| 172 | fmt.Sprintf("Router Pattern"), | 174 | fmt.Sprintf("Router Pattern"), |
| 173 | fmt.Sprintf("Filter Function"), | 175 | fmt.Sprintf("Filter Function"), |
| 174 | } | 176 | } |
| 175 | *resultList = append(*resultList, result) | 177 | content["Fields"] = fields |
| 178 | |||
| 179 | filterTypes := []string{} | ||
| 180 | filterTypeData := make(map[string]interface{}) | ||
| 176 | 181 | ||
| 177 | if BeeApp.Handlers.enableFilter { | 182 | if BeeApp.Handlers.enableFilter { |
| 178 | var result = []string{ | 183 | var filterType string |
| 179 | fmt.Sprintf("success"), | ||
| 180 | fmt.Sprintf("Before Router"), | ||
| 181 | fmt.Sprintf(""), | ||
| 182 | } | ||
| 183 | *resultList = append(*resultList, result) | ||
| 184 | 184 | ||
| 185 | if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok { | 185 | if bf, ok := BeeApp.Handlers.filters[BeforeRouter]; ok { |
| 186 | filterType = "Before Router" | ||
| 187 | filterTypes = append(filterTypes, filterType) | ||
| 188 | resultList := new([][]string) | ||
| 186 | for _, f := range bf { | 189 | for _, f := range bf { |
| 187 | 190 | ||
| 188 | var result = []string{ | 191 | var result = []string{ |
| 189 | fmt.Sprintf(""), | ||
| 190 | fmt.Sprintf("%s", f.pattern), | 192 | fmt.Sprintf("%s", f.pattern), |
| 191 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), | 193 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), |
| 192 | } | 194 | } |
| 193 | *resultList = append(*resultList, result) | 195 | *resultList = append(*resultList, result) |
| 194 | |||
| 195 | } | ||
| 196 | } | 196 | } |
| 197 | result = []string{ | 197 | filterTypeData[filterType] = resultList |
| 198 | fmt.Sprintf("success"), | ||
| 199 | fmt.Sprintf("Before Exec"), | ||
| 200 | fmt.Sprintf(""), | ||
| 201 | } | 198 | } |
| 202 | *resultList = append(*resultList, result) | 199 | |
| 203 | if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok { | 200 | if bf, ok := BeeApp.Handlers.filters[BeforeExec]; ok { |
| 201 | filterType = "Before Exec" | ||
| 202 | filterTypes = append(filterTypes, filterType) | ||
| 203 | resultList := new([][]string) | ||
| 204 | for _, f := range bf { | 204 | for _, f := range bf { |
| 205 | 205 | ||
| 206 | var result = []string{ | 206 | var result = []string{ |
| 207 | fmt.Sprintf(""), | ||
| 208 | fmt.Sprintf("%s", f.pattern), | 207 | fmt.Sprintf("%s", f.pattern), |
| 209 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), | 208 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), |
| 210 | } | 209 | } |
| 211 | *resultList = append(*resultList, result) | 210 | *resultList = append(*resultList, result) |
| 212 | |||
| 213 | } | 211 | } |
| 212 | filterTypeData[filterType] = resultList | ||
| 214 | } | 213 | } |
| 215 | result = []string{ | ||
| 216 | fmt.Sprintf("success"), | ||
| 217 | fmt.Sprintf("AfterExec Exec"), | ||
| 218 | fmt.Sprintf(""), | ||
| 219 | } | ||
| 220 | *resultList = append(*resultList, result) | ||
| 221 | 214 | ||
| 222 | if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok { | 215 | if bf, ok := BeeApp.Handlers.filters[AfterExec]; ok { |
| 216 | filterType = "After Exec" | ||
| 217 | filterTypes = append(filterTypes, filterType) | ||
| 218 | resultList := new([][]string) | ||
| 223 | for _, f := range bf { | 219 | for _, f := range bf { |
| 224 | 220 | ||
| 225 | var result = []string{ | 221 | var result = []string{ |
| 226 | fmt.Sprintf(""), | ||
| 227 | fmt.Sprintf("%s", f.pattern), | 222 | fmt.Sprintf("%s", f.pattern), |
| 228 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), | 223 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), |
| 229 | } | 224 | } |
| 230 | *resultList = append(*resultList, result) | 225 | *resultList = append(*resultList, result) |
| 231 | |||
| 232 | } | 226 | } |
| 227 | filterTypeData[filterType] = resultList | ||
| 233 | } | 228 | } |
| 234 | result = []string{ | ||
| 235 | fmt.Sprintf("success"), | ||
| 236 | fmt.Sprintf("Finish Router"), | ||
| 237 | fmt.Sprintf(""), | ||
| 238 | } | ||
| 239 | *resultList = append(*resultList, result) | ||
| 240 | 229 | ||
| 241 | if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok { | 230 | if bf, ok := BeeApp.Handlers.filters[FinishRouter]; ok { |
| 231 | filterType = "Finish Router" | ||
| 232 | filterTypes = append(filterTypes, filterType) | ||
| 233 | resultList := new([][]string) | ||
| 242 | for _, f := range bf { | 234 | for _, f := range bf { |
| 243 | 235 | ||
| 244 | var result = []string{ | 236 | var result = []string{ |
| 245 | fmt.Sprintf(""), | ||
| 246 | fmt.Sprintf("%s", f.pattern), | 237 | fmt.Sprintf("%s", f.pattern), |
| 247 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), | 238 | fmt.Sprintf("%s", utils.GetFuncName(f.filterFunc)), |
| 248 | } | 239 | } |
| 249 | *resultList = append(*resultList, result) | 240 | *resultList = append(*resultList, result) |
| 250 | |||
| 251 | } | 241 | } |
| 242 | filterTypeData[filterType] = resultList | ||
| 252 | } | 243 | } |
| 253 | } | 244 | } |
| 254 | data["Content"] = resultList | 245 | |
| 246 | content["Data"] = filterTypeData | ||
| 247 | content["Methods"] = filterTypes | ||
| 248 | |||
| 249 | data["Content"] = content | ||
| 255 | data["Title"] = "Filters" | 250 | data["Title"] = "Filters" |
| 256 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) | 251 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) |
| 257 | tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) | 252 | tmpl = template.Must(tmpl.Parse(routerAndFilterTpl)) |
| ... | @@ -276,7 +271,6 @@ func printTree(resultList *[][]string, t *Tree) { | ... | @@ -276,7 +271,6 @@ func printTree(resultList *[][]string, t *Tree) { |
| 276 | if v, ok := l.runObject.(*controllerInfo); ok { | 271 | if v, ok := l.runObject.(*controllerInfo); ok { |
| 277 | if v.routerType == routerTypeBeego { | 272 | if v.routerType == routerTypeBeego { |
| 278 | var result = []string{ | 273 | var result = []string{ |
| 279 | fmt.Sprintf(""), | ||
| 280 | fmt.Sprintf("%s", v.pattern), | 274 | fmt.Sprintf("%s", v.pattern), |
| 281 | fmt.Sprintf("%s", v.methods), | 275 | fmt.Sprintf("%s", v.methods), |
| 282 | fmt.Sprintf("%s", v.controllerType), | 276 | fmt.Sprintf("%s", v.controllerType), |
| ... | @@ -284,7 +278,6 @@ func printTree(resultList *[][]string, t *Tree) { | ... | @@ -284,7 +278,6 @@ func printTree(resultList *[][]string, t *Tree) { |
| 284 | *resultList = append(*resultList, result) | 278 | *resultList = append(*resultList, result) |
| 285 | } else if v.routerType == routerTypeRESTFul { | 279 | } else if v.routerType == routerTypeRESTFul { |
| 286 | var result = []string{ | 280 | var result = []string{ |
| 287 | fmt.Sprintf(""), | ||
| 288 | fmt.Sprintf("%s", v.pattern), | 281 | fmt.Sprintf("%s", v.pattern), |
| 289 | fmt.Sprintf("%s", v.methods), | 282 | fmt.Sprintf("%s", v.methods), |
| 290 | fmt.Sprintf(""), | 283 | fmt.Sprintf(""), |
| ... | @@ -292,7 +285,6 @@ func printTree(resultList *[][]string, t *Tree) { | ... | @@ -292,7 +285,6 @@ func printTree(resultList *[][]string, t *Tree) { |
| 292 | *resultList = append(*resultList, result) | 285 | *resultList = append(*resultList, result) |
| 293 | } else if v.routerType == routerTypeHandler { | 286 | } else if v.routerType == routerTypeHandler { |
| 294 | var result = []string{ | 287 | var result = []string{ |
| 295 | fmt.Sprintf(""), | ||
| 296 | fmt.Sprintf("%s", v.pattern), | 288 | fmt.Sprintf("%s", v.pattern), |
| 297 | fmt.Sprintf(""), | 289 | fmt.Sprintf(""), |
| 298 | fmt.Sprintf(""), | 290 | fmt.Sprintf(""), |
| ... | @@ -347,13 +339,15 @@ func profIndex(rw http.ResponseWriter, r *http.Request) { | ... | @@ -347,13 +339,15 @@ func profIndex(rw http.ResponseWriter, r *http.Request) { |
| 347 | func healthcheck(rw http.ResponseWriter, req *http.Request) { | 339 | func healthcheck(rw http.ResponseWriter, req *http.Request) { |
| 348 | data := make(map[interface{}]interface{}) | 340 | data := make(map[interface{}]interface{}) |
| 349 | 341 | ||
| 350 | resultList := new([][]string) | 342 | var result = []string{} |
| 351 | var result = []string{ | 343 | fields := []string{ |
| 352 | fmt.Sprintf("header"), | ||
| 353 | fmt.Sprintf("Name"), | 344 | fmt.Sprintf("Name"), |
| 345 | fmt.Sprintf("Message"), | ||
| 354 | fmt.Sprintf("Status"), | 346 | fmt.Sprintf("Status"), |
| 355 | } | 347 | } |
| 356 | *resultList = append(*resultList, result) | 348 | resultList := new([][]string) |
| 349 | |||
| 350 | content := make(map[string]interface{}) | ||
| 357 | 351 | ||
| 358 | for name, h := range toolbox.AdminCheckList { | 352 | for name, h := range toolbox.AdminCheckList { |
| 359 | if err := h.Check(); err != nil { | 353 | if err := h.Check(); err != nil { |
| ... | @@ -374,7 +368,9 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) { | ... | @@ -374,7 +368,9 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) { |
| 374 | *resultList = append(*resultList, result) | 368 | *resultList = append(*resultList, result) |
| 375 | } | 369 | } |
| 376 | 370 | ||
| 377 | data["Content"] = resultList | 371 | content["Fields"] = fields |
| 372 | content["Data"] = resultList | ||
| 373 | data["Content"] = content | ||
| 378 | data["Title"] = "Health Check" | 374 | data["Title"] = "Health Check" |
| 379 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) | 375 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) |
| 380 | tmpl = template.Must(tmpl.Parse(healthCheckTpl)) | 376 | tmpl = template.Must(tmpl.Parse(healthCheckTpl)) |
| ... | @@ -405,17 +401,17 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { | ... | @@ -405,17 +401,17 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { |
| 405 | } | 401 | } |
| 406 | 402 | ||
| 407 | // List Tasks | 403 | // List Tasks |
| 404 | content := make(map[string]interface{}) | ||
| 408 | resultList := new([][]string) | 405 | resultList := new([][]string) |
| 409 | var result = []string{ | 406 | var result = []string{} |
| 410 | fmt.Sprintf("header"), | 407 | var fields = []string{ |
| 411 | fmt.Sprintf("Task Name"), | 408 | fmt.Sprintf("Task Name"), |
| 412 | fmt.Sprintf("Task Spec"), | 409 | fmt.Sprintf("Task Spec"), |
| 413 | fmt.Sprintf("Task Function"), | 410 | fmt.Sprintf("Task Function"), |
| 411 | fmt.Sprintf(""), | ||
| 414 | } | 412 | } |
| 415 | *resultList = append(*resultList, result) | ||
| 416 | for tname, tk := range toolbox.AdminTaskList { | 413 | for tname, tk := range toolbox.AdminTaskList { |
| 417 | result = []string{ | 414 | result = []string{ |
| 418 | fmt.Sprintf(""), | ||
| 419 | fmt.Sprintf("%s", tname), | 415 | fmt.Sprintf("%s", tname), |
| 420 | fmt.Sprintf("%s", tk.GetStatus()), | 416 | fmt.Sprintf("%s", tk.GetStatus()), |
| 421 | fmt.Sprintf("%s", tk.GetPrev().String()), | 417 | fmt.Sprintf("%s", tk.GetPrev().String()), |
| ... | @@ -423,7 +419,9 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { | ... | @@ -423,7 +419,9 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) { |
| 423 | *resultList = append(*resultList, result) | 419 | *resultList = append(*resultList, result) |
| 424 | } | 420 | } |
| 425 | 421 | ||
| 426 | data["Content"] = resultList | 422 | content["Fields"] = fields |
| 423 | content["Data"] = resultList | ||
| 424 | data["Content"] = content | ||
| 427 | data["Title"] = "Tasks" | 425 | data["Title"] = "Tasks" |
| 428 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) | 426 | tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl)) |
| 429 | tmpl = template.Must(tmpl.Parse(tasksTpl)) | 427 | tmpl = template.Must(tmpl.Parse(tasksTpl)) | ... | ... |
| ... | @@ -56,31 +56,35 @@ var gcAjaxTpl = ` | ... | @@ -56,31 +56,35 @@ var gcAjaxTpl = ` |
| 56 | {{end}} | 56 | {{end}} |
| 57 | ` | 57 | ` |
| 58 | 58 | ||
| 59 | var qpsTpl = ` | 59 | var qpsTpl = `{{define "content"}} |
| 60 | {{define "content"}} | ||
| 61 | <h1>Requests statistics</h1> | 60 | <h1>Requests statistics</h1> |
| 62 | <table class="table table-striped table-hover "> | 61 | <table class="table table-striped table-hover "> |
| 63 | {{range $i, $slice := .Content}} | 62 | <thead> |
| 64 | <tr> | 63 | <tr> |
| 65 | {{range $j, $elem := $slice}} | 64 | {{range .Content.Fields}} |
| 66 | {{if eq $i 0}} | 65 | <th> |
| 67 | <th> | 66 | {{.}} |
| 68 | {{else}} | 67 | </th> |
| 69 | <td> | 68 | {{end}} |
| 70 | {{end}} | 69 | </tr> |
| 71 | {{$elem}} | 70 | </thead> |
| 72 | {{if eq $i 0}} | 71 | |
| 73 | </th> | 72 | <tbody> |
| 74 | {{else}} | 73 | {{range $i, $elem := .Content.Data}} |
| 75 | </td> | 74 | |
| 76 | {{end}} | 75 | <tr> |
| 77 | {{end}} | 76 | {{range $elem}} |
| 77 | <td> | ||
| 78 | {{.}} | ||
| 79 | </td> | ||
| 80 | {{end}} | ||
| 81 | </tr> | ||
| 82 | |||
| 83 | {{end}} | ||
| 84 | </tbody> | ||
| 78 | 85 | ||
| 79 | </tr> | ||
| 80 | {{end}} | ||
| 81 | </table> | 86 | </table> |
| 82 | {{end}} | 87 | {{end}}` |
| 83 | ` | ||
| 84 | 88 | ||
| 85 | var configTpl = ` | 89 | var configTpl = ` |
| 86 | {{define "content"}} | 90 | {{define "content"}} |
| ... | @@ -93,49 +97,51 @@ var configTpl = ` | ... | @@ -93,49 +97,51 @@ var configTpl = ` |
| 93 | {{end}} | 97 | {{end}} |
| 94 | ` | 98 | ` |
| 95 | 99 | ||
| 96 | var routerAndFilterTpl = ` | 100 | var routerAndFilterTpl = `{{define "content"}} |
| 97 | {{define "content"}} | 101 | |
| 98 | 102 | ||
| 99 | <h1>{{.Title}}</h1> | 103 | <h1>{{.Title}}</h1> |
| 100 | <table class="table table-striped table-hover "> | ||
| 101 | {{range $i, $slice := .Content}} | ||
| 102 | <tr> | ||
| 103 | 104 | ||
| 104 | {{ $header := index $slice 0}} | 105 | {{range .Content.Methods}} |
| 105 | {{if eq "header" $header }} | 106 | |
| 106 | {{range $j, $elem := $slice}} | 107 | <div class="panel panel-default"> |
| 107 | {{if ne $j 0}} | 108 | <div class="panel-heading lead success"><strong>{{.}}</strong></div> |
| 109 | <div class="panel-body"> | ||
| 110 | <table class="table table-striped table-hover "> | ||
| 111 | <thead> | ||
| 112 | <tr> | ||
| 113 | {{range $.Content.Fields}} | ||
| 108 | <th> | 114 | <th> |
| 109 | {{$elem}} | 115 | {{.}} |
| 110 | </th> | ||
| 111 | {{end}} | ||
| 112 | {{end}} | ||
| 113 | {{else if eq "success" $header}} | ||
| 114 | {{range $j, $elem := $slice}} | ||
| 115 | {{if ne $j 0}} | ||
| 116 | <th class="success"> | ||
| 117 | {{$elem}} | ||
| 118 | </th> | 116 | </th> |
| 119 | {{end}} | 117 | {{end}} |
| 120 | {{end}} | 118 | </tr> |
| 121 | {{else}} | 119 | </thead> |
| 122 | {{range $j, $elem := $slice}} | 120 | |
| 123 | {{if ne $j 0}} | 121 | <tbody> |
| 122 | {{$slice := index $.Content.Data .}} | ||
| 123 | {{range $i, $elem := $slice}} | ||
| 124 | |||
| 125 | <tr> | ||
| 126 | {{range $elem}} | ||
| 124 | <td> | 127 | <td> |
| 125 | {{$elem}} | 128 | {{.}} |
| 126 | </td> | 129 | </td> |
| 127 | {{end}} | 130 | {{end}} |
| 131 | </tr> | ||
| 132 | |||
| 128 | {{end}} | 133 | {{end}} |
| 129 | {{end}} | 134 | </tbody> |
| 130 | 135 | ||
| 131 | </tr> | ||
| 132 | {{end}} | ||
| 133 | </table> | 136 | </table> |
| 137 | </div> | ||
| 138 | </div> | ||
| 134 | {{end}} | 139 | {{end}} |
| 135 | ` | ||
| 136 | 140 | ||
| 137 | var tasksTpl = ` | 141 | |
| 138 | {{define "content"}} | 142 | {{end}}` |
| 143 | |||
| 144 | var tasksTpl = `{{define "content"}} | ||
| 139 | 145 | ||
| 140 | <h1>{{.Title}}</h1> | 146 | <h1>{{.Title}}</h1> |
| 141 | 147 | ||
| ... | @@ -156,59 +162,51 @@ bg-warning | ... | @@ -156,59 +162,51 @@ bg-warning |
| 156 | 162 | ||
| 157 | 163 | ||
| 158 | <table class="table table-striped table-hover "> | 164 | <table class="table table-striped table-hover "> |
| 159 | {{range $i, $slice := .Content}} | 165 | <thead> |
| 160 | <tr> | 166 | <tr> |
| 167 | {{range .Content.Fields}} | ||
| 168 | <th> | ||
| 169 | {{.}} | ||
| 170 | </th> | ||
| 171 | {{end}} | ||
| 172 | </tr> | ||
| 173 | </thead> | ||
| 161 | 174 | ||
| 162 | {{ $header := index $slice 0}} | 175 | <tbody> |
| 163 | {{if eq "header" $header }} | 176 | {{range $i, $slice := .Content.Data}} |
| 164 | {{range $j, $elem := $slice}} | 177 | <tr> |
| 165 | {{if ne $j 0}} | 178 | {{range $slice}} |
| 166 | <th> | ||
| 167 | {{$elem}} | ||
| 168 | </th> | ||
| 169 | {{end}} | ||
| 170 | {{end}} | ||
| 171 | <th> | ||
| 172 | Run Task | ||
| 173 | </th> | ||
| 174 | {{else}} | ||
| 175 | {{range $j, $elem := $slice}} | ||
| 176 | {{if ne $j 0}} | ||
| 177 | <td> | 179 | <td> |
| 178 | {{$elem}} | 180 | {{.}} |
| 179 | </td> | 181 | </td> |
| 180 | {{end}} | 182 | {{end}} |
| 181 | {{end}} | ||
| 182 | <td> | 183 | <td> |
| 183 | <a class="btn btn-primary btn-sm" href="/task?taskname={{index $slice 1}}">Run</a> | 184 | <a class="btn btn-primary btn-sm" href="/task?taskname={{index $slice 1}}">Run</a> |
| 184 | </td> | 185 | </td> |
| 185 | {{end}} | ||
| 186 | |||
| 187 | </tr> | 186 | </tr> |
| 188 | {{end}} | 187 | {{end}} |
| 188 | </tbody> | ||
| 189 | </table> | 189 | </table> |
| 190 | {{end}} | 190 | |
| 191 | ` | 191 | {{end}}` |
| 192 | 192 | ||
| 193 | var healthCheckTpl = ` | 193 | var healthCheckTpl = ` |
| 194 | {{define "content"}} | 194 | {{define "content"}} |
| 195 | 195 | ||
| 196 | <h1>{{.Title}}</h1> | 196 | <h1>{{.Title}}</h1> |
| 197 | <table class="table table-striped table-hover "> | 197 | <table class="table table-striped table-hover "> |
| 198 | {{range $i, $slice := .Content}} | 198 | <thead> |
| 199 | |||
| 200 | {{ $header := index $slice 0}} | ||
| 201 | {{if eq "header" $header }} | ||
| 202 | <tr> | 199 | <tr> |
| 203 | {{range $j, $elem := $slice}} | 200 | {{range .Content.Fields}} |
| 204 | {{if ne $j 0}} | ||
| 205 | <th> | 201 | <th> |
| 206 | {{$elem}} | 202 | {{.}} |
| 207 | </th> | 203 | </th> |
| 208 | {{end}} | 204 | {{end}} |
| 209 | {{end}} | ||
| 210 | </tr> | 205 | </tr> |
| 211 | {{else}} | 206 | </thead> |
| 207 | <tbody> | ||
| 208 | {{range $i, $slice := .Content.Data}} | ||
| 209 | {{ $header := index $slice 0}} | ||
| 212 | {{ if eq "success" $header}} | 210 | {{ if eq "success" $header}} |
| 213 | <tr class="success"> | 211 | <tr class="success"> |
| 214 | {{else if eq "error" $header}} | 212 | {{else if eq "error" $header}} |
| ... | @@ -223,10 +221,13 @@ var healthCheckTpl = ` | ... | @@ -223,10 +221,13 @@ var healthCheckTpl = ` |
| 223 | </td> | 221 | </td> |
| 224 | {{end}} | 222 | {{end}} |
| 225 | {{end}} | 223 | {{end}} |
| 224 | <td> | ||
| 225 | {{$header}} | ||
| 226 | </td> | ||
| 226 | </tr> | 227 | </tr> |
| 227 | {{end}} | 228 | {{end}} |
| 228 | 229 | ||
| 229 | {{end}} | 230 | </tbody> |
| 230 | </table> | 231 | </table> |
| 231 | {{end}}` | 232 | {{end}}` |
| 232 | 233 | ||
| ... | @@ -247,6 +248,7 @@ Welcome to Beego Admin Dashboard | ... | @@ -247,6 +248,7 @@ Welcome to Beego Admin Dashboard |
| 247 | </title> | 248 | </title> |
| 248 | 249 | ||
| 249 | <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> | 250 | <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> |
| 251 | <link href="//cdn.datatables.net/plug-ins/725b2a2115b/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet"> | ||
| 250 | 252 | ||
| 251 | <style type="text/css"> | 253 | <style type="text/css"> |
| 252 | ul.nav li.dropdown:hover > ul.dropdown-menu { | 254 | ul.nav li.dropdown:hover > ul.dropdown-menu { |
| ... | @@ -334,7 +336,15 @@ Healthcheck | ... | @@ -334,7 +336,15 @@ Healthcheck |
| 334 | 336 | ||
| 335 | <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | 337 | <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> |
| 336 | <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | 338 | <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> |
| 339 | <script src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script> | ||
| 340 | <script src="//cdn.datatables.net/plug-ins/725b2a2115b/integration/bootstrap/3/dataTables.bootstrap.js | ||
| 341 | "></script> | ||
| 337 | 342 | ||
| 343 | <script type="text/javascript"> | ||
| 344 | $(document).ready(function() { | ||
| 345 | $('.table').dataTable(); | ||
| 346 | }); | ||
| 347 | </script> | ||
| 338 | {{template "scripts" .}} | 348 | {{template "scripts" .}} |
| 339 | </body> | 349 | </body> |
| 340 | </html> | 350 | </html> | ... | ... |
| ... | @@ -78,13 +78,16 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri | ... | @@ -78,13 +78,16 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | // put url statistics result in io.Writer | 80 | // put url statistics result in io.Writer |
| 81 | func (m *UrlMap) GetMap() [][]string { | 81 | func (m *UrlMap) GetMap() map[string]interface{} { |
| 82 | m.lock.RLock() | 82 | m.lock.RLock() |
| 83 | defer m.lock.RUnlock() | 83 | defer m.lock.RUnlock() |
| 84 | |||
| 85 | var fields = []string{"requestUrl", "method", "times", "used", "max used", "min used", "avg used"} | ||
| 86 | |||
| 84 | resultLists := make([][]string, 0) | 87 | resultLists := make([][]string, 0) |
| 88 | content := make(map[string]interface{}) | ||
| 89 | content["Fields"] = fields | ||
| 85 | 90 | ||
| 86 | var result = []string{"requestUrl", "method", "times", "used", "max used", "min used", "avg used"} | ||
| 87 | resultLists = append(resultLists, result) | ||
| 88 | for k, v := range m.urlmap { | 91 | for k, v := range m.urlmap { |
| 89 | for kk, vv := range v { | 92 | for kk, vv := range v { |
| 90 | result := []string{ | 93 | result := []string{ |
| ... | @@ -99,7 +102,8 @@ func (m *UrlMap) GetMap() [][]string { | ... | @@ -99,7 +102,8 @@ func (m *UrlMap) GetMap() [][]string { |
| 99 | resultLists = append(resultLists, result) | 102 | resultLists = append(resultLists, result) |
| 100 | } | 103 | } |
| 101 | } | 104 | } |
| 102 | return resultLists | 105 | content["Data"] = resultLists |
| 106 | return content | ||
| 103 | } | 107 | } |
| 104 | 108 | ||
| 105 | // global statistics data map | 109 | // global statistics data map | ... | ... |
-
Please register or sign in to post a comment