@@ -117,62 +117,58 @@ impl DockerData {
117
117
spawn_id : SpawnId ,
118
118
spawns : Arc < Mutex < HashMap < SpawnId , JoinHandle < ( ) > > > > ,
119
119
) {
120
- if state . is_alive ( ) {
121
- let id = spawn_id . get_id ( ) ;
122
- let mut stream = docker
123
- . stats (
124
- id . get ( ) ,
125
- Some ( StatsOptions {
126
- stream : false ,
127
- one_shot : false ,
128
- } ) ,
129
- )
130
- . take ( 1 ) ;
131
-
132
- while let Some ( Ok ( stats) ) = stream . next ( ) . await {
133
- // Memory stats are only collected if the container is alive - is this the behaviour we want?
134
- let mem_stat = if state . is_alive ( ) {
135
- let mem_cache = stats . memory_stats . stats . map_or ( 0 , |i| match i {
136
- MemoryStatsStats :: V1 ( x) => x. inactive_file ,
137
- MemoryStatsStats :: V2 ( x ) => x . inactive_file ,
138
- } ) ;
120
+ let id = spawn_id . get_id ( ) ;
121
+ let mut stream = docker
122
+ . stats (
123
+ id . get ( ) ,
124
+ Some ( StatsOptions {
125
+ stream : false ,
126
+ one_shot : false ,
127
+ } ) ,
128
+ )
129
+ . take ( 1 ) ;
130
+
131
+ while let Some ( Ok ( stats ) ) = stream . next ( ) . await {
132
+ // Memory stats are only collected if the container is alive - is this the behaviour we want?
133
+ let ( mem_stat , cpu_stats ) = if state . is_alive ( ) {
134
+ let mem_cache = stats . memory_stats . stats . map_or ( 0 , |i| match i {
135
+ MemoryStatsStats :: V1 ( x ) => x . inactive_file ,
136
+ MemoryStatsStats :: V2 ( x) => x. inactive_file ,
137
+ } ) ;
138
+ (
139
139
Some (
140
140
stats
141
141
. memory_stats
142
142
. usage
143
143
. unwrap_or_default ( )
144
144
. saturating_sub ( mem_cache) ,
145
- )
146
- } else {
147
- None
148
- } ;
145
+ ) ,
146
+ Some ( Self :: calculate_usage ( & stats) ) ,
147
+ )
148
+ } else {
149
+ ( None , None )
150
+ } ;
151
+
152
+ let mem_limit = stats. memory_stats . limit . unwrap_or_default ( ) ;
149
153
150
- let mem_limit = stats. memory_stats . limit . unwrap_or_default ( ) ;
154
+ let op_key = stats
155
+ . networks
156
+ . as_ref ( )
157
+ . and_then ( |networks| networks. keys ( ) . next ( ) . cloned ( ) ) ;
151
158
152
- let op_key = stats
159
+ let ( rx, tx) = if let Some ( key) = op_key {
160
+ stats
153
161
. networks
154
- . as_ref ( )
155
- . and_then ( |networks| networks. keys ( ) . next ( ) . cloned ( ) ) ;
156
-
157
- let cpu_stats = if state. is_alive ( ) {
158
- Some ( Self :: calculate_usage ( & stats) )
159
- } else {
160
- None
161
- } ;
162
- let ( rx, tx) = if let Some ( key) = op_key {
163
- stats
164
- . networks
165
- . unwrap_or_default ( )
166
- . get ( & key)
167
- . map_or ( ( 0 , 0 ) , |f| ( f. rx_bytes , f. tx_bytes ) )
168
- } else {
169
- ( 0 , 0 )
170
- } ;
171
-
172
- app_data
173
- . lock ( )
174
- . update_stats_by_id ( id, cpu_stats, mem_stat, mem_limit, rx, tx) ;
175
- }
162
+ . unwrap_or_default ( )
163
+ . get ( & key)
164
+ . map_or ( ( 0 , 0 ) , |f| ( f. rx_bytes , f. tx_bytes ) )
165
+ } else {
166
+ ( 0 , 0 )
167
+ } ;
168
+
169
+ app_data
170
+ . lock ( )
171
+ . update_stats_by_id ( id, cpu_stats, mem_stat, mem_limit, rx, tx) ;
176
172
}
177
173
spawns. lock ( ) . remove ( & spawn_id) ;
178
174
}
0 commit comments