Skip to content

fix(connections): alert on the tracked percentage, not on 0 - #3683

Merged
nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/connections-conntrack-alert
Aug 26, 2026
Merged

nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/connections-conntrack-alert

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

connections/__init__.py builds the conntrack decoration like this:

self.views['nf_conntrack_percent']['decoration'] = self.get_alert(header='nf_conntrack_percent')

No value is passed, so get_alert uses its own default — current=0 — and computes value = 0 * 100 / 100. Zero is below every threshold, so the result is OK on every refresh regardless of how full the table is.

The thresholds are real and documented. conf/glances.conf ships them:

# nf_conntrack thresholds in %
nf_conntrack_percent_careful=70
nf_conntrack_percent_warning=80
nf_conntrack_percent_critical=90

and docs/aoa/connections.rst documents the same three. None of them could ever fire.

That matters more than a missing colour: once nf_conntrack_count reaches nf_conntrack_max the kernel starts dropping new connections, which is precisely the condition a critical=90 threshold is there to warn about before it happens. nf_conntrack_percent is already computed correctly in update_for_nf_conntrack_method, so the number on screen was right the whole time — only its colour was decided from 0.

Both interfaces read this one decoration — the WebUI through getDecoration('nf_conntrack_percent') in plugin-connections.vue — so both were silent, and both are fixed by the one change.

Tests

Added to tests/test_connections_states.py, reusing that file's plugin fixture. update_views runs over injected stats and the decoration is read back:

  • 95% → CRITICAL, 85% → WARNING, 75% → CAREFUL
  • 10% → OK

The limits are set on the fixture to the values conf/glances.conf ships, since the fixture builds the plugin with config=None.

Mutation-checked — restoring get_alert(header='nf_conntrack_percent') fails exactly one test, on the first assertion:

- CRITICAL
+ OK
1 failed, 5 passed

The 10% → OK case deliberately does not catch that mutation: it pins the low end, which reads OK either way. It is there so a future change cannot fix the high end by colouring everything.

python -m pytest tests/test_connections_states.py -q
6 passed

No WebUI rebuild is needed — the change is Python only, and the bundle already reads the decoration the plugin publishes.

update_views called get_alert(header='nf_conntrack_percent') without a value,
so it measured get_alert's default current=0 on every refresh. The tracked
connection percentage was drawn OK at any fill level, and the thresholds
conf/glances.conf ships for it -- careful 70, warning 80, critical 90 -- could
never fire. A conntrack table close to nf_conntrack_max drops new connections,
which is exactly what those thresholds exist to warn about.

Both interfaces read this one decoration (the WebUI through
getDecoration('nf_conntrack_percent')), so both were silent.
@nicolargo
nicolargo merged commit 5a38e15 into nicolargo:develop Aug 26, 2026
17 of 19 checks passed
@nicolargo nicolargo added this to the Glances 4.5.7 milestone Aug 26, 2026
@nicolargo

Copy link
Copy Markdown
Owner

Thanks for the PR @ntdatt812

Merged into develop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants