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

Method startMetricsStatsd

pkg/proxy/metrics.go:121–174  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

119}
120
121func (p *Proxy) startMetricsStatsd() {
122 server := p.config.MetricsReportStatsdServer
123 period := p.config.MetricsReportStatsdPeriod.Duration()
124 if server == "" {
125 return
126 }
127 period = math2.MaxDuration(time.Second, period)
128
129 c, err := statsdClient.New(statsdClient.Address(server))
130 if err != nil {
131 log.WarnErrorf(err, "create statsd client failed")
132 return
133 }
134
135 var (
136 prefix = p.config.MetricsReportStatsdPrefix
137 replacer = strings.NewReplacer(".", "_", ":", "_")
138 )
139
140 p.startMetricsReporter(period, func() error {
141 model := p.Model()
142 stats := p.Stats(StatsRuntime)
143
144 segs := []string{
145 prefix, model.ProductName,
146 replacer.Replace(model.AdminAddr),
147 replacer.Replace(model.ProxyAddr),
148 }
149
150 fields := map[string]interface{}{
151 "ops_total": stats.Ops.Total,
152 "ops_fails": stats.Ops.Fails,
153 "ops_redis_errors": stats.Ops.Redis.Errors,
154 "ops_qps": stats.Ops.QPS,
155 "sessions_total": stats.Sessions.Total,
156 "sessions_alive": stats.Sessions.Alive,
157 "rusage_mem": stats.Rusage.Mem,
158 "rusage_cpu": stats.Rusage.CPU,
159 "runtime_gc_num": stats.Runtime.GC.Num,
160 "runtime_gc_total_pausems": stats.Runtime.GC.TotalPauseMs,
161 "runtime_num_procs": stats.Runtime.NumProcs,
162 "runtime_num_goroutines": stats.Runtime.NumGoroutines,
163 "runtime_num_cgo_call": stats.Runtime.NumCgoCall,
164 "runtime_num_mem_offheap": stats.Runtime.MemOffheap,
165 }
166 for key, value := range fields {
167 c.Gauge(strings.Join(append(segs, key), "."), value)
168 }
169 return nil
170 }, func() error {
171 c.Close()
172 return nil
173 })
174}

Callers 1

NewFunction · 0.95

Calls 6

startMetricsReporterMethod · 0.95
ModelMethod · 0.95
StatsMethod · 0.95
DurationMethod · 0.80
WarnErrorfMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected