func route(ctx *web.Context, cmd, other string) { levelog.Info(cmd, other) if stat, ok := _stats[cmd]; ok { stat.Fun(ctx) return } ctx.Abort(404, "Command not support") }
func levelogStat(ctx *web.Context, log *levelog.LevelLogger) { ctx.WriteString("<pre>Now loading logs\n") ch := make(chan byte, 1) log.AddTraceLog(&StreamLog{ctx, ch}, "all") select { case <-ch: levelog.Info("Error happened") } }
func listroute(ctx *web.Context) { cmds := []*StatInfo{} for _, s := range _stats { si := StatInfo{s.Name, s.Description, s.Stream} cmds = append(cmds, &si) } bin, err := json.Marshal(cmds) if err != nil { ctx.Abort(400, err.Error()) return } ctx.Write(bin) }
func processStat(ctx *web.Context) { PidStr := strconv.Itoa(os.Getpid()) cmd := exec.Command("ps", "u", "-p", PidStr) var buf bytes.Buffer cmd.Stdout = &buf err := cmd.Run() if err != nil { levelog.Error(err) ctx.Abort(400, err.Error()) return } r := bufio.NewReader(&buf) data, _, err := r.ReadLine() if err != nil { levelog.Error(err) ctx.Abort(400, err.Error()) return } data, _, err = r.ReadLine() if err != nil { levelog.Error(err) ctx.Abort(400, err.Error()) return } levelog.Info("Data is", string(data)) ds := strings.Split(string(data), " ") nds := make([]string, 0, len(ds)) for i := 0; i < len(ds); i++ { if ds[i] != "" { nds = append(nds, ds[i]) } } bin, err := json.Marshal(processStatInfo{nds[2], nds[3], nds[4], nds[5], runtime.NumGoroutine()}) if err != nil { levelog.Error(err) ctx.Abort(400, err.Error()) return } ctx.Write(bin) }