25
25
_NEAR_CACHE_DESCRIPTOR_PREFIX = "nearcache"
26
26
_NEAR_CACHE_DESCRIPTOR_DISCRIMINATOR = "name"
27
27
28
+ _TCP_METRICS_PREFIX = "tcp"
29
+
28
30
29
31
class Statistics (object ):
30
32
def __init__ (
@@ -130,7 +132,7 @@ def _register_system_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LONG
130
132
self ._registered_system_gauges [gauge_name ] = (gauge_fn , value_type )
131
133
except Exception as e :
132
134
_logger .debug (
133
- "Unable to register the system related gauge %s. Error: %s" % ( gauge_name , e )
135
+ "Unable to register the system related gauge %s. Error: %s" , gauge_name , e
134
136
)
135
137
136
138
def _register_process_gauge (self , gauge_name , gauge_fn , value_type = ValueType .LONG ):
@@ -141,7 +143,7 @@ def _register_process_gauge(self, gauge_name, gauge_fn, value_type=ValueType.LON
141
143
self ._registered_process_gauges [gauge_name ] = (gauge_fn , value_type )
142
144
except Exception as e :
143
145
_logger .debug (
144
- "Unable to register the process related gauge %s. Error: %s" % ( gauge_name , e )
146
+ "Unable to register the process related gauge %s. Error: %s" , gauge_name , e
145
147
)
146
148
147
149
def _collect_and_send_stats (self ):
@@ -157,6 +159,7 @@ def _collect_and_send_stats(self):
157
159
self ._add_client_attributes (attributes , connection )
158
160
self ._add_near_cache_metrics (attributes , compressor )
159
161
self ._add_system_and_process_metrics (attributes , compressor )
162
+ self ._add_tcp_metrics (compressor )
160
163
self ._send_stats (
161
164
collection_timestamp , "" .join (attributes ), compressor .generate_blob (), connection
162
165
)
@@ -180,7 +183,7 @@ def _add_system_and_process_metrics(self, attributes, compressor):
180
183
attributes , compressor , gauge_name , value , value_type
181
184
)
182
185
except :
183
- _logger .exception ("Error while collecting '%s'." % gauge_name )
186
+ _logger .exception ("Error while collecting '%s'." , gauge_name )
184
187
185
188
if not self ._registered_process_gauges :
186
189
# Do not create the process object if no process-related
@@ -195,7 +198,7 @@ def _add_system_and_process_metrics(self, attributes, compressor):
195
198
attributes , compressor , gauge_name , value , value_type
196
199
)
197
200
except :
198
- _logger .exception ("Error while collecting '%s'." % gauge_name )
201
+ _logger .exception ("Error while collecting '%s'." , gauge_name )
199
202
200
203
def _add_system_or_process_metric (self , attributes , compressor , gauge_name , value , value_type ):
201
204
# We don't have any metrics that do not have prefix.
@@ -342,9 +345,26 @@ def _add_near_cache_metric(
342
345
self ._add_attribute (attributes , metric , value , nc_name_with_prefix )
343
346
except :
344
347
_logger .exception (
345
- "Error while collecting %s metric for near cache '%s'" % ( metric , nc_name )
348
+ "Error while collecting %s metric for near cache '%s'." , metric , nc_name
346
349
)
347
350
351
+ def _add_tcp_metrics (self , compressor ):
352
+ self ._add_tcp_metric (compressor , "bytesSend" , self ._reactor .bytes_sent )
353
+ self ._add_tcp_metric (compressor , "bytesReceived" , self ._reactor .bytes_received )
354
+
355
+ def _add_tcp_metric (
356
+ self , compressor , metric , value , value_type = ValueType .LONG , unit = ProbeUnit .BYTES
357
+ ):
358
+ descriptor = MetricDescriptor (
359
+ metric = metric ,
360
+ prefix = _TCP_METRICS_PREFIX ,
361
+ unit = unit ,
362
+ )
363
+ try :
364
+ self ._add_metric (compressor , descriptor , value , value_type )
365
+ except :
366
+ _logger .exception ("Error while collecting '%s.%s'." , _TCP_METRICS_PREFIX , metric )
367
+
348
368
def _add_metric (self , compressor , descriptor , value , value_type ):
349
369
if value_type == ValueType .LONG :
350
370
compressor .add_long (descriptor , value )
0 commit comments