MCPcopy
hub / github.com/CodisLabs/codis / Stats

Method Stats

pkg/proxy/proxy.go:566–628  ·  view source on GitHub ↗
(flags StatsFlags)

Source from the content-addressed store, hash-verified

564}
565
566func (s *Proxy) Stats(flags StatsFlags) *Stats {
567 stats := &Stats{}
568 stats.Online = s.IsOnline()
569 stats.Closed = s.IsClosed()
570
571 servers, masters := s.GetSentinels()
572 if servers != nil {
573 stats.Sentinels.Servers = servers
574 }
575 if masters != nil {
576 stats.Sentinels.Masters = make(map[string]string)
577 for gid, addr := range masters {
578 stats.Sentinels.Masters[strconv.Itoa(gid)] = addr
579 }
580 }
581 stats.Sentinels.Switched = s.HasSwitched()
582
583 stats.Ops.Total = OpTotal()
584 stats.Ops.Fails = OpFails()
585 stats.Ops.Redis.Errors = OpRedisErrors()
586 stats.Ops.QPS = OpQPS()
587
588 if flags.HasBit(StatsCmds) {
589 stats.Ops.Cmd = GetOpStatsAll()
590 }
591
592 stats.Sessions.Total = SessionsTotal()
593 stats.Sessions.Alive = SessionsAlive()
594
595 if u := GetSysUsage(); u != nil {
596 stats.Rusage.Now = u.Now.String()
597 stats.Rusage.CPU = u.CPU
598 stats.Rusage.Mem = u.MemTotal()
599 stats.Rusage.Raw = u.Usage
600 }
601
602 stats.Backend.PrimaryOnly = s.Config().BackendPrimaryOnly
603
604 if flags.HasBit(StatsRuntime) {
605 var r runtime.MemStats
606 runtime.ReadMemStats(&r)
607
608 stats.Runtime = &RuntimeStats{}
609 stats.Runtime.General.Alloc = r.Alloc
610 stats.Runtime.General.Sys = r.Sys
611 stats.Runtime.General.Lookups = r.Lookups
612 stats.Runtime.General.Mallocs = r.Mallocs
613 stats.Runtime.General.Frees = r.Frees
614 stats.Runtime.Heap.Alloc = r.HeapAlloc
615 stats.Runtime.Heap.Sys = r.HeapSys
616 stats.Runtime.Heap.Idle = r.HeapIdle
617 stats.Runtime.Heap.Inuse = r.HeapInuse
618 stats.Runtime.Heap.Objects = r.HeapObjects
619 stats.Runtime.GC.Num = r.NumGC
620 stats.Runtime.GC.CPUFraction = r.GCCPUFraction
621 stats.Runtime.GC.TotalPauseMs = r.PauseTotalNs / uint64(time.Millisecond)
622 stats.Runtime.NumProcs = runtime.GOMAXPROCS(0)
623 stats.Runtime.NumGoroutines = runtime.NumGoroutine()

Callers 8

OverviewMethod · 0.95
startMetricsInfluxdbMethod · 0.95
startMetricsStatsdMethod · 0.95
TestStatsFunction · 0.45
newHealthyCheckerFunction · 0.45
parseProxyTokensMethod · 0.45
handleProxyCommandMethod · 0.45
handleGroupCommandMethod · 0.45

Calls 15

IsOnlineMethod · 0.95
IsClosedMethod · 0.95
GetSentinelsMethod · 0.95
HasSwitchedMethod · 0.95
ConfigMethod · 0.95
OpTotalFunction · 0.85
OpFailsFunction · 0.85
OpRedisErrorsFunction · 0.85
OpQPSFunction · 0.85
GetOpStatsAllFunction · 0.85
SessionsTotalFunction · 0.85
SessionsAliveFunction · 0.85

Tested by 1

TestStatsFunction · 0.36