diff --git a/.gitattributes b/.gitattributes index 385524c..6895dcc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,12 @@ * text=auto eol=lf *.rrd binary + +# Left out of release archives (git archive): CI, tests and their +# synthetic fixtures, and developer tooling (REQ-REL-003). +/.editorconfig export-ignore +/.gitattributes export-ignore +/.github export-ignore +/tests export-ignore +/phpstan.neon export-ignore +/phpunit.xml export-ignore +/phpunit-integration.xml export-ignore diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index e9fdcc8..a189993 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -70,7 +70,7 @@ jobs: integration-test: name: PHP ${{ matrix.php }} on Cacti ${{ matrix.cacti }} runs-on: ubuntu-latest - timeout-minutes: 30 + timeout-minutes: 75 strategy: fail-fast: false @@ -179,9 +179,9 @@ jobs: GPU_TEST_DATABASE: disposable run: '"$CACTI_PEST_BIN" --configuration=phpunit-integration.xml' - # The integration tests provoke refusals that the plugin logs as errors, - # such as a schema downgrade. Keep their log apart so the error check - # below covers the install and the poller run. + # The integration tests provoke refusals that the plugin logs, such as + # a schema downgrade. Keep their log apart; the check below allows only + # those refusals in it and nothing at all in the install and poller run. - name: Set the integration tests' log aside if: always() run: | @@ -279,20 +279,96 @@ jobs: fi exit "$rc" + # Thold and Maint at the tagged releases the plugin is tested against, + # unchanged. The plugin never loads them; the alert test drives them as an + # operator would (docs/alerting.md). + - name: Checkout Thold v1.8.2 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: Cacti/plugin_thold + ref: 1eb406bd0f81f3204358cce7bd43c8bb5adc8e4a + path: cacti/plugins/thold + persist-credentials: false + + - name: Checkout Maint v1.3 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + repository: Cacti/plugin_maint + ref: cd62de9cc323a4f5a8ac80a8d9dda3c7fa16c470 + path: cacti/plugins/maint + persist-credentials: false + + # Each test runs in the same database as the end-to-end test, after it. + # The failure and restore tests provoke collection, database, and RRD + # errors on purpose, so their logs are printed but not checked; each + # test checks the state those errors leave. The alert and scale logs must + # hold nothing but expected collection failures, and no TypeError. + - name: Run the alerting, failure, restore, and scale tests + working-directory: cacti + env: + GPU_TEST_DATABASE: disposable + GPU_E2E_AGENT: 127.0.0.1:1161 + GPU_E2E_FIXTURES: /var/lib/gpu-e2e + run: | + set -uo pipefail + export GPU_E2E_SECRETS="$RUNNER_TEMP/snmp-secrets" + mv log/cacti.log log/main.log + rc=0 + php cli/plugin_manage.php --plugin=thold --plugin=maint --install --enable || rc=1 + php plugins/gpu/tests/bin/alert-flow.php || rc=$? + mv log/cacti.log log/alert.log + echo "== alert log" + cat log/alert.log + # The test polls off the cron schedule, so Cacti may warn that the + # poll is out of sync and that it cannot mail the admin about it. + if grep -E "FATAL:|ERROR:|WARNING:|TypeError" log/alert.log | grep -v -e "GPU WARNING: Node [0-9]*: collection failed" -e "Cactid/Cron is out of sync" -e "Primary Admin account notifications disabled"; then + rc=1 + fi + for flow in failure restore; do + php "plugins/gpu/tests/bin/$flow-flow.php" || rc=$? + echo "== $flow log, not checked" + if [ -f log/cacti.log ]; then + mv log/cacti.log "log/$flow.log" + cat "log/$flow.log" + fi + done + php -d memory_limit=2G plugins/gpu/tests/bin/scale-flow.php 100 provision || rc=$? + if [ -f log/cacti.log ]; then + mv log/cacti.log log/scale.log + echo "== scale log" + cat log/scale.log + # The test polls off the cron schedule, so Cacti may warn that the + # poll is out of sync and that it cannot mail the admin about it, + # and the devices the failure and permission tests left down fail + # their polls with no notification receiver configured. + if grep -E "FATAL:|ERROR:|WARNING:" log/scale.log | grep -v -e "Cactid/Cron is out of sync" -e "Primary Admin account notifications disabled" -e "No notification receivers configured for event: cactiNotifyDeviceFailedPoll"; then + rc=1 + fi + fi + mv log/main.log log/cacti.log + exit "$rc" + - name: Check Cacti log for errors if: always() run: | + rc=0 if [ -f cacti/log/integration.log ]; then - echo "== integration tests (not checked)" + echo "== integration tests" cat cacti/log/integration.log + # Two refusals are provoked on purpose: a schema newer than the + # code, and a second record for a stored GPU UUID. + if grep -E "FATAL:|ERROR:|WARNING:" cacti/log/integration.log | grep -v -e "GPU ERROR: Schema version 99 is newer than this code" -e "GPU WARNING: Node [0-9]*: a new GPU record was not stored because GPU record [0-9]* already has its UUID"; then + rc=1 + fi fi if [ -f cacti/log/cacti.log ]; then echo "== install and poller run" cat cacti/log/cacti.log if grep -E "FATAL:|ERROR:|WARNING:" cacti/log/cacti.log; then - exit 1 + rc=1 fi fi + exit "$rc" # A 1.2.31 site may still run PHP 8.1. Enabling the plugin there must be # refused with a message and leave Cacti working, both on a fresh install diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..07c8b04 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,36 @@ +# Changelog + +All user-visible changes are listed here. Versions follow [Semantic Versioning](https://semver.org/); there is no release yet. + +## Unreleased + +Phase 1 (NVIDIA through SNMP extend), first version 0.1.0. Not yet run on GPU hardware; see [docs/pilot-plan.md](docs/pilot-plan.md). + +### Added + +- Install, upgrade, disable, and uninstall through Cacti's Plugins page, refused with a message on PHP below 8.2. +- GPU Nodes (GPU Admin), GPU Inventory and GPU Health (GPU View), each limited to devices the user may see. +- GPU identity records keyed by vendor and UUID, with replacement detection, confirmed moves between nodes, absence after a configurable number of collections, and JSON export. +- Collection of `nvidia-smi` through two fixed SNMP `extend` lines on each node ([docs/node-setup.md](docs/node-setup.md)), with strict parsing that turns any bad output into unknown values. +- The *GPU - Devices* data query, the *GPU - Metrics* data template, and ten graphs per GPU: Utilization, Memory, Temperature, Power, Clocks, Throttle, ECC Errors, New ECC Errors, Retired Pages, and Sample Age. +- Decoded clock event reasons as alertable 0 or 1 indicators, with the raw mask kept and shown on GPU Health. +- The clock event reasons are read as `clocks_event_reasons.active`, falling back to `clocks_throttle_reasons.active` through an optional third extend entry, `cacti_gpu_legacy`, when nvidia-smi refuses the new name (#36). +- At most 128 GPUs per node are supported, which keeps the metrics output well under snmpd's 100 KiB limit. +- New corrected and uncorrected ECC errors since the previous sample, computed by the plugin as gauges; retired single-bit and double-bit page counts; the ECC mode, shown on GPU Health when ECC values are unknown. +- Thold threshold templates for temperature, power against its limit, the hardware and thermal throttle indicators, new uncorrected ECC errors, pending page retirement, and sample age ([docs/alerting.md](docs/alerting.md)). +- The GPU Health page: freshness, last collection outcome, Maint state, backend, tool and driver versions, GPU presence, ECC state, and the raw clock event mask. It never contacts a node. +- An RRD file found at a new GPU data source's path is renamed instead of reused, so a database restored older than the RRD directory attaches no history to another GPU ([docs/backup.md](docs/backup.md)). +- *Remove the plugin's Cacti objects on uninstall* (default off): uninstall then removes the plugin's templates that nothing outside it uses, and its data query XML if unchanged. It never deletes RRD files, devices, graphs, or data sources. +- Operator, alerting, backup, performance, and security review documentation. + +### Upgrade notes + +- Schema version 3 adds the observation columns `ecc_corr_new`, `ecc_uncorr_new`, `retired_sbe`, `retired_dbe`, and `ecc_mode`. The upgrade runs when the Plugins page or a GPU page is opened. +- The metrics `extend` line now also asks for `ecc.mode.current`, `retired_pages.sbe`, and `retired_pages.dbe`. Update it on every node from [docs/node-setup.md](docs/node-setup.md); until then the node's collection fails with *Output rejected*. +- Only on a node whose `nvidia-smi` is older than the clock event reasons rename, add the optional `cacti_gpu_legacy` extend line from the same page. A metrics line with the current field list that asks for `clocks_throttle_reasons.active` in the last position also works, because both names print the same bitmask there; a line with the earlier field list does not. +- Re-import `templates/gpu_thold_templates.xml` in Thold to pick up template changes. + +### Not yet supported + +- XID errors: no source fits the fixed `nvidia-smi` commands; decision #8. +- DCGM and AMD backends (phase 2), MIG instances and remote data collectors (phase 3). diff --git a/INFO b/INFO index 69c14bb..10d743d 100644 --- a/INFO +++ b/INFO @@ -16,7 +16,7 @@ [info] name = gpu -version = 0.1.0-dev +version = 0.1.0 longname = GPU author = "Thomas Vincent (somethingwithproof)" email = thomasvincent@gmail.com diff --git a/README.md b/README.md index 1adfda8..e1f1d3f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A Cacti 1.2 plugin that brings per-GPU utilization, memory, temperature, power, ECC errors, XID errors, and throttling reasons from NVIDIA and AMD tools into Cacti. Each GPU becomes an index of a data query on its node's device, so GPU graphs sit next to the node's other graphs under Cacti's permissions, and Thold and Maint can alert on and suppress them. -> **Status: in development, no release yet.** Milestones 2 (foundation) and 3 (NVIDIA collection and Cacti objects) are merged on `main`. The plugin reads `nvidia-smi` on each GPU node through the node's SNMP agent, keeps GPU identity records, and creates one data query index, one data source, and eight graphs per GPU. It has been run only against a real `snmpd` with a fake `nvidia-smi` printing synthetic output, never on GPU hardware. Alerting, the health page, and the phase 1 release are milestone 4. Milestone 1 research is written up from documentation and source; checks that need GPU hardware are still open. Do not run it in production. +> **Status: in development, not released.** Milestone 4 makes phase 1 (NVIDIA through SNMP extend) code complete: collection, identity, graphs, throttle and ECC signals, Thold and Maint alerting, the health page, and the operator documentation. It has been run only against a real `snmpd` with a fake `nvidia-smi` printing synthetic output, never on GPU hardware. Still open before a release: pilots on real hardware ([docs/pilot-plan.md](docs/pilot-plan.md), #54), an external security review ([docs/security-review.md](docs/security-review.md)), fixtures captured from real tools (#14), and scale measured on production-sized hardware ([docs/performance.md](docs/performance.md)). XID errors wait on decision #8. Do not run it in production. ## Why @@ -21,6 +21,17 @@ The plugin closes that gap by turning vendor tool output into Cacti data sources Out of scope: any command that changes a GPU or node (clocks, power limits, resets, MIG layout), a plugin-owned alerting engine, a custom daemon or network protocol, and scheduler or job accounting. See the plan for the research backlog. +## What milestone 4 adds + +- **Throttle reasons as alert values.** The clock event mask is decoded into one 0 or 1 indicator per reason; an unknown mask gives unknown indicators, never zeros, and bits without an indicator stay in the raw mask, which GPU Health shows. +- **ECC as alert values** ([docs/metrics.md](docs/metrics.md)). New corrected and uncorrected errors since the previous sample are computed by the plugin from two consecutive totals and stored as gauges: unknown for a first sample, a missed read, or a driver reload, so a reset never reads as zero or as a negative count. Retired single-bit and double-bit page counts and the ECC mode are read too. Two more graphs per GPU, ten in all, so Cacti stores them. XID is not collected: no source fits the fixed `nvidia-smi` commands (#8). +- **Thold and Maint** ([docs/alerting.md](docs/alerting.md)). Shipped Thold templates for temperature, power against its limit, the throttle indicators, new uncorrected ECC errors, pending page retirement, and sample age. Every value is a gauge, because Thold 1.8.2 fails on an unknown counter. An end-to-end test with unchanged Thold 1.8.2 and Maint 1.3 shows each threshold fire and restore, across an ECC reset, and Maint suppress it. +- **GPU Health** (GPU View). Per node: freshness, how the last collection ended, Maint state, backend, tool and driver versions, and GPU counts; per GPU: presence, sample age, ECC state, and the raw mask. It reads stored records only. +- **Permissions.** The permission suite covers every page file and action, revocation on the next request, and refusals that disclose nothing. +- **Failure and restore qualification.** Scripted end-to-end runs break the agent, the credentials, the tool, its output, the database connection, and RRD writes, and restore the database from a dump, including one older than the RRD files; a new GPU never inherits another's RRD file ([docs/backup.md](docs/backup.md)). +- **Scale** ([docs/performance.md](docs/performance.md)). A scale test times collection, the script server input, Cacti object creation, a poller cycle, and the health page at a given GPU count; CI runs it at 100 GPUs. The 1,000 and 8,000 GPU measurements are not recorded yet, so no supported GPU count is stated. +- **Operator documentation** ([docs/operations.md](docs/operations.md)): install, upgrade, uninstall, least privilege, unavailable values, and troubleshooting. Changes are listed in [CHANGELOG.md](CHANGELOG.md). + ## What milestone 3 adds - **Collection through SNMP extend** ([ADR 0008](docs/decisions/0008-collect-through-snmp-extend.md)). The node's administrator adds two fixed `extend` lines to `snmpd.conf` ([docs/node-setup.md](docs/node-setup.md)); the plugin reads NET-SNMP-EXTEND-MIB through Cacti's SNMP functions with the device's own credentials, SNMPv3 recommended. It runs nothing on the Cacti server or the node. @@ -31,7 +42,7 @@ Out of scope: any command that changes a GPU or node (clocks, power limits, rese - **Device permissions on GPU Nodes.** A GPU Admin sees, changes, exports, and moves only nodes and GPUs on devices they may see in Cacti; a GPU move needs both nodes. A node whose device was deleted can only be disabled. - **The common metric model** ([ADR 0009](docs/decisions/0009-common-metric-core-with-vendor-extensions.md), [docs/metrics.md](docs/metrics.md)). Memory is in bytes, the clock event mask is decoded into `thr_*` indicators, and `age` is the age of the GPU's own sample time, or `U` when unknown. -The installing (web server) user must be able to write `/resource/script_server/`, where the plugin places its data query XML; install and upgrade stop with a message otherwise and retry on the next attempt. Uninstall does not yet remove the templates or the XML (#30). Nodes on remote data collectors are not collected until phase 3. +The installing (web server) user must be able to write `/resource/script_server/`, where the plugin places its data query XML; install and upgrade stop with a message otherwise and retry on the next attempt. Uninstall removes the templates and the XML only when *Remove the plugin's Cacti objects on uninstall* is checked, and never deletes RRD files, devices, graphs, or data sources ([docs/operations.md](docs/operations.md#uninstall)). Nodes on remote data collectors are not collected until phase 3. ## What milestone 2 ships @@ -43,13 +54,14 @@ The installing (web server) user must be able to write `/resource/script_ ### Install for evaluation -These steps install the milestone 3 code to try it. They require Cacti 1.2.31 or later on PHP 8.2 or later. +These steps install the current code to try it; [docs/operations.md](docs/operations.md) has the full operator guide. They require Cacti 1.2.31 or later on PHP 8.2 or later. 1. Copy the repository to `plugins/gpu` under your Cacti directory. The directory must be named `gpu`. 2. In Cacti, open **Configuration > Plugins**, then install and enable **GPU**. 3. Give users the *GPU View* or *GPU Admin* realm under **Configuration > Users**. The installing user gets both. 4. Set up each GPU node's SNMP agent as described in [docs/node-setup.md](docs/node-setup.md), then add the node under **Management > GPU Nodes**. -5. Optionally adjust **Configuration > Settings > GPU**: *Mark Absent After* (default 3 successful collections, from 1 to 100), *Stale After* (how old a sample may be before its values print `U`), and *Keep Plugin Tables on Uninstall* (default on). +5. For alerts, import the shipped Thold templates as [docs/alerting.md](docs/alerting.md) describes. +6. Optionally adjust **Configuration > Settings > GPU**: *Mark Absent After* (default 3 successful collections, from 1 to 100), *Stale After* (how old a sample may be before its values print `U`), and *Keep Plugin Tables on Uninstall* (default on). ## How metrics reach Cacti @@ -63,7 +75,7 @@ Decision [#7](https://github.com/somethingwithproof/plugin_gpu/issues/7) chose S | PHP | 8.2 or later; `setup.php` stays parseable on 8.0 so an unsupported runtime gets a refusal instead of a broken Cacti UI | | NVIDIA | Driver and tool lines to be set by research [#26](https://github.com/somethingwithproof/plugin_gpu/issues/26); DCGM field IDs checked at v3.3.9 and v4.7.0 | | AMD | `amd-smi` on ROCm releases to be set by research [#26](https://github.com/somethingwithproof/plugin_gpu/issues/26) | -| Thold, Maint | No changes required | +| Thold, Maint | Thold 1.8.2 and Maint 1.3, unchanged, tested end to end ([docs/alerting.md](docs/alerting.md)) | ## Design diff --git a/REUSE.toml b/REUSE.toml index 521d95e..587e084 100644 --- a/REUSE.toml +++ b/REUSE.toml @@ -10,6 +10,7 @@ path = [ "README.md", "CONTRIBUTING.md", "SECURITY.md", + "CHANGELOG.md", "docs/**", ".github/**", ".editorconfig", diff --git a/docs/PLAN.md b/docs/PLAN.md index 1c117d9..f0950ff 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -1,6 +1,6 @@ # Cacti 1.2 GPU Plugin Plan -Status: in development, plan revision 2 (2026-11-15). Revision 2 folds in the milestone 1 documentation and source research in [`docs/research/`](research/); items that need hardware are marked *live* and listed in each research page's Live checks table. Milestone 2 (foundation) is implemented: the PHP guard, lifecycle, realms and pages, node registry, GPU identity records, and the test harness. Where it differs from the text below, the difference is stated in place. Milestone 3 (NVIDIA collection and Cacti objects) is merged too: the SNMP extend reader and parser, the collector and cache, the data query, templates, and eight graphs per GPU, tested only against a real `snmpd` with synthetic `nvidia-smi` output. Milestone 4 (alerting, health, release) is not done, and there is no release. Statements about vendor tools, Cacti core, Thold, and net-snmp describe upstream behavior and cite the source that was checked, with the version or commit where one was available. Statements that could not be verified are listed as assumptions with the research issue that confirms them; they are not facts. Owner and estimates are not assigned; milestone 1 produces the estimates. +Status: in development, plan revision 2 (2026-11-15). Revision 2 folds in the milestone 1 documentation and source research in [`docs/research/`](research/); items that need hardware are marked *live* and listed in each research page's Live checks table. Milestone 2 (foundation) is implemented: the PHP guard, lifecycle, realms and pages, node registry, GPU identity records, and the test harness. Where it differs from the text below, the difference is stated in place. Milestone 3 (NVIDIA collection and Cacti objects) is merged too: the SNMP extend reader and parser, the collector and cache, the data query, templates, and eight graphs per GPU, tested only against a real `snmpd` with synthetic `nvidia-smi` output. Milestone 4 (alerting, health, release) makes phase 1 code complete: ECC deltas, Thold templates tested against unchanged Thold 1.8.2 and Maint 1.3, the health page, and failure, restore, and scale tests, all still against synthetic output. Pilots on hardware, an external security review, captured fixtures, and production-scale measurement remain, and there is no release. Statements about vendor tools, Cacti core, Thold, and net-snmp describe upstream behavior and cite the source that was checked, with the version or commit where one was available. Statements that could not be verified are listed as assumptions with the research issue that confirms them; they are not facts. Owner and estimates are not assigned; milestone 1 produces the estimates. `plugin_gpu` brings per-GPU utilization, memory, temperature, power, ECC errors, XID errors, and clock throttling reasons from NVIDIA and AMD tools into Cacti 1.2. Each GPU becomes an index of a data query on its node's Cacti device, so operators see GPU graphs next to the node's other graphs, under Cacti's own permissions, and alert on them with Thold and Maint. @@ -42,7 +42,7 @@ Each phase ships to users. Later phases are re-estimated after the phase before | Phase | Label | Scope | Depends on | |---|---|---|---| | 0 | Research | Vendor tool output, DCGM fields, XID and throttle signals, identity, privileges, collection path decision (milestone 1) | Nothing | -| 1 | Planned | `nvidia-smi` collection, inventory by UUID, data query and templates, graphs, throttle, ECC and XID signals, Thold and Maint, health page (milestones 2 to 4) | Phase 0 | +| 1 | Code complete, not released | `nvidia-smi` collection, inventory by UUID, data query and templates, graphs, throttle, ECC and XID signals, Thold and Maint, health page (milestones 2 to 4) | Phase 0 | | 2 | Planned | DCGM backend, `amd-smi` backend, mapping onto the common metric model (milestone 5) | Phase 1, security review | | 3 | Planned | MIG instances, Cacti remote data collectors (milestone 6) | Phase 2, security review | | - | Research | NVLink and NVSwitch fabric health, per-process usage, scheduler job attribution, vGPU, other vendors | Demand after phase 1 | @@ -242,7 +242,7 @@ Rules, tested by fixtures (REQ-ID-001 to 006): | Data source and graphs | Graph templates per GPU | Created by Cacti's data query path from the templates | | Data source for staleness | A field of the same data query (`age`) | Always numeric | -As built in milestone 3: the data query is *GPU - Devices*, one data template (*GPU - Metrics*) holds every model field, and eight graph templates (Utilization, Memory, Temperature, Power, Clocks, Throttle, ECC Errors, Sample Age) are created for each present GPU. Every model field is drawn by one of them, because `rrdtool_function_create()` puts into the RRD file only the data source items some graph item uses; an undrawn field such as a throttle indicator or `age` would never be stored, so Thold could not use it. The plugin copies the data query XML to `/resource/script_server/plugin_gpu.xml`, so that directory must be writable by the installing user. Absent GPUs stay in the listing rather than using `index_transient`; an operator's **Remove from Data Query** on an absent GPU takes it out, and it returns if reported again. The index delimiter is `!`, which a `vendor/UUID` key cannot contain, and the data query sets `arg_num_indexes`. Uninstall leaves the templates and the XML in place for now (#30). +As built in milestone 3: the data query is *GPU - Devices*, one data template (*GPU - Metrics*) holds every model field, and eight graph templates (Utilization, Memory, Temperature, Power, Clocks, Throttle, ECC Errors, Sample Age) are created for each present GPU. Every model field is drawn by one of them, because `rrdtool_function_create()` puts into the RRD file only the data source items some graph item uses; an undrawn field such as a throttle indicator or `age` would never be stored, so Thold could not use it. The plugin copies the data query XML to `/resource/script_server/plugin_gpu.xml`, so that directory must be writable by the installing user. Absent GPUs stay in the listing rather than using `index_transient`; an operator's **Remove from Data Query** on an absent GPU takes it out, and it returns if reported again. The index delimiter is `!`, which a `vendor/UUID` key cannot contain, and the data query sets `arg_num_indexes`. Uninstall removes the templates and the XML only when *Remove the plugin's Cacti objects on uninstall* is checked (default off), each template only where nothing outside the plugin uses it and the XML only if unchanged; it never deletes RRD files, devices, graphs, or data sources (#30). Milestone 4 adds *New ECC Errors* and *Retired Pages*, ten graphs in all. Templates ship as Cacti template XML and are imported with `import_xml_data()`, matched by hash so re-imports update rather than duplicate, under a lock so two upgrades cannot import together. The data query uses reindex method None; the plugin runs a forced reindex after each inventory change so titles refresh. `api_device_update_host_template()` (called from `api_device_save()` when a template is applied) runs `REPLACE INTO host_snmp_query` with the global default reindex method for data queries that have no cache rows yet, so the plugin sets None again afterward; `api_device_save()` itself only forces method 0 for devices with SNMP version 0. Confirmed by source at `release/1.2.31` and `1.2.x`; running it is *live* ([research/cacti-core.md](research/cacti-core.md)). A data query XML may instead set `index_transient`, which stops removed indexes being marked orphan; M3 chooses between that and keeping absent GPUs in the listing. @@ -270,7 +270,7 @@ One set of fields describes every GPU, so a single set of templates and Thold te | `xid_last` | XID number | per #8 | field 230 | not applicable | | `age` | seconds | computed | computed | computed | -Milestone 3 names the throttle indicators `thr_*` (for example `thr_sw_power_cap`, `thr_hw_slowdown`) so every data source name fits Cacti's 19-character limit, and reads the mask as hex or decimal. The NVIDIA backend reads the mask through the old query name `clocks_throttle_reasons.active`, because the new `clocks_event_reasons.*` names are not confirmed per driver line (#17); REQ-NVSMI-005 is therefore only partly met. GPU names come from a second extend entry, because a product name is free text that can contain the CSV separator. [docs/metrics.md](metrics.md) is generated from the model and is the field reference. +Milestone 3 names the throttle indicators `thr_*` (for example `thr_sw_power_cap`, `thr_hw_slowdown`) so every data source name fits Cacti's 19-character limit, and reads the mask as hex or decimal. The NVIDIA backend reads the mask through the new query name `clocks_event_reasons.active` and, when nvidia-smi refuses it with status 2, through an optional second entry asking for the old name `clocks_throttle_reasons.active` in the same position; both decode the same way (REQ-NVSMI-005, #36). Which driver releases know which name is still not confirmed (#17). GPU names come from a second extend entry, because a product name is free text that can contain the CSV separator. [docs/metrics.md](metrics.md) is generated from the model and is the field reference. Rules: @@ -287,11 +287,13 @@ The active reasons are a bitmask. The plugin decodes it into one indicator per r ECC and retired-page values are numbers the GPU reports. XID is different: the kernel log carries each event, and DCGM carries one number per GPU described as the last XID. The plugin therefore does not present the XID field as an error count. DCGM source shows each XID event is appended as a sample, so only a reader that asks for samples since a cursor can count repeats; a latest-value read cannot ([research/xid.md](research/xid.md)). Decision #8 picks the source; clearing behavior and kernel log access are *live*. If a kernel log reader is chosen, it is read-only, limited to lines matching the XID pattern, and bounded in size and age. No error value triggers a reset, drain, or retirement action. +As built in milestone 4 ([metrics.md](metrics.md)): the volatile ECC totals, retired single-bit and double-bit page counts, the pending flag, and the ECC mode are collected. New corrected and uncorrected errors are computed by the plugin from two consecutive totals of the same GPU and stored as gauges, unknown for a first sample, a missed read, or a fall in the total (a driver reload). XID is not collected: the fixed `nvidia-smi --query-gpu` commands of ADR 0008 offer no XID field, so it waits on #8. + ## Measurement state | Dimension | States | Evidence | |---|---|---| -| Freshness | Current, delayed, stale, never observed | Observation time against the expected interval | +| Freshness | Current, delayed, stale, never observed, ahead of Cacti's clock | Observation time against the expected interval | | Execution | Completed, tool error, permission denied, timed out, unknown | Exit status, timeout, and output validation | | GPU presence | Present, absent; possible replacement is a separate flag, since a replacement card is itself present (M2) | Inventory records | | Maintenance | In maintenance, not in maintenance | Maint's `plugin_maint_check_cacti_host()` for the node's device (guarded call; the `is_device_in_maintenance` hook has no caller in core) | @@ -308,6 +310,9 @@ Stated limits: - **Alignment.** Cacti's poll interval and the collection interval are independent, so a value can be reported twice or skipped. Thold durations should be at least one collection interval. - **Unknown values.** `U` never breaches a threshold; `age` is how a stopped collector alerts. - **Counters.** Volatile ECC totals reset at driver load, so a threshold on the total can clear after a reboot without the cause being resolved. +- **Gauges only.** Thold 1.8.2 throws a `TypeError` when a thresholded DERIVE or COUNTER data source reads `U`, and Cacti then disables Thold. Every GPU data source item is therefore a GAUGE, and the plugin computes ECC deltas itself. + +As built in milestone 4 ([alerting.md](alerting.md)): `templates/gpu_thold_templates.xml` holds nine Thold templates (temperature, power against its limit, four throttle indicators, new uncorrected ECC errors, pending retirement, and `age`) that an operator imports and links to the GPU Node device template. An end-to-end test drives unchanged Thold 1.8.2 and Maint 1.3 through firing, restoring, an ECC reset, a failed collection, and a Maint window. Alternatives considered: @@ -363,7 +368,7 @@ Plugin code is object-oriented wherever Cacti's plugin contract allows it. Cacti Plugin tables hold node mappings, GPU records, the observation cache, and health. They are created and upgraded with Cacti's tracked plugin table API, and the stored plugin version changes only after a migration succeeds. The collector runs from `poller_bottom` through `exec_background()` as one `register_process_start()` process per poller, with a time budget. Runs are idempotent. -Disabling the plugin stops jobs and leaves devices, graphs, and RRD files untouched. Uninstalling offers an export, then asks separately whether to drop plugin tables and whether to remove plugin-created Cacti objects. Cacti 1.2 gives a plugin no prompt during uninstall, so as built in M2 the questions are settings answered before uninstalling: *Keep Plugin Tables on Uninstall* (default on), with the export on the GPU Nodes page. If the tables are to be kept but cannot be untracked from Cacti's plugin table list, the uninstall stops with an error and the plugin stays installed, because Cacti ignores the uninstall function's return value and would otherwise drop them (accepted by the owner on 2026-11-15). M2 creates no Cacti objects, so the second question arrives with the milestone that creates them. The plugin never changes anything on a GPU node. Backup documentation covers the Cacti database and the RRD directory. A restore must not attach an RRD file to a different UUID, which is a release test. +Disabling the plugin stops jobs and leaves devices, graphs, and RRD files untouched. Uninstalling offers an export, then asks separately whether to drop plugin tables and whether to remove plugin-created Cacti objects. Cacti 1.2 gives a plugin no prompt during uninstall, so as built in M2 the questions are settings answered before uninstalling: *Keep Plugin Tables on Uninstall* (default on), with the export on the GPU Nodes page. If the tables are to be kept but cannot be untracked from Cacti's plugin table list, the uninstall stops with an error and the plugin stays installed, because Cacti ignores the uninstall function's return value and would otherwise drop them (accepted by the owner on 2026-11-15). M2 creates no Cacti objects, so the second question arrives with the milestone that creates them. As built in milestone 4, it is the setting *Remove the plugin's Cacti objects on uninstall*, default off (#30). The plugin never changes anything on a GPU node. Backup documentation covers the Cacti database and the RRD directory. A restore must not attach an RRD file to a different UUID, which is a release test. ## Performance @@ -412,7 +417,7 @@ Phase 2 needs a security review of the DCGM and amd-smi invocation paths and any - **Alerting.** Thold fires and recovers on fixture throttle, ECC, and staleness; Maint suppresses it. - **Remote.** Collector offline, recovery mode, replication after reconnect. - **Failure scenarios before each phase release:** tool missing, timeout, permission denied, driver unloaded, GPU lost mid-collection, node unreachable, clock skew, full disk, interrupted collector, duplicate collector start, interrupted upgrade. -- **Harness.** Use the harness maintained Cacti plugins use, and confirm with maintainers before adding test or CI infrastructure (#12). M2 adopts it provisionally: Pest from the locked plugin harness in Cacti's `tests/tools/plugin-harness`, as maintained plugins run it, until #12 is decided. Identity fixtures in M2 are synthetic sequences, not captured tool output; captured fixtures arrive with the first backend. Milestone 3's `nvidia-smi` fixtures are also synthetic, written to the documented field order; captured output (#14) must replace them before a release. Its end-to-end test runs a real net-snmp `snmpd` with the documented extend lines and a fake `nvidia-smi`, and Cacti's own poller writes the RRD files. +- **Harness.** Use the harness maintained Cacti plugins use, and confirm with maintainers before adding test or CI infrastructure (#12). M2 adopts it provisionally: Pest from the locked plugin harness in Cacti's `tests/tools/plugin-harness`, as maintained plugins run it, until #12 is decided. Identity fixtures in M2 are synthetic sequences, not captured tool output; captured fixtures arrive with the first backend. Milestone 3's `nvidia-smi` fixtures are also synthetic, written to the documented field order; captured output (#14) must replace them before a release. Its end-to-end test runs a real net-snmp `snmpd` with the documented extend lines and a fake `nvidia-smi`, and Cacti's own poller writes the RRD files. Milestone 4 adds, on the same harness: the alert test, a failure test (agent down, wrong SNMPv3 credentials, tool missing, permission denied, driver unloaded, timeout, cut and overlong output, clock skew, duplicate collector start, database loss mid-run, and an RRD file Cacti cannot write), a backup and restore test with `mysqldump`, and a scale test. Interrupted upgrades are covered by the lifecycle tests and lost GPUs by the identity sequences; a full disk is approximated by the unwritable RRD file. ## Milestones @@ -438,6 +443,8 @@ Milestone size estimates (ranges from measured reference plugins, no durations) | Repository home and name (#11) | `Cacti/plugin_gpu` (proposed); community plugin | Before code is published | Cacti maintainers | | Test harness (#12) | Whatever maintained plugins use | Milestone 2 | Cacti maintainers | | MIG representation (#13) | Indexes, separate data query, parent only | Milestone 6 | #20 | +| Nodes on deleted devices | Decided for milestone 4: a GPU Admin may disable or delete a node whose device no longer exists, since no device permission can apply to it; such nodes are left out of the export (`NodeAccess`) | Milestone 4 | Owner | +| A created device its creator cannot see | Decided for milestone 4: the device is removed again through `api_device_remove()` in the same request and an error is shown, so no node points at a device its creator cannot manage (`gpu_nodes.php`) | Milestone 4 | Owner | ## Risks diff --git a/docs/alerting.md b/docs/alerting.md new file mode 100644 index 0000000..698b737 --- /dev/null +++ b/docs/alerting.md @@ -0,0 +1,54 @@ +# Alerting with Thold and Maint + +The plugin has no alert engine and sends no notification of its own (REQ-ALERT-005, [ADR 0002](decisions/0002-alert-through-cacti-data-sources.md)). Every GPU value is an item of the GPU data source, so Thold alerts on it like any other Cacti data source, and Maint suppresses those alerts for a node's device. Neither plugin is changed. + +Tested against Thold v1.8.2 (`1eb406bd0f81f3204358cce7bd43c8bb5adc8e4a`) and Maint v1.3 (`cd62de9cc323a4f5a8ac80a8d9dda3c7fa16c470`), installed unchanged, on Cacti 1.2.31 and current 1.2.x (`tests/bin/alert-flow.php`, run in CI). + +## Set up the shipped thresholds + +1. Install and enable Thold, and Maint if you use maintenance windows. +2. In **Management > Threshold Templates**, choose **Import** and import `plugins/gpu/templates/gpu_thold_templates.xml`. +3. In **Templates > Device Templates > GPU Node**, add each *GPU - ...* threshold template under *Associated Threshold Templates*. +4. Turn on Thold's *Auto Create Thresholds* setting, so Thold creates the thresholds as the plugin creates each GPU's graphs. This is the path the end-to-end test takes. +5. Devices that already had the GPU Node template before step 3 are not linked yet: add the templates under *Associated Threshold Templates* on each device's page, then select the devices under **Management > Devices** and run the **Apply Thresholds** action. + +Thold creates one threshold per template for each GPU's data source. Notification lists, emails, and repeat settings are Thold's; set them on the templates or the thresholds. + +## Shipped templates + +| Template | Item | Breaches when | After | +|---|---|---|---| +| GPU - Temperature High | `temp_gpu` | above 85 °C | 2 polls | +| GPU - Power Above Limit | `power` | above 100 percent of `power_limit` | 2 polls | +| GPU - Software Thermal Slowdown | `thr_sw_thermal` | 1 | 1 poll | +| GPU - Hardware Thermal Slowdown | `thr_hw_thermal` | 1 | 1 poll | +| GPU - Hardware Power Brake | `thr_hw_power_brake` | 1 | 1 poll | +| GPU - Hardware Slowdown | `thr_hw_slowdown` | 1 | 1 poll | +| GPU - New Uncorrected ECC Errors | `ecc_uncorr_new` | any new error since the previous sample | 1 poll | +| GPU - Page Retirement Pending | `retired_pending` | 1 | 1 poll | +| GPU - Sample Too Old | `age` | above 900 seconds | 1 poll | + +The values are starting points, not vendor limits; adjust them per GPU model. Not templated, on purpose: + +- **Software power cap** (`thr_sw_power_cap`): a GPU under full load is normally held there. +- **Idle and the other mask bits** without an indicator: Idle is normal, and the nvidia-smi documentation marks it and Application Clocks Setting deprecated (REQ-THR-002). +- **The volatile ECC totals** (`ecc_corr`, `ecc_uncorr`): they fall to 0 at driver load, so a threshold on them clears after a reboot without the cause being fixed. Alert on `ecc_uncorr_new` instead. +- **New corrected ECC errors**: occasional corrected errors are normal and no default rate is known; add a threshold if your fleet has one. + +The template list is generated from `lib/TholdTemplateXml.php`, and a unit test fails if the shipped file differs. + +## Rules for GPU thresholds + +- **Durations.** Set each fail trigger to at least one collection interval (REQ-ALERT-004). A trigger counts Cacti polls, and the plugin collects each node once per poller cycle, so one poll is one interval. Cacti's poll and the collection are not aligned: a value can be read twice or skipped, so a single-poll trigger can fire on one sample, and a fault shorter than the interval is not seen. +- **Unknown values.** `U` never breaches a threshold (REQ-ALERT-002): a GPU without ECC, a failed collection, or a stale sample reads `U`, and Thold does not alert on it. It does not hold an alert either: Thold 1.8.2 takes a value that is not a number as not breached, so a threshold in alert restores, and sends its restoration notice, when its value turns `U`. A restoration while the GPU's values are unknown therefore means the plugin lost the value, not that the fault cleared; `age` shows which, because it stays numeric whenever a sample exists and keeps growing, and the *GPU - Sample Too Old* threshold alerts on it. +- **Gauges only.** Every data source item is a GAUGE. Thold 1.8.2 throws a PHP `TypeError` when a thresholded DERIVE or COUNTER data source reads `U`, and Cacti then disables Thold for everyone. So the plugin computes the new ECC errors itself, from two consecutive samples of the same GPU, and stores the result as a gauge: unknown for a first sample, after a missed read, and after a reset. Do not change a GPU data source item to COUNTER or DERIVE. +- **Maintenance.** A Maint schedule on the node's device suppresses its GPU thresholds (REQ-ALERT-003): Thold neither counts nor notifies a breach while the device is in maintenance, and the RRD files still record the values. The GPU Health page shows whether Maint holds each node. + +## What the end-to-end test proves + +`tests/bin/alert-flow.php` imports the shipped templates with Thold's own import, links them to the GPU Node template, and lets Thold create the thresholds when the plugin creates the graphs. It then changes the fake `nvidia-smi` output behind a real `snmpd`, collects over SNMPv3, runs Cacti's poller and Thold's check, and reads Thold's log: + +- a hot, hardware-throttled GPU with new uncorrected errors and a pending page retirement fires each threshold, the temperature only on its second poll, and each restores when the value returns; +- a driver reload drops the ECC total to 0: the new-error value reads `U`, nothing breaches, and Thold stays enabled; two new errors after the reset fire the threshold again, and it restores; +- a failing tool makes every other value `U`, which breaches nothing and restores a hardware slowdown threshold that was in alert, while `age` alerts and restores once samples return; +- under a Maint schedule a breach is neither counted nor notified while the RRD file records it; after the schedule ends it counts and notifies again. diff --git a/docs/backup.md b/docs/backup.md new file mode 100644 index 0000000..4ae8635 --- /dev/null +++ b/docs/backup.md @@ -0,0 +1,38 @@ +# Backup and restore + +GPU history lives in two places that must be backed up together: the records that say which GPU a data source belongs to, in the database, and the history itself, in the RRD files (REQ-BACKUP-001). + +## What to back up + +| What | Where | Why | +|---|---|---| +| The Cacti database, whole | Including every `plugin_gpu_*` table and the `settings` rows named `gpu_*` | Nodes, GPU records keyed by UUID, the latest samples, and the data sources, graphs, and data query cache that tie each GPU to its RRD file | +| The RRD directory | `/rra` by default | The history | +| The plugin settings | The `gpu_*` rows of Cacti's `settings` table, inside the database dump | *Mark Absent After*, *Stale After*, *Keep Plugin Tables on Uninstall*, and the schema version | +| Each node's `snmpd.conf` extend lines | On the node | Not Cacti's to restore; copy them from [node-setup.md](node-setup.md) | + +Take the database dump and the RRD copy at the same time, with Cacti's poller stopped or between cycles, so neither is newer than the other. A consistent dump of a running database: + +``` +mysqldump --single-transaction --routines cacti > cacti.sql +``` + +## Restore + +1. Stop Cacti's poller (its cron entry or service). +2. Restore the database: `mysql cacti < cacti.sql`. +3. Restore the RRD directory from the same backup. +4. Start the poller. The plugin's next collection checks every GPU against its records by UUID, so a GPU keeps its data source and RRD file and its values continue in them. + +## A database older than the RRD directory + +If only the database is restored, or the dump is older than the RRD files, Cacti hands out the data source ids it had at the time of the dump again, and Cacti names RRD files after the data source id. A GPU that first appears after the restore could then get a data source whose file name belongs to a file already on disk, with another GPU's history in it. + +The plugin prevents that (REQ-BACKUP-003): when it creates a data source for a GPU and an RRD file already exists at that data source's path, it renames the file with the suffix `.gpu-orphan-