@@ -29,13 +29,145 @@ import (
2929 "dbm-services/common/go-pubpkg/apm/metric"
3030)
3131
32- var Metrics []* metric.Metric
32+ const (
33+ MetricLabelSwitchID = "switch_id"
34+ MetricLabelActionScope = "action_scope"
35+ MetricLabelDbType = "db_type"
36+ )
37+
38+ var (
39+ Metrics []* metric.Metric
40+
41+ ScanBusinessTotal * haapm.HaCounter
42+ ScanBusinessTimeConsumingMs * haapm.HaHistogram
43+ SwitchingTimeConsumingMs * haapm.HaHistogram
44+ MysqlClusterSwitchingTimeConsumingMs * haapm.HaHistogram
45+ MysqlHostSwitchingTimeConsumingMs * haapm.HaHistogram
46+ MysqlInstanceSwitchingTimeConsumingMs * haapm.HaHistogram
47+ SwitchingSuccessTotal * haapm.HaCounter
48+ SwitchingErrorTotal * haapm.HaCounter
49+ MysqlSwitchingSuccessTotal * haapm.HaCounter
50+ MysqlSwitchingErrorTotal * haapm.HaCounter
51+ RedisSwitchingSuccessTotal * haapm.HaCounter
52+ RedisSwitchingErrorTotal * haapm.HaCounter
53+ )
54+
55+ // Default histogram buckets for latency (milliseconds)
56+ var defaultLatencyBuckets = []float64 {1 , 5 , 10 , 25 , 50 , 100 , 250 , 500 , 1000 , 2500 , 5000 , 10000 }
57+
58+ func init () {
59+ // Scan business total counter
60+ ScanBusinessTotal = haapm .NewHaCounter (
61+ "scan_business_total" ,
62+ "Total number of scan business" ,
63+ haapm .MetricLabelServiceID , haapm .MetricLabelServiceName ,
64+ )
65+
66+ // Scan business time consuming histogram
67+ ScanBusinessTimeConsumingMs = haapm .NewHaHistogramWithBuckets (
68+ "scan_business_time_consuming_ms" ,
69+ "Time consuming of scan business in milliseconds" ,
70+ defaultLatencyBuckets ,
71+ haapm .MetricLabelServiceID , haapm .MetricLabelServiceName ,
72+ )
73+
74+ // Switching time consuming histogram
75+ SwitchingTimeConsumingMs = haapm .NewHaHistogramWithBuckets (
76+ "switching_time_consuming_ms" ,
77+ "Time consuming of switching in milliseconds" ,
78+ defaultLatencyBuckets ,
79+ MetricLabelDbType ,
80+ )
81+
82+ // Mysql cluster switching time consuming histogram
83+ MysqlClusterSwitchingTimeConsumingMs = haapm .NewHaHistogramWithBuckets (
84+ "mysql_cluster_switching_time_consuming_ms" ,
85+ "Time consuming of MySQL cluster switching in milliseconds" ,
86+ defaultLatencyBuckets ,
87+ MetricLabelSwitchID , MetricLabelActionScope , MetricLabelDbType ,
88+ )
89+
90+ // Mysql host switching time consuming histogram
91+ MysqlHostSwitchingTimeConsumingMs = haapm .NewHaHistogramWithBuckets (
92+ "mysql_host_switching_time_consuming_ms" ,
93+ "Time consuming of MySQL host switching in milliseconds" ,
94+ defaultLatencyBuckets ,
95+ MetricLabelSwitchID , MetricLabelActionScope , MetricLabelDbType ,
96+ )
97+
98+ // Mysql instance switching time consuming histogram
99+ MysqlInstanceSwitchingTimeConsumingMs = haapm .NewHaHistogramWithBuckets (
100+ "mysql_instance_switching_time_consuming_ms" ,
101+ "Time consuming of MySQL instance switching in milliseconds" ,
102+ defaultLatencyBuckets ,
103+ MetricLabelSwitchID , MetricLabelActionScope , MetricLabelDbType ,
104+ )
105+
106+ // Switching success total counter
107+ SwitchingSuccessTotal = haapm .NewHaCounter ("switching_success_total" , "Total number of switching success" )
33108
109+ // Switching error total counter
110+ SwitchingErrorTotal = haapm .NewHaCounter ("switching_error_total" , "Total number of switching error" )
111+
112+ // Mysql switching success total counter
113+ MysqlSwitchingSuccessTotal = haapm .NewHaCounter (
114+ "mysql_switching_success_total" ,
115+ "Total number of MySQL switching success" ,
116+ MetricLabelActionScope , MetricLabelDbType ,
117+ )
118+
119+ // Mysql switching error total counter
120+ MysqlSwitchingErrorTotal = haapm .NewHaCounter (
121+ "mysql_switching_error_total" ,
122+ "Total number of MySQL switching error" ,
123+ MetricLabelActionScope , MetricLabelDbType ,
124+ )
125+
126+ // Redis switching success total counter
127+ RedisSwitchingSuccessTotal = haapm .NewHaCounter (
128+ "redis_switching_success_total" ,
129+ "Total number of Redis switching success" ,
130+ MetricLabelActionScope , MetricLabelDbType ,
131+ )
132+
133+ // Redis switching error total counter
134+ RedisSwitchingErrorTotal = haapm .NewHaCounter (
135+ "redis_switching_error_total" ,
136+ "Total number of Redis switching error" ,
137+ MetricLabelActionScope , MetricLabelDbType ,
138+ )
139+ }
140+
141+ // InitAPM init apm
34142func InitAPM (serviceID , serviceName string ) {
35143 haapm .AppStartupMetric .UpdateLabel (map [string ]string {
36144 haapm .MetricLabelServiceID : serviceID ,
37145 haapm .MetricLabelServiceName : serviceName ,
38146 })
39147
40148 Metrics = append (Metrics , haapm .AppStartupMetric .ToMetric ())
149+
150+ // Scan business total counter
151+ Metrics = append (Metrics , ScanBusinessTotal .ToMetric ())
152+ Metrics = append (Metrics , ScanBusinessTimeConsumingMs .ToMetric ())
153+
154+ // Switching total counter
155+ Metrics = append (Metrics , SwitchingSuccessTotal .ToMetric ())
156+ Metrics = append (Metrics , SwitchingErrorTotal .ToMetric ())
157+
158+ // Switching time consuming histogram
159+ Metrics = append (Metrics , SwitchingTimeConsumingMs .ToMetric ())
160+
161+ // Mysql switching time consuming histogram
162+ Metrics = append (Metrics , MysqlClusterSwitchingTimeConsumingMs .ToMetric ())
163+ Metrics = append (Metrics , MysqlHostSwitchingTimeConsumingMs .ToMetric ())
164+ Metrics = append (Metrics , MysqlInstanceSwitchingTimeConsumingMs .ToMetric ())
165+
166+ // Mysql switching total counter
167+ Metrics = append (Metrics , MysqlSwitchingSuccessTotal .ToMetric ())
168+ Metrics = append (Metrics , MysqlSwitchingErrorTotal .ToMetric ())
169+
170+ // Redis switching total counter
171+ Metrics = append (Metrics , RedisSwitchingSuccessTotal .ToMetric ())
172+ Metrics = append (Metrics , RedisSwitchingErrorTotal .ToMetric ())
41173}
0 commit comments