Ejemplo n.º 1
0
// 命令执行监控
func (server *GoRedisServer) initCommandMonitor(path string) {
	file, err := openfile(path)
	if err != nil {
		panic(err)
	}

	st := stat.New(file)
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	st.Add(stat.IncrItem("total", 7, func() int64 { return server.cmdCateCounters.Get("total").Count() }))
	// key, string, hash, list, ...
	for _, cate := range CommandCategoryList {
		func(name string) {
			var padding int
			if padding = len(name) + 1; padding < 7 {
				padding = 7
			}
			st.Add(stat.IncrItem(name, padding, func() int64 { return server.cmdCateCounters.Get(name).Count() }))
		}(string(cate))
	}

	st.Add(stat.TextItem("connection", 11, func() interface{} { return server.counters.Get("connection").Count() }))

	go st.Start()
	server.DeferClosing(func() {
		st.Close()
	})
}
Ejemplo n.º 2
0
func (server *GoRedisServer) initSeqLog(path string) {
	file, err := openfile(path)
	if err != nil {
		panic(err)
	}
	st := stat.New(file)
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	st.Add(stat.TextItem("minseq", 16, func() interface{} {
		if server.synclog.IsEnabled() {
			return server.synclog.MinSeq()
		} else {
			return "-"
		}
	}))
	st.Add(stat.TextItem("maxseq", 16, func() interface{} {
		if server.synclog.IsEnabled() {
			return server.synclog.MaxSeq()
		} else {
			return "-"
		}
	}))
	st.Add(stat.TextItem("size", 16, func() interface{} {
		if server.synclog.IsEnabled() {
			return server.synclog.MaxSeq() - server.synclog.MinSeq()
		} else {
			return "-"
		}
	}))
	go st.Start()
	server.DeferClosing(func() {
		st.Close()
	})
}
Ejemplo n.º 3
0
func (s *SlaveClient) initlog() error {
	s.synclog = stat.New(os.Stdout)
	st := s.synclog
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	st.Add(stat.IncrItem("rdb", 8, func() int64 { return s.counters.Get("rdb").Count() }))
	st.Add(stat.IncrItem("in", 8, func() int64 { return s.counters.Get("in").Count() }))
	st.Add(stat.IncrItem("out", 8, func() int64 { return s.counters.Get("out").Count() }))
	st.Add(stat.TextItem("buffer", 10, func() interface{} { return len(s.buffer) }))
	go st.Start()
	return nil
}
Ejemplo n.º 4
0
func (s *SlaveClientV2) initLog() error {
	path := fmt.Sprintf("%s/sync_%s.log", s.server.opt.LogPath(), s.session.RemoteAddr())
	file, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, os.ModePerm)
	if err != nil {
		return err
	}
	s.synclog = stat.New(file)
	st := s.synclog
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	st.Add(stat.IncrItem("raw", 8, func() int64 { return s.counters.Get("raw").Count() }))
	st.Add(stat.IncrItem("cmd", 8, func() int64 { return s.counters.Get("cmd").Count() }))
	st.Add(stat.TextItem("seq", 16, func() interface{} { return s.lastseq }))
	go st.Start()

	return nil
}
Ejemplo n.º 5
0
func (s *SlaveClient) initLog() error {
	path := fmt.Sprintf("%s/sync.log", s.directory())
	file, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND|os.O_CREATE, os.ModePerm)
	if err != nil {
		return err
	}
	s.synclog = stat.New(file)
	st := s.synclog
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	st.Add(stat.IncrItem("rdb", 8, func() int64 { return s.counters.Get("rdb").Count() }))
	st.Add(stat.IncrItem("recv", 8, func() int64 { return s.counters.Get("recv").Count() }))
	st.Add(stat.IncrItem("proc", 8, func() int64 { return s.counters.Get("proc").Count() }))
	st.Add(stat.TextItem("buffer", 10, func() interface{} { return len(s.buffer) }))
	go st.Start()
	return nil
}
Ejemplo n.º 6
0
func (server *GoRedisServer) initExecLog(path string) {
	file, err := openfile(path)
	if err != nil {
		panic(err)
	}
	st := stat.New(file)
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	for _, name := range []string{"<1ms", "1-5ms", "6-10ms", "11-30ms", ">30ms"} {
		func(n string) {
			st.Add(stat.IncrItem(n, 8, func() int64 { return server.execCounters.Get(n).Count() }))
		}(name)
	}
	go st.Start()
	server.DeferClosing(func() {
		st.Close()
	})
}
Ejemplo n.º 7
0
func main() {
	var recv int64 = 10
	go func() {
		for {
			recv += rand.Int63n(1000)
			time.Sleep(time.Millisecond * 300)
		}
	}()

	s := stat.New(os.Stdout)
	go func() {
		time.Sleep(time.Second * 10)
		s.Close()
	}()
	s.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	s.Add(stat.IncrItem("recv", 8, func() int64 { return recv }))
	// s.Add(stat.NewItem("time", 8, "OK"))
	// s.Add(stat.NewItem("time", 8, "OK"))
	s.Start()
}
Ejemplo n.º 8
0
func (server *GoRedisServer) initLeveldbIOLog(path string) {
	// leveldb.io
	file, err := openfile(path)
	if err != nil {
		panic(err)
	}
	st := stat.New(file)
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))

	// leveldb io 操作数
	ldbkeys := []string{"get", "set", "batch", "enum", "del", "lru_hit", "lru_miss"}
	for _, k := range ldbkeys {
		// pass local var to inner func()
		func(name string) {
			st.Add(stat.IncrItem(name, 10, func() int64 { return server.levelRedis.Counter(name) }))
		}(k)
	}
	go st.Start()
	server.DeferClosing(func() {
		st.Close()
	})
}
Ejemplo n.º 9
0
func (server *GoRedisServer) initCommandCounterLog(cate string, cmds []string) {
	path := fmt.Sprintf("%s/cmd.%s.log", server.directory, cate)
	file, err := openfile(path)
	if err != nil {
		panic(err)
	}

	st := stat.New(file)
	st.Add(stat.TextItem("time", 8, func() interface{} { return stat.TimeString() }))
	for _, k := range cmds {
		func(cmd string) {
			var padding int
			if padding = len(cmd) + 1; padding < 8 {
				padding = 8
			}
			st.Add(stat.IncrItem(cmd, padding, func() int64 { return server.cmdCounters.Get(cmd).Count() }))
		}(k)
	}
	go st.Start()
	server.DeferClosing(func() {
		st.Close()
	})
}