@@ -30,7 +30,7 @@ type Container struct {
3030
3131 Services map [string ]service.HTTP
3232 metricsManager metrics.Manager
33- pubsub pubsub.Client
33+ PubSub pubsub.Client
3434
3535 Redis * redis.Redis
3636 SQL * sql.DB
@@ -82,18 +82,18 @@ func (c *Container) Create(conf config.Config) {
8282 partition , _ := strconv .Atoi (conf .GetOrDefault ("PARTITION_SIZE" , "0" ))
8383 offSet , _ := strconv .Atoi (conf .GetOrDefault ("PUBSUB_OFFSET" , "-1" ))
8484
85- c .pubsub = kafka .New (kafka.Config {
85+ c .PubSub = kafka .New (kafka.Config {
8686 Broker : conf .Get ("PUBSUB_BROKER" ),
8787 Partition : partition ,
8888 ConsumerGroupID : conf .Get ("CONSUMER_ID" ),
8989 OffSet : offSet ,
90- }, c .Logger )
90+ }, c .Logger , c . metricsManager )
9191 }
9292 case "GOOGLE" :
93- c .pubsub = google .New (google.Config {
93+ c .PubSub = google .New (google.Config {
9494 ProjectID : conf .Get ("GOOGLE_PROJECT_ID" ),
9595 SubscriptionName : conf .Get ("GOOGLE_SUBSCRIPTION_NAME" ),
96- }, c .Logger )
96+ }, c .Logger , c . metricsManager )
9797 }
9898}
9999
@@ -115,19 +115,26 @@ func (c *Container) registerFrameworkMetrics() {
115115 c .Metrics ().NewGauge ("app_go_numGC" , "Number of completed Garbage Collector cycles." )
116116 c .Metrics ().NewGauge ("app_go_sys" , "Number of total bytes of memory." )
117117
118- histogramBuckets := []float64 {.001 , .003 , .005 , .01 , .02 , .03 , .05 , .1 , .2 , .3 , .5 , .75 , 1 , 2 , 3 , 5 , 10 , 30 }
119-
120118 // http metrics
121- c .Metrics ().NewHistogram ("app_http_response" , "Response time of http requests in seconds." , histogramBuckets ... )
122- c .Metrics ().NewHistogram ("app_http_service_response" , "Response time of http service requests in seconds." , histogramBuckets ... )
119+ httpBuckets := []float64 {.001 , .003 , .005 , .01 , .02 , .03 , .05 , .1 , .2 , .3 , .5 , .75 , 1 , 2 , 3 , 5 , 10 , 30 }
120+ c .Metrics ().NewHistogram ("app_http_response" , "Response time of http requests in seconds." , httpBuckets ... )
121+ c .Metrics ().NewHistogram ("app_http_service_response" , "Response time of http service requests in seconds." , httpBuckets ... )
123122
124123 // redis metrics
125- c .Metrics ().NewHistogram ("app_redis_stats" , "Observes the response time for Redis commands." , histogramBuckets ... )
124+ redisBuckets := []float64 {50 , 75 , 100 , 125 , 150 , 200 , 300 , 500 , 750 , 1000 , 1250 , 1500 , 2000 , 2500 , 3000 }
125+ c .Metrics ().NewHistogram ("app_redis_stats" , "Response time of Redis commands in microseconds." , redisBuckets ... )
126126
127127 // sql metrics
128- c .Metrics ().NewHistogram ("app_sql_stats" , "Observes the response time for SQL queries." , histogramBuckets ... )
128+ sqlBuckets := []float64 {50 , 75 , 100 , 125 , 150 , 200 , 300 , 500 , 750 , 1000 , 2000 , 3000 , 4000 , 5000 , 7500 , 10000 }
129+ c .Metrics ().NewHistogram ("app_sql_stats" , "Response time of SQL queries in microseconds." , sqlBuckets ... )
129130 c .Metrics ().NewGauge ("app_sql_open_connections" , "Number of open SQL connections." )
130131 c .Metrics ().NewGauge ("app_sql_inUse_connections" , "Number of inUse SQL connections." )
132+
133+ // pubsub metrics
134+ c .Metrics ().NewCounter ("app_pubsub_publish_total_count" , "Number of total publish operations." )
135+ c .Metrics ().NewCounter ("app_pubsub_publish_success_count" , "Number of successful publish operations." )
136+ c .Metrics ().NewCounter ("app_pubsub_subscribe_total_count" , "Number of total subscribe operations." )
137+ c .Metrics ().NewCounter ("app_pubsub_subscribe_success_count" , "Number of successful subscribe operations." )
131138}
132139
133140func (c * Container ) GetAppName () string {
@@ -139,9 +146,9 @@ func (c *Container) GetAppVersion() string {
139146}
140147
141148func (c * Container ) GetPublisher () pubsub.Publisher {
142- return c .pubsub
149+ return c .PubSub
143150}
144151
145152func (c * Container ) GetSubscriber () pubsub.Subscriber {
146- return c .pubsub
153+ return c .PubSub
147154}
0 commit comments