import psutil
import time
import yaml
import os

class WorkloadMonitor:
    def __init__(self, config):
        self.config = config
        self.metrics = {}

    def collect_metrics(self):
        self.metrics['cpu_percent'] = psutil.cpu_percent(interval=1)
        self.metrics['memory_percent'] = psutil.virtual_memory().percent
        net_io = psutil.net_io_counters()
        self.metrics['bytes_sent'] = net_io.bytes_sent
        self.metrics['bytes_recv'] = net_io.bytes_recv
        return self.metrics

    def store_metrics(self, metrics):
        # Placeholder for storing metrics in a time-series database (e.g., Prometheus)
        # In a real implementation, this would involve pushing the metrics to Prometheus or another TSDB.
        # For now, we'll just print them.
        print(f"Collected Metrics: {metrics}")

    def run(self):
        while True:
            metrics = self.collect_metrics()
            self.store_metrics(metrics)
            time.sleep(self.config.get('collection_interval', 60))  # Default to 60 seconds


if __name__ == '__main__':
    # Load configuration
    config_path = os.path.join(os.path.dirname(__file__), '../config/monitoring.yaml')
    with open(config_path, 'r') as f:
        config = yaml.safe_load(f)

    monitor = WorkloadMonitor(config)
    monitor.run()