| 1 | | | import 'package:meta/meta.dart'; |
| 2 | | | |
| 3 | | | /// Base statistics for worker. |
| 4 | | | class WorkerStat { |
| 5 | | 6 | WorkerStat._( |
| 6 | | | this.workerType, |
| 7 | | | this.workerHashCode, |
| 8 | | | this.isStopped, |
| 9 | | | this.workload, |
| 10 | | | this.maxWorkload, |
| 11 | | | this.totalWorkload, |
| 12 | | | this.totalErrors, |
| 13 | | | this.upTime, |
| 14 | | | this.idleTime, |
| 15 | | | this.activeConnections, |
| 16 | | | ); |
| 17 | | | |
| 18 | | | /// Timestamp of this snapshot |
| 19 | | | final timestamp = DateTime.now().toUtc(); |
| 20 | | | |
| 21 | | | /// The worker's runtime type. |
| 22 | | | final Type workerType; |
| 23 | | | |
| 24 | | | /// The worker's hashCode. |
| 25 | | | final int workerHashCode; |
| 26 | | | |
| 27 | | | /// Worker running flag. |
| 28 | | | final bool isStopped; |
| 29 | | | |
| 30 | | | /// Current workload being processed by the worker. |
| 31 | | | final int workload; |
| 32 | | | |
| 33 | | | /// Maximum concurrent workload processed by the worker. |
| 34 | | | final int maxWorkload; |
| 35 | | | |
| 36 | | | /// Total workload processed by the worker. |
| 37 | | | final int totalWorkload; |
| 38 | | | |
| 39 | | | /// Total errors raised during processing. |
| 40 | | | final int totalErrors; |
| 41 | | | |
| 42 | | | /// The worker's up-time. |
| 43 | | | Duration upTime; |
| 44 | | | |
| 45 | | | /// The worker's idle-time. |
| 46 | | | Duration idleTime; |
| 47 | | | |
| 48 | | | /// The worker channel's count of active connections. |
| 49 | | | final int activeConnections; |
| 50 | | | } |
| 51 | | | |
| 52 | | | extension WorkerStatsExt on Iterable<WorkerStat> { |
| 53 | | | /// Gets the total workload from a collection of worker stats. |
| 54 | | 0 | int get workload => fold<int>(0, (p, s) => p + s.workload); |
| 55 | | | |
| 56 | | | /// Gets the grand total of workloads from a collection of worker stats. |
| 57 | | 0 | int get totalWorkload => fold<int>(0, (p, s) => p + s.totalWorkload); |
| 58 | | | |
| 59 | | | /// Gets the grand total of errors from a collection of worker stats. |
| 60 | | 0 | int get totalErrors => fold<int>(0, (p, s) => p + s.totalErrors); |
| 61 | | | } |
| 62 | | | |
| 63 | | | @internal |
| 64 | | | extension WorkerStatImpl on WorkerStat { |
| 65 | | 6 | static WorkerStat create( |
| 66 | | | Type workerType, |
| 67 | | | int workerHashCode, |
| 68 | | | bool isStopped, |
| 69 | | | int workload, |
| 70 | | | int maxWorkload, |
| 71 | | | int totalWorkload, |
| 72 | | | int totalErrors, |
| 73 | | | Duration upTime, |
| 74 | | | Duration idleTime, |
| 75 | | | int activeConnections) => |
| 76 | | 6 | WorkerStat._(workerType, workerHashCode, isStopped, workload, maxWorkload, |
| 77 | | | totalWorkload, totalErrors, upTime, idleTime, activeConnections); |
| 78 | | | } |