paul f717f7a82f Long-term telemetry: hourly rollups in JSONL, a range selector in the UI
- telemetry/record.py: a Recorder subscribed to Telemetry keeps min/avg/max
  per metric for the current hour and appends each finished hour as one JSON
  line to records-YYYY-MM.jsonl in the data dir (~400 days kept; whole months
  older than that are pruned on start). Best effort by design: a failing disk
  logs once and stops recording; nothing else notices. load() merges lines per
  hour (a restart re-writes the current hour; torn last lines are skipped).
- app.py: the recorder runs unless --demo (simulated samples must not mix into
  real records) and flushes the open hour in close(), after the telemetry
  thread has stopped. records(days) validates 1..400.
- Web: GET /api/records?days=N (bad values answer 400 with the reason).
- UI: a range selector above the power/temperature charts switches them
  between the live 10 minutes and hourly averages for 24 h / 7 d / 30 d /
  1 y; the chart window, tick labels (min/h/d), tooltips and table captions
  adapt to the span. Live samples keep accumulating behind a long-range view,
  so switching back is instant.
- Tests: test_record.py (5) and a /api/records case in test_web.py; README
  updated (API table, System section, layout).
2026-12-05 18:04:57 +13:00

The Kurgan

The Kurgan's sword

One process that runs this PC's backend systems, with one web UI at http://127.0.0.1:8080/:

Capability What it does Package
Telemetry CPU, GPU and whole-PC power readings, once a second, with 10 minutes of history kurgan/telemetry
Display The CPU/GPU/power dashboard on the Thermaltake 3.9" LCD kurgan/display
Cooling Commander PRO case fans and motherboard top fans on selectable profiles kurgan/cooling
Lighting Case fan, RAM and GPU LEDs: off, temperature or the red side chase kurgan/lighting
AI Serves Strata and llama.cpp at /strata/v1 and /llama/v1, running one at a time: a request starts the one it needs, and an unused one stops kurgan/ai
Web UI Control and monitoring for all of the above, plus a JSON API kurgan/web

It replaces three background programs: the TT LCD Dashboard task, Strata's tray service and the Qwen4 service (llama.cpp plus its monitor page on port 8084). Sensors are read once and shared, so the LCD, the fan curves, the lighting and the web UI all use the same readings.

Setup

powershell -ExecutionPolicy Bypass -File .\setup.ps1 -RetireAIServices

This does the following:

  • Installs the Python packages into the project's .venv (or for the current user).
  • Installs PawnIO. PawnIO is the signed driver LibreHardwareMonitor and FanControl also use. It reads the Intel CPU sensors and drives the motherboard fan headers and the RAM lighting.
  • Replaces the old TT LCD Dashboard task with a The Kurgan scheduled task. The task runs pythonw -m kurgan hidden, with admin rights, at every logon.

-RetireAIServices stops and disables the Strata Local Service and Qwen4 Local Service tasks, so The Kurgan can run whichever server you select. Without that switch, The Kurgan finds those servers already listening on their ports. It shows them as "running outside The Kurgan" and monitors them, but it never starts a second copy. Requests go to one only once it answers as the expected server; a port held by some other program is reported, not served.

uninstall.ps1 removes the task. uninstall.ps1 -RestoreAIServices also re-enables and starts the two LLM service tasks. -RemovePawnIO uninstalls PawnIO.

Admin rights are needed for these readings and controls:

  • CPU temperature and power
  • The motherboard top fans
  • The RAM lighting

Without admin rights those show -- or stay idle, and everything else works. The LLM servers always run as a normal user at medium integrity, never elevated, even though The Kurgan itself is elevated (see kurgan/ai/launcher.py). The web UI shows each server's integrity level.

Web UI

Open it from the tray icon (left-click, or Open The Kurgan in its menu) or browse to http://127.0.0.1:8080/. It only listens on 127.0.0.1. The page refreshes once a second while it is visible. Every chart has a Table button that shows the same numbers as a table. The tray icon also pops a balloon tip when something starts to go wrong — a fan group entering failsafe, an AI server reporting an error, or a sensor source starting to fail. What is already wrong when The Kurgan starts is not ballooned; it sits in the tray menu and the UI.

  • System: CPU and GPU temperature, load, clock and power; GPU memory; the LCD's state. Charts show whole-PC power (stacked: other, CPU, GPU) and temperatures over the last 10 minutes. A range selector above the charts switches them to hourly averages for 24 hours, 7 days, 30 days or a year. Those long-term rollups live in %LOCALAPPDATA%\Kurgan\records-YYYY-MM.jsonl — one JSON line per hour, about 400 days kept, written best effort (a failing disk stops recording and nothing else notices; --demo never records). When a sensor source's last read failed — a disconnected Commander PRO, a busy NVML — a pill in the header names it and hover shows the error.
  • Cooling: the fan profile selector; each fan group's duty, temperature and RPMs; fan speeds over time; and the selected profile's curves, with a dot for each group's current operating point. Hover over a profile to preview its curves.
  • Lighting: a mode selector per zone (case fans, RAM, GPU), the zone's status, and the shared chase speed.
  • AI: pick Strata (and its model), llama.cpp or None; requests to either address also pick it. Then see the server's process, model, context size, live request progress and token speeds, and when it will stop if unused; load or unload the model; GPU memory over time; and recent requests.

Every choice is saved immediately in %LOCALAPPDATA%\Kurgan\settings.json and restored at the next start.

JSON API

Request Body / result
GET /api/state Everything live (what the UI polls), including telemetry.health: the sensor sources whose latest read failed, each with its error and age
GET /api/history The last 10 minutes of telemetry and fan duty
GET /api/records?days=N Hourly min/avg/max rollups for the last N days (1-400), oldest first
GET /api/config Fan profiles and LCD theme thresholds
POST /api/lighting {"zone": "case_fans"|"memory"|"gpu", "mode": "off"|"temperature"|"chase"}
POST /api/cooling/profile {"profile": "quiet"|"balanced"|"performance"|"full"}
POST /api/ai/active {"backend": "strata"|"llama"|null, "variant": "q5"|"iq3"} (variant: Strata only, optional)
POST /api/ai/model {"action": "load"|"unload"}
any /strata/..., /llama/... Passed to that LLM server (see AI)

POSTs to /api/... need Content-Type: application/json and an X-Kurgan: 1 header. A web page on another site can't send that header without a CORS preflight, which this server never answers. Requests must also name 127.0.0.1:<port> or localhost:<port> as the Host, which blocks DNS rebinding. There is no other authentication: any program already running on this PC as you can use the API.

