Skip to content

prometheus-node-exporter-lua: expose node_os_info#29247

Open
evgeni wants to merge 1 commit intoopenwrt:masterfrom
evgeni:prom-lua-os-info
Open

prometheus-node-exporter-lua: expose node_os_info#29247
evgeni wants to merge 1 commit intoopenwrt:masterfrom
evgeni:prom-lua-os-info

Conversation

@evgeni
Copy link
Copy Markdown

@evgeni evgeni commented Apr 26, 2026

📦 Package Details

Maintainer: @champtar

Description:
the original node_exporter exposes a node_os_info metric with a set of data about the system [1] which is then used by several dashboards.

openwrt.lua already exposes OS info, but using the node_openwrt_info metric requires changes to existing dashboards, and would require more complex lookups when there are non-OpenWrt hosts in the overview too.

as we've already called ubus and fetched the data, we can expose it in two formats easily.

[1] https://github.com/prometheus/node_exporter/blob/d6d0e710bb7daf07a2743fde060f0d5f32c565f3/collector/os_release.go#L190-L192


🧪 Run Testing Details

  • OpenWrt Version: 25.12.2
  • OpenWrt Target/Subtarget: bcm27xx/bcm2711
  • OpenWrt Device: Raspberry Pi Compute Module 4 Rev 1.0

But should work everywhere else too, that's just the env I tested the change in :)


✅ Formalities

  • I have reviewed the CONTRIBUTING.md file for detailed contributing guidelines.

If your PR contains a patch:

  • It can be applied using git am
  • It has been refreshed to avoid offsets, fuzzes, etc., using
    make package/<your-package>/refresh V=s
  • It is structured in a way that it is potentially upstreamable
    (e.g., subject line, commit description, etc.)
    We must try to upstream patches to reduce maintenance burden.

the original node_exporter exposes a node_os_info metric with a set of
data about the system [1] which is then used by several dashboards.

openwrt.lua already exposes OS info, but using the node_openwrt_info
metric requires changes to existing dashboards, and would require more
complex lookups when there are non-OpenWrt hosts in the overview too.

as we've already called ubus and fetched the data, we can expose it in
two formats easily.

[1] https://github.com/prometheus/node_exporter/blob/d6d0e710bb7daf07a2743fde060f0d5f32c565f3/collector/os_release.go#L190-L192

Signed-off-by: Evgeni Golov <evgeni@golov.de>
@evgeni evgeni force-pushed the prom-lua-os-info branch from 9b376dd to 9336c9d Compare April 26, 2026 13:47
target = b.release.target
}

local os_info = {
Copy link
Copy Markdown
Author

@evgeni evgeni Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original node exporter also has the following fields: id_like, image_id, image_version, variant, variant_id version_codename, but as they are not part of the system board call, I skipped them here (only id_like is present in OpenWrts /etc/os-release).

the og exporter reports

node_os_info{build_id="r32802-f505120278",id="openwrt",id_like="lede openwrt",image_id="",image_version="",name="OpenWrt",pretty_name="OpenWrt 25.12.2",variant="",variant_id="",version="25.12.2",version_codename="",version_id="25.12.2"} 1

on my system, while the code here does

node_os_info{pretty_name="OpenWrt 25.12.2",name="OpenWrt",build_id="r32802-f505120278",id="openwrt",version_id="25.12.2",version="25.12.2"} 1

@BKPepe BKPepe requested a review from Copilot April 28, 2026 06:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Expose OpenWrt OS release metadata via the standard node_os_info metric (in addition to the existing node_openwrt_info) to keep compatibility with existing Prometheus dashboards that expect node_exporter’s metric names/labels.

Changes:

  • Add an os_info label-set derived from OpenWrt release data.
  • Emit a new node_os_info gauge metric alongside node_openwrt_info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +15 to +22
local os_info = {
id = string.lower(b.release.distribution),
name = b.release.distribution,
pretty_name = b.release.distribution .. " " .. b.release.version,
version = b.release.version,
version_id = b.release.version,
build_id = b.release.revision,
}
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os_info is built at module load time and dereferences b.release.*. In this diff, b is declared later (and initialized to nil), which makes this table construction prone to failing with attempt to index a nil value during require()/module load. Construct os_info only after the ubus/os-release data has been fetched (e.g., inside scrape() right before emitting the metric, or in whatever init path populates b) so the collector won’t fail to load.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe read the whole file?


local function scrape()
metric("node_openwrt_info", "gauge", labels, 1)
metric("node_os_info", "gauge", os_info, 1)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For maximum drop-in compatibility with node_exporter dashboards, node_os_info should expose the same label set as node_exporter’s node_os_info (node_exporter includes additional labels such as id_like, variant, variant_id, version_codename, etc.). Consider adding the missing label keys (using empty strings when OpenWrt doesn’t provide a value) so queries and label-based joins don’t break or require special-casing.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants