Exemplo n.º 1
0
Arquivo: stat.go Projeto: vuleetu/misc
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")
}
Exemplo n.º 2
0
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")
	}
}
Exemplo n.º 3
0
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)
}