API: Window¶
이 페이지는 사용 가능한 Window를 문서화합니다. Window는 최근 호출에 대한 Metric을 저장하고 제공하는 역할을 합니다.
Window 선택에 대한 개요는 Windows 컴포넌트 가이드를 참조하십시오.
fluxgate.windows.CountWindow
¶
CountWindow(size: int)
Bases: IWindow
Count-based sliding window for tracking recent call metrics.
Maintains a fixed-size sliding window that keeps the most recent N calls. When the window is full, the oldest record is evicted when a new one arrives.
Examples:
>>> window = CountWindow(size=100) # Track last 100 calls
>>>
>>> window.record(Record(success=True, duration=0.5))
>>>
>>> metric = window.get_metric()
>>> print(metric.total_count)
1
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Maximum number of calls to track in the window |
required |
Source code in fluxgate/windows.py
31 32 33 34 35 36 37 | |
record
¶
record(record: Record) -> None
Add a call record to the window.
If window is full, evicts the oldest record before adding the new one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Record
|
Call result to record |
required |
Source code in fluxgate/windows.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
get_metric
¶
get_metric() -> Metric
Get aggregated metrics for all records in the window.
Returns:
| Type | Description |
|---|---|
Metric
|
Aggregated metrics (counts, durations) |
Source code in fluxgate/windows.py
65 66 67 68 69 70 71 72 73 74 75 76 | |
reset
¶
reset() -> None
Clear all records and reset metrics to zero.
Source code in fluxgate/windows.py
78 79 80 81 82 83 84 | |
fluxgate.windows.TimeWindow
¶
TimeWindow(size: int)
Bases: IWindow
Time-based sliding window for tracking metrics over a time period.
Divides time into fixed buckets (1 second each) and tracks metrics per bucket. When a bucket's time period expires, it is reset and reused for the new time.
Examples:
>>> window = TimeWindow(size=60) # Track last 60 seconds
>>>
>>> window.record(Record(success=True, duration=0.5))
>>>
>>> metric = window.get_metric()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Number of seconds to track (window size in seconds) |
required |
Note
Time precision is 1 second. All calls within the same second are grouped into the same bucket.
Source code in fluxgate/windows.py
127 128 129 130 131 132 133 134 | |
Bucket
dataclass
¶
Bucket(
sec_count: int = 0,
sec_failure_count: int = 0,
sec_total_duration: float = 0.0,
sec_slow_call_count: int = 0,
)
sec_total_duration
class-attribute
instance-attribute
¶
sec_total_duration: float = field(default=0.0)
sec_slow_call_count
class-attribute
instance-attribute
¶
sec_slow_call_count: int = field(default=0)
admit
¶
admit(record: Record) -> None
Source code in fluxgate/windows.py
115 116 117 118 119 | |
reset
¶
reset() -> None
Source code in fluxgate/windows.py
121 122 123 124 125 | |
record
¶
record(record: Record) -> None
Source code in fluxgate/windows.py
150 151 152 153 154 155 156 157 158 159 160 | |
get_metric
¶
get_metric() -> Metric
Source code in fluxgate/windows.py
162 163 164 165 166 167 168 | |
reset
¶
reset() -> None
Source code in fluxgate/windows.py
170 171 172 173 174 175 176 177 | |