Dynamic Thermal Governance in Local AIOps: Automated GPU Offloading via n8n, Open WebUI, and Ollama

Running local LLMs (Large Language Models) on home server infrastructure or small-form-factor GPUs offers privacy and lower latency, but passive cooling or compact GPU enclosures often face thermal throttling under heavy or sustained prompt workloads.

To solve this, we can design an automated AIOps dynamic thermal governance pipeline using n8n, Open WebUI, and Ollama. This architecture intercepts user prompts, checks live GPU core temperatures via an endpoint, and intelligently routes execution to the GPU runtime or automatically falls back to a CPU runtime when heat thresholds are exceeded.

Architecture & Workflow Overview

[ Open WebUI ] 
      │ (Webhook POST)
      ▼
[ n8n Workflow ]
      │
      ├─► Extract Payload
      ├─► Check GPU Temp (HTTP GET to Exporter)
      ├─► Evaluate Temperature Threshold (e.g., > 60°C)
      │
      ├───► [Temp Normal] ──► Ollama API (GPU) ──► Format Response ──┐
      │                                                             │
      └───► [Temp High]   ──► Ollama API (CPU) ──► Format Response ──┼─► Respond to Webhook
                                                                    │
                                                                    ▼
                                                            [ Open WebUI Output ]

1. Monitoring GPU Thermals (The Sensor)

To allow n8n to make real-time decisions, a lightweight exporter or HTTP API returns current GPU metrics in JSON format (e.g., exposing nvidia-smi queries over an internal endpoint).

Sample Temperature Endpoint Response ([http://192.168.88.4:9999](http://192.168.88.4:9999)):

JSON

{
  "temperature": 62
}

2. Orchestration Pipeline Breakdown (n8n Workflow)

The n8n workflow acts as the central router between Open WebUI and the local LLM inferencing engine:

  1. OpenWebUI Webhook: Receives incoming chat request payloads from Open WebUI.

  2. Extract Payload: Parses prompt content, model parameters, and context metadata.

  3. Check GPU Temp (HTTP): Queries the local thermal monitoring endpoint ([http://192.168.88.4:9999](http://192.168.88.4:9999)).

  4. Check Temp Logic: Evaluates temperature against safe operational limits (e.g., target threshold = $60^\circ\text{C}$).

  5. Switch Route:

    • GPU Path ($\text{Temp} \le 60^\circ\text{C}$): Routes execution to the GPU-accelerated Ollama instance endpoint.

    • CPU Fallback Path ($\text{Temp} > 60^\circ\text{C}$): Re-routes execution to the CPU-bound Ollama instance to allow the GPU fan/heatsink to cool down without dropping the user's session.

  6. Format & Respond: Prepends status indicators (such as 🐢 [Running CPU Fallback] when active) to inform the user before returning the response payload back to Open WebUI.

3. Sample Code Snippets

    A. HTTP GPU Temperature Monitor (Python Endpoint)

        A lightweight Flask/FastAPI service querying nvidia-smi:

            Python

            from flask import Flask, jsonify
            import subprocess

            app = Flask(__name__)

            @app.route('/', methods=['GET'])
            def get_gpu_temp():
                try:
                    # Queries current GPU temperature using nvidia-smi
                    result = subprocess.run(
                    ['nvidia-smi', '--query-gpu=temperature.gpu', '--format=csv,noheader,nounits'],
                    stdout=subprocess.PIPE,
                    text=True,
                    check=True
                )
                    temp = int(result.stdout.strip())
                        return jsonify({"temperature": temp}), 200
                    except Exception as e:
                    return jsonify({"error": str(e)}), 500

                if __name__ == '__main__':
                app.run(host='0.0.0.0', port=9999)

    B. n8n Routing Logic Node (JavaScript Function Node)

        JavaScript

            // Extract temperature from HTTP node response
            const temp = $json.temperature;
            const THRESHOLD = 60; // Max acceptable GPU temp in °C

            if (temp > THRESHOLD) {
              return [{ json: { route: "CPU", temp: temp } }];
            } else {
              return [{ json: { route: "GPU", temp: temp } }];
            }

4. Practical Results in Open WebUI

When the GPU operates within nominal temperatures, requests hit the primary GPU node for maximum tokens-per-second performance.

When sustained batch workloads raise GPU temps past the defined limit (e.g., reaching $62^\circ\text{C}$):

  1. The n8n router dynamically shifts processing to the CPU Fallback Ollama endpoint.

  2. Open WebUI seamlessly displays the output with a status tag: 🐢 [Running CPU Fallback].

  3. The GPU core is allowed to cool down passively while service continuity remains uninterrupted.

Examples:









Key Takeaways

  • Hardware Longevity: Prevents GPU degradation from sustained high-temperature running in compact or passively cooled lab builds.

  • High Availability: Ensures model responses are delivered even when dedicated GPU acceleration is throttled or offloaded.

  • Declarative AIOps: Highlights how local low-code automation tools like n8n can bridge UI frontends with hardware-aware orchestration.


Comments

Popular posts from this blog

AdGuard Home DNS for Newbies - Part 3

Suricata on Mikrotik(IDS+IPS) = Part 4 - Configuration of the IPS Part

DHCP for Dummies: How Your Devices Get Online Without You Lifting a Finger