Background thread target that updates CPU and memory usage gauges.
(interval: int = 5)
| 516 | |
| 517 | |
| 518 | def monitor_resources(interval: int = 5): |
| 519 | """Background thread target that updates CPU and memory usage gauges.""" |
| 520 | logger.debug("Starting resource monitoring with interval %d seconds", interval) |
| 521 | p = psutil.Process() |
| 522 | logger.debug("PID is %d", p.pid) |
| 523 | while True: |
| 524 | with p.oneshot(): |
| 525 | cpu_usage = p.cpu_percent() |
| 526 | memory_usage = p.memory_percent() |
| 527 | logger.debug("CPU usage: %s%%, Memory usage: %s%%", cpu_usage, memory_usage) |
| 528 | cpu_usage_gauge.set(cpu_usage) |
| 529 | memory_usage_gauge.set(memory_usage) |
| 530 | time.sleep(interval) |
| 531 | |
| 532 | |
| 533 | def monitor_freshness(store: "FeatureStore", interval: int = 30): |