-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetrics.py
More file actions
33 lines (29 loc) · 1 KB
/
Copy pathmetrics.py
File metadata and controls
33 lines (29 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Metrics tracking for processing performance.
"""
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
@dataclass
class ProcessingMetrics:
"""Track processing metrics."""
start_time: datetime
end_time: Optional[datetime] = None
events_parsed: int = 0
events_filtered: int = 0
anomalies_detected: int = 0
processing_time: Optional[float] = None
def finish(self):
"""Mark processing as finished and calculate processing time."""
self.end_time = datetime.now()
if self.start_time:
self.processing_time = (self.end_time - self.start_time).total_seconds()
def __str__(self) -> str:
"""String representation of metrics."""
return (
f"Processing metrics: "
f"{self.events_parsed} events parsed, "
f"{self.events_filtered} filtered, "
f"{self.anomalies_detected} anomalies, "
f"{self.processing_time:.2f}s processing time"
)