@@ -8,15 +8,16 @@ use relay_redis::AsyncRedisClient;
8
8
#[ cfg( feature = "processing" ) ]
9
9
use relay_redis:: { RedisPool , RedisPools , Stats } ;
10
10
use relay_statsd:: metric;
11
- use relay_system:: { Addr , RuntimeMetrics , Service } ;
11
+ use relay_system:: { Addr , Handle , RuntimeMetrics , Service } ;
12
12
use tokio:: time:: interval;
13
13
14
14
/// Relay Stats Service.
15
15
///
16
16
/// Service which collects stats periodically and emits them via statsd.
17
17
pub struct RelayStats {
18
18
config : Arc < Config > ,
19
- runtime : RuntimeMetrics ,
19
+ runtime : Handle ,
20
+ rt_metrics : RuntimeMetrics ,
20
21
upstream_relay : Addr < UpstreamRelay > ,
21
22
#[ cfg( feature = "processing" ) ]
22
23
redis_pools : Option < RedisPools > ,
@@ -25,88 +26,106 @@ pub struct RelayStats {
25
26
impl RelayStats {
26
27
pub fn new (
27
28
config : Arc < Config > ,
28
- runtime : RuntimeMetrics ,
29
+ runtime : Handle ,
29
30
upstream_relay : Addr < UpstreamRelay > ,
30
31
#[ cfg( feature = "processing" ) ] redis_pools : Option < RedisPools > ,
31
32
) -> Self {
32
33
Self {
33
34
config,
34
35
upstream_relay,
36
+ rt_metrics : runtime. metrics ( ) ,
35
37
runtime,
36
38
#[ cfg( feature = "processing" ) ]
37
39
redis_pools,
38
40
}
39
41
}
40
42
43
+ async fn service_metrics ( & self ) {
44
+ for ( service, metrics) in self . runtime . current_services_metrics ( ) . iter ( ) {
45
+ metric ! (
46
+ gauge( RelayGauges :: ServiceUtilization ) = metrics. utilization as u64 ,
47
+ service = service. name( ) ,
48
+ instance_id = & service. instance_id( ) . to_string( ) ,
49
+ ) ;
50
+ }
51
+ }
52
+
41
53
async fn tokio_metrics ( & self ) {
42
- metric ! ( gauge( RuntimeGauges :: NumIdleThreads ) = self . runtime . num_idle_threads( ) as u64 ) ;
43
- metric ! ( gauge( RuntimeGauges :: NumAliveTasks ) = self . runtime . num_alive_tasks( ) as u64 ) ;
54
+ metric ! ( gauge( RuntimeGauges :: NumIdleThreads ) = self . rt_metrics . num_idle_threads( ) as u64 ) ;
55
+ metric ! ( gauge( RuntimeGauges :: NumAliveTasks ) = self . rt_metrics . num_alive_tasks( ) as u64 ) ;
44
56
metric ! (
45
- gauge( RuntimeGauges :: BlockingQueueDepth ) = self . runtime. blocking_queue_depth( ) as u64
57
+ gauge( RuntimeGauges :: BlockingQueueDepth ) =
58
+ self . rt_metrics. blocking_queue_depth( ) as u64
46
59
) ;
47
60
metric ! (
48
- gauge( RuntimeGauges :: NumBlockingThreads ) = self . runtime. num_blocking_threads( ) as u64
61
+ gauge( RuntimeGauges :: NumBlockingThreads ) =
62
+ self . rt_metrics. num_blocking_threads( ) as u64
49
63
) ;
50
64
metric ! (
51
65
gauge( RuntimeGauges :: NumIdleBlockingThreads ) =
52
- self . runtime . num_idle_blocking_threads( ) as u64
66
+ self . rt_metrics . num_idle_blocking_threads( ) as u64
53
67
) ;
54
68
55
69
metric ! (
56
70
counter( RuntimeCounters :: BudgetForcedYieldCount ) +=
57
- self . runtime . budget_forced_yield_count( )
71
+ self . rt_metrics . budget_forced_yield_count( )
58
72
) ;
59
73
60
- metric ! ( gauge( RuntimeGauges :: NumWorkers ) = self . runtime . num_workers( ) as u64 ) ;
61
- for worker in 0 ..self . runtime . num_workers ( ) {
74
+ metric ! ( gauge( RuntimeGauges :: NumWorkers ) = self . rt_metrics . num_workers( ) as u64 ) ;
75
+ for worker in 0 ..self . rt_metrics . num_workers ( ) {
62
76
let worker_name = worker. to_string ( ) ;
63
77
64
78
metric ! (
65
79
gauge( RuntimeGauges :: WorkerLocalQueueDepth ) =
66
- self . runtime . worker_local_queue_depth( worker) as u64 ,
80
+ self . rt_metrics . worker_local_queue_depth( worker) as u64 ,
67
81
worker = & worker_name,
68
82
) ;
69
83
metric ! (
70
84
gauge( RuntimeGauges :: WorkerMeanPollTime ) =
71
- self . runtime . worker_mean_poll_time( worker) . as_secs_f64( ) ,
85
+ self . rt_metrics . worker_mean_poll_time( worker) . as_secs_f64( ) ,
72
86
worker = & worker_name,
73
87
) ;
74
88
75
89
metric ! (
76
90
counter( RuntimeCounters :: WorkerLocalScheduleCount ) +=
77
- self . runtime . worker_local_schedule_count( worker) ,
91
+ self . rt_metrics . worker_local_schedule_count( worker) ,
78
92
worker = & worker_name,
79
93
) ;
80
94
metric ! (
81
- counter( RuntimeCounters :: WorkerNoopCount ) += self . runtime. worker_noop_count( worker) ,
95
+ counter( RuntimeCounters :: WorkerNoopCount ) +=
96
+ self . rt_metrics. worker_noop_count( worker) ,
82
97
worker = & worker_name,
83
98
) ;
84
99
metric ! (
85
100
counter( RuntimeCounters :: WorkerOverflowCount ) +=
86
- self . runtime . worker_overflow_count( worker) ,
101
+ self . rt_metrics . worker_overflow_count( worker) ,
87
102
worker = & worker_name,
88
103
) ;
89
104
metric ! (
90
- counter( RuntimeCounters :: WorkerParkCount ) += self . runtime. worker_park_count( worker) ,
105
+ counter( RuntimeCounters :: WorkerParkCount ) +=
106
+ self . rt_metrics. worker_park_count( worker) ,
91
107
worker = & worker_name,
92
108
) ;
93
109
metric ! (
94
- counter( RuntimeCounters :: WorkerPollCount ) += self . runtime. worker_poll_count( worker) ,
110
+ counter( RuntimeCounters :: WorkerPollCount ) +=
111
+ self . rt_metrics. worker_poll_count( worker) ,
95
112
worker = & worker_name,
96
113
) ;
97
114
metric ! (
98
115
counter( RuntimeCounters :: WorkerStealCount ) +=
99
- self . runtime . worker_steal_count( worker) ,
116
+ self . rt_metrics . worker_steal_count( worker) ,
100
117
worker = & worker_name,
101
118
) ;
102
119
metric ! (
103
120
counter( RuntimeCounters :: WorkerStealOperations ) +=
104
- self . runtime . worker_steal_operations( worker) ,
121
+ self . rt_metrics . worker_steal_operations( worker) ,
105
122
worker = & worker_name,
106
123
) ;
107
124
metric ! (
108
125
counter( RuntimeCounters :: WorkerTotalBusyDuration ) +=
109
- self . runtime. worker_total_busy_duration( worker) . as_millis( ) as u64 ,
126
+ self . rt_metrics
127
+ . worker_total_busy_duration( worker)
128
+ . as_millis( ) as u64 ,
110
129
worker = & worker_name,
111
130
) ;
112
131
}
@@ -171,6 +190,7 @@ impl Service for RelayStats {
171
190
loop {
172
191
let _ = tokio:: join!(
173
192
self . upstream_status( ) ,
193
+ self . service_metrics( ) ,
174
194
self . tokio_metrics( ) ,
175
195
self . redis_pools( ) ,
176
196
) ;
0 commit comments