Skip to content

fix(webui): match the AMP alert to the plugin's get_alert - #3696

Merged
nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/webui-amps-alert
Aug 29, 2026
Merged

nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/webui-amps-alert

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

plugin-amps.vue computes its own decoration instead of reading the server's. It disagrees with AmpsPlugin.get_alert(), which is the authority — the TUI calls it directly at amps/__init__.py:114 with the same three fields the component reads (count, countmin, countmax).

1. Out-of-range count is WARNING, not CAREFUL

} else {
    decoration = "careful";   // plugin returns 'WARNING'
}

These are different levels with different colours in style.scss:

class colour
.careful #295183 (blue)
.warning #5D4062 (purple)

So an AMP outside its configured bounds is under-reported in the WebUI relative to the TUI — the same monitor shows one severity in glances and a milder one in the browser.

2. countmin=0 with a count of 0 rendered critical

decoration = countMin === null ? "ok" : "critical";

The plugin defaults an unset bound to the observed count and then:

if int(countmin) == 0:
    return 'OK'
return 'CRITICAL'

So a configured minimum of 0 means zero processes is fine. That is a value the plugin supports deliberately — the int(countmin) == 0 branch exists for it — and conf/glances.conf documents countmin as optional. The WebUI flagged it red instead.

What did not change

The range check already matched. It is rewritten to default the bounds the way the plugin does rather than short-circuiting on null, so the two now read alike, but the behaviour for count > 0 with either bound unset is identical.

Deliberately not mirrored: the plugin's if nbprocess is None: return 'OK' guard. count is initialised to 0 in glances/amps/amp.py and only ever assigned a real count, so that branch is unreachable from the API — porting it would be dead code. Say the word if you would rather have it for symmetry.

Evidence

The WebUI has no JS test runner, so the proof is the rebuilt bundle: careful occurrences drop 18 → 17, and glances.js goes 686883 → 686922 bytes with only the component and the bundle changed.

npx eslint on the component: 0 errors. The two warnings (vue/require-default-prop, vue/no-v-html) are on untouched code and predate this change.

`plugin-amps.vue` disagreed with `AmpsPlugin.get_alert()`, which is the
authority — the TUI calls it directly at `amps/__init__.py:114`.

Two divergences:

1. An out-of-range process count rendered "careful"; the plugin returns
   WARNING. Those are different levels with different colours in style.scss
   (`.careful` #295183, `.warning` #5D4062), so an AMP outside its configured
   bounds was under-reported in the WebUI relative to the TUI.

2. With a count of 0 the WebUI returned "critical" for any non-null
   `countmin`, including `countmin=0`. The plugin defaults an unset bound to
   the observed count and then returns OK when `int(countmin) == 0`, so a
   configured minimum of zero means zero processes is fine. The plugin
   supports that value explicitly; the WebUI flagged it red.

The range check itself already matched and is unchanged in behaviour — it is
only rewritten to default the bounds the way the plugin does, rather than
short-circuiting on null, so the two read alike.

Not mirrored: the plugin's `nbprocess is None -> OK` guard. `count` is
initialised to 0 in `amps/amp.py` and only ever assigned a real count, so that
branch is unreachable from the API and adding it would be dead code.

Evidence, since the WebUI has no JS test runner: in the rebuilt bundle the
`careful` occurrences drop 18 -> 17. `npx eslint` on the component reports
0 errors (the two warnings, `vue/require-default-prop` and `vue/no-v-html`,
are on untouched code and predate this change).
@ntdatt812

Copy link
Copy Markdown
Contributor Author

Reworked per your note on #3699: rebased onto current develop and dropped glances/outputs/static/public/glances.js, so this is now the single .vue source file and nothing generated. The source diff is byte-identical to the one you already saw, and the bundle was the only thing these branches conflicted on.

@nicolargo nicolargo added this to the Glances 4.5.7 milestone Aug 29, 2026
@nicolargo
nicolargo merged commit d17b078 into nicolargo:develop Aug 29, 2026
17 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants