Documentation for Reporter Module¶
Reporter
¶
Source code in nebula/addons/reporter.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
__init__(config, trainer, cm)
¶
Initializes the reporter module for sending periodic updates to a dashboard controller.
This initializer sets up the configuration parameters required to report metrics and statistics about the network, participant, and trainer. It connects to a specified URL endpoint where these metrics will be logged, and it initializes values used for tracking network traffic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration dictionary containing all setup parameters. |
required |
trainer
|
Trainer
|
The trainer object responsible for managing training sessions. |
required |
cm
|
CommunicationsManager
|
The communications manager handling network connections and interactions. |
required |
Attributes:
Name | Type | Description |
---|---|---|
frequency |
int
|
The frequency at which the reporter sends updates. |
grace_time |
int
|
Grace period before starting the reporting. |
data_queue |
Queue
|
An asyncio queue for managing data to be reported. |
url |
str
|
The endpoint URL for reporting updates. |
counter |
int
|
Counter for tracking the number of reports sent. |
first_net_metrics |
bool
|
Flag indicating if this is the first collection of network metrics. |
prev_bytes_sent |
int), prev_bytes_recv (int), prev_packets_sent (int), prev_packets_recv (int
|
Metrics for tracking network data sent and received. |
acc_bytes_sent |
int), acc_bytes_recv (int), acc_packets_sent (int), acc_packets_recv (int
|
Accumulators for network traffic. |
Notes
- Logs the start of the reporter module.
- Initializes both current and accumulated metrics for traffic monitoring.
Source code in nebula/addons/reporter.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
__report_data_queue()
async
¶
Processes and reports queued data entries.
This asynchronous function iterates over the data queue, retrieving each name-value pair and sending it to the trainer's logging mechanism. Once logged, each item is marked as done.
Functionality
- Retrieves and logs all entries in the data queue until it is empty.
- Assumes that
log_data
can handle asynchronous execution for optimal performance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
-
|
name (str
|
The identifier for the data entry (e.g., metric name). |
required |
-
|
value (Any
|
The value of the data entry to be logged. |
required |
Returns:
Type | Description |
---|---|
|
Notes
- Each processed item is marked as done in the queue.
Source code in nebula/addons/reporter.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
__report_resources()
async
¶
Reports system resource usage metrics.
This asynchronous function gathers and logs CPU usage data for the participant's device, and attempts to retrieve the CPU temperature (Linux systems only). Additionally, it measures CPU usage specifically for the current process.
Functionality
- Gathers total CPU usage (percentage) and attempts to retrieve CPU temperature.
- Uses
psutil
for non-blocking access to system data on Linux. - Records CPU usage of the current process for finer monitoring.
Notes
- On non-Linux platforms, CPU temperature will default to 0.
- Uses
asyncio.to_thread
to call CPU and sensor readings without blocking the event loop.
Source code in nebula/addons/reporter.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
__report_status_to_controller()
async
¶
Sends the participant's status to the controller.
This asynchronous function transmits the current participant configuration to the controller's URL endpoint. It handles both client and general exceptions to ensure robust communication with the controller, retrying in case of errors.
Functionality
- Initiates a session to post participant data to the controller.
- Logs the response status, indicating issues when status is non-200.
- Retries after a short delay in case of connection errors or unhandled exceptions.
Returns:
Type | Description |
---|---|
|
Notes
- Uses the participant index to specify the User-Agent in headers.
- Delays for 5 seconds upon general exceptions to avoid rapid retry loops.
Source code in nebula/addons/reporter.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
enqueue_data(name, value)
async
¶
Asynchronously enqueues data for reporting.
This function adds a named data value pair to the data queue, which will later be processed and sent to the designated reporting endpoint. The queue enables handling of reporting tasks independently of other processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name or identifier for the data item. |
required |
value
|
Any
|
The value of the data item to be reported. |
required |
Returns:
Type | Description |
---|---|
None |
Notes
- This function is asynchronous to allow non-blocking data enqueueing.
- Uses asyncio's queue to manage data, ensuring concurrency.
Source code in nebula/addons/reporter.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
report_scenario_finished()
async
¶
Reports the scenario completion status to the controller.
This asynchronous function notifies the scenario controller that the participant has finished its tasks. It sends a POST request to the designated controller URL, including the participant's ID in the JSON payload.
URL Construction
- The URL is dynamically built using the controller address and scenario name from the configuration settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
-
|
idx (int
|
The unique identifier for this participant, sent in the request data. |
required |
Returns:
Type | Description |
---|---|
|
Error Handling
- Logs an error if the response status is not 200, indicating that the controller might be temporarily overloaded.
- Logs exceptions if the connection attempt to the controller fails.
Source code in nebula/addons/reporter.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
run_reporter()
async
¶
Runs the continuous reporting loop.
This asynchronous function performs periodic reporting tasks such as reporting resource usage, data queue contents, and, optionally, status updates to the controller. The loop runs indefinitely, updating the counter with each cycle to track the frequency of specific tasks.
Key Actions
- Regularly reports the resource status.
- Reloads the configuration file every 50 cycles to reflect any updates.
Notes
- The reporting frequency is determined by the 'report_frequency' setting in the config file.
Source code in nebula/addons/reporter.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
start()
async
¶
Starts the reporter module after a grace period.
This asynchronous function initiates the reporting process following a designated grace period. It creates a background task to run the reporting loop, allowing data to be reported at defined intervals.
Returns:
Type | Description |
---|---|
asyncio.Task: The task for the reporter loop, which handles the data reporting asynchronously. |
Notes
- The grace period allows for a delay before the first reporting cycle.
- The reporter loop runs in the background, ensuring continuous data updates.
Source code in nebula/addons/reporter.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|