curl.exe -s -X POST -H "Content-Type: application/json" -H "X-Kurgan: 1" `
  -d '{\"profile\":\"quiet\"}' http://127.0.0.1:8080/api/cooling/profile

Settings

%LOCALAPPDATA%\Kurgan\settings.json, created on the first start:

{
  "cooling":  {"profile": "balanced", "gpu_ports": [4, 5, 6], "cpu_ports": [1, 2, 3], "top_channels": [2, 5]},
  "lighting": {"case_fans": "chase", "memory": "off", "gpu": "off"},
  "ai":       {"active": "strata", "strata_model": "q5", "idle_stop_minutes": 40},
  "web":      {"port": 8080}
}

On the first start, The Kurgan imports the TT LCD Dashboard's fan ports and RAM and GPU lighting modes from %LOCALAPPDATA%\TTLcdDashboard. The old task's --rgb-side-chase becomes case_fans: chase. The file is checked strictly. An invalid file stops The Kurgan with a message, rather than starting without fan control. A failed save leaves the previous setting in place, both in memory and on disk.

idle_stop_minutes is how long a server may go unused before The Kurgan stops it (0 = never, up to 1440). The ai section also accepts these optional keys, for when an install moves:

  • strata_root (default D:\AI\Strata) and strata_port (8082, internal)
  • llama_server (llama.cpp b12977), llama_presets, llama_model and llama_port (8083, internal)

See kurgan/ai/config.py. Restart The Kurgan after editing the file by hand.

Command-line lighting options such as --rgb-side-chase apply to that run only. The UI marks them "this run only"; choosing a mode in the UI saves it.

Log: %LOCALAPPDATA%\Kurgan\kurgan.log

AI: Strata and llama.cpp

Point OpenAI-compatible clients at The Kurgan:

Server Base URL Chat page Model
Strata http://127.0.0.1:8080/strata/v1 http://127.0.0.1:8080/strata/ OrcaRouter Qwen3.8 Flash Next, Q5_K_M or IQ3_XXS (selectable)
llama.cpp http://127.0.0.1:8080/llama/v1 http://127.0.0.1:8080/llama/ Qwen4 35B-A3B UD-Q5_K_XL

No API key is needed. Clients that insist on one can send any key.

Only one server runs at a time, so the two never share the RTX 4090's 24 GB. A request starts the server it is addressed to. If the other server is running, it is stopped first:

  • If the other server is busy (a request in progress, a reply being generated, or a model loading), the new request waits until it finishes, for up to 10 minutes, rather than cutting it off.
  • Stopping means stopping completely: every process in its job object has ended and its port has closed. Only then does the other server start.
  • A server with a request in flight is never stopped or replaced mid-reply, however the switch happens: the old server finishes its request first, and the new one doesn't start until the GPU's memory is free again.
  • A request that has to start its server waits for it. A swap takes a few seconds, plus the model's load time (about 45 s for either model). Give clients a generous timeout.

A server nobody has used for idle_stop_minutes (40) is stopped, and the UI shows None. The next request starts it again. Choosing a server in the UI starts it straight away. If a request is in progress there, the UI asks before switching.

How the proxy behaves (kurgan/web/proxy.py):

  • Replies stream through as they are generated.
  • A client that hangs up (a timeout, or a cancel) is noticed within a second, even while its request is still waiting: it gives up its place, so it never makes the servers swap, and the server is told to drop it. The log says how long the client waited and at which stage.
  • Clients' own timeouts must allow for the waits above. opencode, for example, gives up after 5 minutes without a reply unless its provider options set headerTimeout.
  • GET /v1/models is answered by The Kurgan while a server is stopped, so a client that lists the models of both doesn't make them swap.
  • Requests from web pages of other sites are refused, as for the UI's own API.

Behind the proxy each server listens on its own port on 127.0.0.1. Clients shouldn't use these ports: requests sent straight to them don't start or keep a server running.

Server Internal port What The Kurgan runs
Strata 8082 kurgan/ai/strata_host.py, using Strata's own terminal\.venv
llama.cpp 8083, under /llama llama-server.exe b12977 in router mode, from the Qwen4 service's presets.ini, with --api-prefix /llama and its API key (sk-local), which the proxy supplies

Strata's optional API-monitor page (/api-monitor) uses absolute paths, so it doesn't work under /strata/. The Kurgan's own AI section shows the same requests.

Both start with no model in memory. The model loads on the first request, or when you press Load model. Strata unloads it after 2000 s idle; llama.cpp sleeps after its preset's idle time. Strata is stopped gracefully through a named event, and gets 45 s to finish; if the server somehow never returns from that, it ends its engine processes and exits by itself after 40 s (The Kurgan's kill stays as the last resort). llama.cpp is ended through its job object. Each server gets the same environment its own service gave it: Strata runs with GGML_CUDA_DISABLE_GRAPHS=1, and llama.cpp runs without it. Both use OpenBLAS's default threading, not the single-thread pin The Kurgan uses for itself.

Live progress comes from different places:

  • Strata: its /metrics endpoint.
  • llama.cpp: its log. Polling /slots would reset the idle timer.

Logs:

  • %LOCALAPPDATA%\Kurgan\logs\strata-host.log and llama-server.log (each keeps the previous run's log as .prev)
  • Strata's own D:\AI\Strata\logs\local-service-*.log: the task log keeps one .prev, and the newest seven stdout/stderr pairs are kept

A server that exits on its own is restarted after 5 seconds. After 5 exits within 5 minutes, The Kurgan waits 5 minutes before trying again, and the UI shows why.

Updating Strata: Strata's LOCAL-SERVICE-HANDOFF.md assumes its own tray service. Once that service is retired, select None in the UI before updating Strata, then select Strata again. Until the update is finished, don't send requests to /strata/: any one of them starts Strata again. The Kurgan starts strata_host.py with Strata's own server.main, so the update procedure otherwise stays the same.

Cooling

Profiles

Profile GPU-side case fans CPU-side case fans Top fans
Quiet 35% to 45 C, 100% at 75 C 35% to 55 C, 100% at 85 C start 55 C, stop below 50 C
Balanced (the original curves) 40% to 40 C, 50% at 50 C, 65% at 60 C, 100% at 70 C 40% to 50 C, 50% at 60 C, 65% at 70 C, 100% at 80 C start 50 C, stop below 45 C; 30% at 50 C, 60% at 60 C, 100% at 70 C
Performance 50% to 35 C, 100% at 65 C 50% to 45 C, 100% at 75 C start 45 C, stop below 40 C
Full speed 100% 100% 100%

The exact points are in kurgan/cooling/profiles.py. Duty between points is interpolated. A profile change raises speeds at once. Lower speeds follow the usual ramp-down: they wait 10 seconds after the last rise, then fall at most 2 points per second. These fail-safes apply in every profile:

  • Fans run at 100% on start-up.
  • They run at 100% after a polling gap of over 5 seconds.
  • They run at 100% when a temperature is missing or invalid.
  • A group runs at 100% when one of its fans reads below 200 RPM on three consecutive polls after its 10-second spin-up; a single glitchy reading doesn't count.
  • The top fans run at 100% when a fan that was seen turning then reads 0 RPM on three consecutive polls.
  • The top fans are held at 100% while either case-fan group runs at 85% or more. They are released once both groups are at 65% or less.

Ports and channels

On this machine, identification confirmed these mappings:

  • Commander PRO PWM ports 1-3 are the CPU side and 4-6 the GPU side. This is separate from the RGB chain order.
  • The two top extractors are on SYS_FAN1 and SYS_FAN4 (NCT6687D PWM channels 2 and 5).
  • The CPU cooler is on CPU_FAN1 (channel 0), which is never touched.

The mapping is in settings.json. To identify or change it, first exit The Kurgan from its tray menu, then run:

.\.venv\Scripts\python.exe -m kurgan.cooling.control --identify 1,2,3         # these ports to 100%; watch which side speeds up
.\.venv\Scripts\python.exe -m kurgan.cooling.control --save-ports 4,5,6       # GPU side
.\.venv\Scripts\python.exe -m kurgan.cooling.control --save-cpu-ports 1,2,3   # CPU side (GPU side first)
.\.venv\Scripts\python.exe -m kurgan.cooling.board_fans --probe               # read-only motherboard headers (admin)
.\.venv\Scripts\python.exe -m kurgan.cooling.board_fans --identify 2,5        # hold channels at 100% (admin)
.\.venv\Scripts\python.exe -m kurgan.cooling.board_fans --auto 2,5            # hand them back to the BIOS (admin)
.\.venv\Scripts\python.exe -m kurgan.cooling.control --save-top-channels 2,5

--identify leaves the selected group at 100%, rather than guessing its previous profile. Do not guess the port mapping. --gpu-fan-ports 4,5,6 overrides the saved ports for one run, and --no-gpu-fan-control turns fan control off for one run.

Controller ownership: exit iCUE, FanControl and other Commander PRO tools. If you run OpenRGB, disable its Corsair Commander Pro and Corsair Lighting Node Core detectors in both %APPDATA%\OpenRGB\OpenRGB.json and C:\Program Files\OpenRGB\service_config\OpenRGB.json. While another tool has a device, The Kurgan leaves that device alone and says so in the UI. The top fans share LibreHardwareMonitor's ISA-bus mutex, so don't let another tool control the same headers. On exit the case fans are left at 100% and the top fans go back to the BIOS Smart Fan curve.

This is software control, not a hardware thermal safeguard. It can't guarantee a speed change after a USB failure, a forced process kill or a system hang, and the Commander PRO may keep its last duty. If a top-fan write fails, The Kurgan hands those headers back to the BIOS curve at once; if even that fails, the UI says what duty they are left at. Verify temperatures and fan rotation under your real workloads. Only SYS_FAN4's tach is wired to the EC, so top-fan stall detection covers that fan only: a channel whose tach has never been seen turning is left alone rather than crying wolf.

Lighting

Zone Device Modes
Case fans Corsair Lighting Node CORE (1B1C:0C1A), six QL120 fans on header 1 off, temperature, red side chase
RAM Four Corsair Dominator Platinum DDR5 sticks, over the Intel SMBus through PawnIO (admin) off, temperature, red side chase
GPU ASUS ROG STRIX RTX 4090 LED row, over NVIDIA's nvapi64.dll off, red side chase
  • Off: the case fans return to the CORE's own hardware effect. The RAM is held dark while The Kurgan runs; black frames are refreshed every 5 s, and the stored effects are untouched. The GPU's previous direct colours and mode are restored.
  • Temperature:
    • Case fans: the CPU-side fans follow CPU temperature and the GPU-side fans follow GPU temperature. They are green below --temp-warn (50 C), yellow up to --temp-hot (80 C), and red above.
    • RAM: the hotter of CPU and GPU blends from dark red (24, 0, 0) to warm orange (255, 48, 0).
  • Red side chase: warm-orange heads with four fading trail LEDs over dark red. All three zones share one power-paced clock, so they stay in step. The pace is 150 ms per LED at 150 W or less, speeding up evenly to 25 ms at 550 W or more (--rgb-chase-*).
    • Case fans: the CPU route is bottom → middle → top → middle, and the GPU side is mirrored.
    • RAM: two mirrored heads visit sticks 4 → 3 → 2 → 1 → 2 → 3 once per fan cycle.
    • GPU: one head runs front to back and back again once per cycle.

Calibrated case-fan outer-ring indices (zero-based within each 34-LED fan: hub 0-9, outer ring 10-21, inner ring 22-33):

Chain fan Location Outer ring left / right of 12
1 GPU bottom 16 / 17
2 GPU middle 16 / 17
3 GPU top 16 / 17
4 CPU top 19 / 20
5 CPU bottom 10 / 11
6 CPU middle 19 / 20

The CORE needs a keep-alive every 5 seconds or it drops back to its hardware effect. Updates on every device are capped at about 22 per second. The CORE and the LCD share a Genesys USB 2.0 hub, and heavier traffic once hung the LCD firmware until it was power-cycled. If the LCD repeatedly reports a handshake timeout (opcode 0x85), set the case fans to off. Then safely power-cycle the LCD and check the cable, power and hub routing before re-enabling the chase. Do not unplug internal cables while the PC is powered.

The RAM controllers are at 0x18-0x1B, top to bottom. They are written directly over SMBus with PawnIO's I801 module (PawnIO Modules 0.2.12; its LGPL source and licence are in kurgan/hardware/pawnio/). RAM control never changes the stored lighting effects. The GPU driver is restricted to PCI 10DE:2684, subsystem 1043:8932, with supported ENE firmware at I2C 0x67. It never sends ENE's save-to-flash command. Exit ASUS lighting software, iCUE and OpenRGB before using either.

NVIDIA services:

  • Keep NVDisplay.ContainerLocalSystem running. With it disabled, the card stayed in P0 at full clocks (about 63 W) when idle.
  • Its nvgwls.exe plugin is blocked instead, because it repeatedly loaded the GPU at about 270 W. The block is an Image File Execution Options Debugger value under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\nvgwls.exe; delete that key to undo it.
  • NvContainerLocalSystem, FvSvc and the NVIDIA App self-update task remain disabled. Driver updates may re-enable them.

Display

The Thermaltake 3.9" bar LCD (USB 264A:233D, 480×128) needs no TT RGB Plus. The GPU is on the left and the CPU on the right, matching the case; all gauges fill clockwise.

Element Shows
Outer gauges CPU package temperature (20–100 °C), GPU temperature (20–90 °C)
Inner gauges CPU and GPU load %
MHz readouts CPU effective clock, GPU graphics clock
Centre tank Total power, full = the PSU rating (1000 W). From the bottom: other (copper), CPU (blue), GPU (aqua). Each tick is 10%
TOTAL readout CPU + GPU + other, in watts
Bottom readouts The three tank layers: GPU W, other W, CPU W

The background is kurgan/display/background.png, loaded once at start-up; restart after replacing it. The panel falls back to its own screen if it gets no frame for a few seconds. When the LCD is unplugged or the PC sleeps, The Kurgan reconnects; everything else keeps running.

Where the watts come from

All figures are DC watts, i.e. load on the power supply; wall draw is roughly 8–12% higher.

Part Source
CPU Measured: the package's energy counter (RAPL), via PawnIO
GPU Measured: board power from NVIDIA (the whole card, including its fans and lighting)
CPU regulator losses Derived: CPU watts × 11%
Memory Estimated per module (4 × DDR5): 2.5 W idle to 5.5 W, scaled by CPU load
Drives Estimated from each drive's activity and rated power (Lexar NQ790 3.5 W, Kingston KC3000 8.8 W; the USB hard drive as bus-powered, spun down after 10 minutes idle)
Case fans Estimated from the Commander PRO's fan speeds (about 2 W per fan at 1500 rpm)
Motherboard & chipset Fixed 15 W
Motherboard-header fans/pump Fixed 5 W
USB devices & RGB lighting Fixed 12 W

The estimates are in PowerModel in kurgan/telemetry/sensors.py.

Running by hand

Stop-ScheduledTask "The Kurgan"                               # only one copy runs at a time
.\.venv\Scripts\python.exe -m kurgan                          # console, Ctrl+C to stop
.\.venv\Scripts\python.exe -m kurgan --preview x.png          # render one LCD frame from live sensors
$env:KURGAN_DATA_DIR = "$env:TEMP\kurgan-demo"
.\.venv\Scripts\python.exe -m kurgan --demo --port 18080      # simulated hardware; separate settings
Start-ScheduledTask "The Kurgan"                              # back to the hidden, elevated copy

In demo mode the LLM servers use ports 18082 and 18083, but they are real servers. python -m kurgan --help lists the LCD and lighting options. To make one permanent, add it to the task's arguments. Lighting modes are better chosen in the UI.

Tool Use
python -m kurgan.telemetry.sensors Print the live readings and power breakdown (exit The Kurgan first: one program at a time should poll the Commander PRO)
python -m kurgan.display.renderer demo.png Render the LCD with fixed demo values
python -m kurgan.display.tt_lcd LCD test card
python -m kurgan.tray Show a test tray icon for 20 seconds

Tests: .\.venv\Scripts\python.exe -m unittest discover -s tests

Layout

kurgan/
  app.py           wires the capabilities together; command line; single instance
  settings.py      settings.json: defaults, strict validation, atomic saves, legacy import
  paths.py, theme.py, tray.py, demo.py (simulated hardware for --demo)
  telemetry/       sensors.py (CPU/GPU/system power), readings.py, service.py (sampling + history),
                   record.py (hourly rollups for the long-term charts)
  display/         tt_lcd.py (panel HID protocol), renderer.py, service.py (LCD loop), background.png
  cooling/         profiles.py, control.py (case-fan groups, top-fan curve), board_fans.py (NCT6687D)
  lighting/        case_fans.py (CORE patterns + shared chase clock), lighting_node.py, memory.py, gpu.py, service.py
  ai/              config.py, launcher.py (non-elevated child processes in job objects),
                   backends.py (Strata, llama.cpp), service.py (one-at-a-time supervisor), strata_host.py
  web/             server.py (API), static/ (index.html, app.js, style.css, logo.png, favicon.ico)
  assets/          sword.png, hilt.png, kurgan.ico (tray icon); make_assets.py rebuilds them and the
                   web UI's logo and favicon from The-Kurgan-Sword.png
  hardware/        hid.py (Windows HID), pawnio/ (signed PawnIO modules, LGPL-2.1)
tests/             unittest suites
docs/              design references and research notes
lcd_dashboard.py   compatibility shim for the old "TT LCD Dashboard" task until setup.ps1 is re-run

LCD protocol notes

The panel protocol was worked out by ttlcd, thermaltaked and Tower-500-LCD-Controller. This is an independent implementation.

  • Interface 0: commands (440-byte reports). Handshake 85 87 85 87 84 81, brightness 12, heartbeat 82.
  • Interface 1: frames (1024-byte reports). A baseline JPEG in 1020-byte chunks: header 08 count 00 80, then 08 index 00 00.
S
Description
No description provided
Readme
2 MiB
0 Stars 1 Watchers 0 Forks
Languages
Python 82.4%
JavaScript 7.2%
OpenEdge ABL 5.6%
CSS 2.4%
PowerShell 1.4%
Other 1%