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

Method startMetricsInfluxdb

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

Source from the content-addressed store, hash-verified

53}
54
55func (p *Proxy) startMetricsInfluxdb() {
56 server := p.config.MetricsReportInfluxdbServer
57 period := p.config.MetricsReportInfluxdbPeriod.Duration()
58 if server == "" {
59 return
60 }
61 period = math2.MaxDuration(time.Second, period)
62
63 c, err := influxdbClient.NewHTTPClient(influxdbClient.HTTPConfig{
64 Addr: server,
65 Username: p.config.MetricsReportInfluxdbUsername,
66 Password: p.config.MetricsReportInfluxdbPassword,
67 Timeout: time.Second * 5,
68 })
69 if err != nil {
70 log.WarnErrorf(err, "create influxdb client failed")
71 return
72 }
73
74 database := p.config.MetricsReportInfluxdbDatabase
75
76 p.startMetricsReporter(period, func() error {
77 b, err := influxdbClient.NewBatchPoints(influxdbClient.BatchPointsConfig{
78 Database: database,
79 Precision: "ns",
80 })
81 if err != nil {
82 return errors.Trace(err)
83 }
84 model := p.Model()
85 stats := p.Stats(StatsRuntime)
86
87 tags := map[string]string{
88 "token": model.Token,
89 "product_name": model.ProductName,
90 "admin_addr": model.AdminAddr,
91 "proxy_addr": model.ProxyAddr,
92 "hostname": model.Hostname,
93 }
94 fields := map[string]interface{}{
95 "ops_total": stats.Ops.Total,
96 "ops_fails": stats.Ops.Fails,
97 "ops_redis_errors": stats.Ops.Redis.Errors,
98 "ops_qps": stats.Ops.QPS,
99 "sessions_total": stats.Sessions.Total,
100 "sessions_alive": stats.Sessions.Alive,
101 "rusage_mem": stats.Rusage.Mem,
102 "rusage_cpu": stats.Rusage.CPU,
103 "runtime_gc_num": stats.Runtime.GC.Num,
104 "runtime_gc_total_pausems": stats.Runtime.GC.TotalPauseMs,
105 "runtime_num_procs": stats.Runtime.NumProcs,
106 "runtime_num_goroutines": stats.Runtime.NumGoroutines,
107 "runtime_num_cgo_call": stats.Runtime.NumCgoCall,
108 "runtime_num_mem_offheap": stats.Runtime.MemOffheap,
109 }
110 p, err := influxdbClient.NewPoint("codis_usage", tags, fields, time.Now())
111 if err != nil {
112 return errors.Trace(err)

Callers 1

NewFunction · 0.95

Calls 7

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

Tested by

no test coverage detected