import time
import logging

from prometheus_client import Gauge

# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

# Define Prometheus metrics
system_load_gauge = Gauge('system_load', 'Current system load')
low_latency_threshold_gauge = Gauge('low_latency_threshold', 'Low latency threshold')
high_latency_threshold_gauge = Gauge('high_latency_threshold', 'High latency threshold')


def log_and_export_metrics(system_load, low_latency_threshold, high_latency_threshold):
    """Logs and exports latency thresholds and system load as Prometheus metrics."""
    logging.info(f"System Load: {system_load}, Low Latency Threshold: {low_latency_threshold}, High Latency Threshold: {high_latency_threshold}")

    system_load_gauge.set(system_load)
    low_latency_threshold_gauge.set(low_latency_threshold)
    high_latency_threshold_gauge.set(high_latency_threshold)


if __name__ == '__main__':
    # Example usage (replace with actual system load and threshold values)
    from prometheus_client import start_http_server

    start_http_server(8000)
    while True:
        # Simulate system load and threshold values changing
        system_load = 0.5  # Example value
        low_latency_threshold = 0.1  # Example value
        high_latency_threshold = 0.5  # Example value

        log_and_export_metrics(system_load, low_latency_threshold, high_latency_threshold)
        time.sleep(60)
