Merge branch 'support/v4.4.x'

This commit is contained in:
nicolargo 2025-11-03 14:44:57 +01:00
commit de6fae584e
8 changed files with 106 additions and 12 deletions

1
.gitignore vendored
View File

@ -69,3 +69,4 @@ uv.lock
# Test
.coverage
tests-data/issues/*/config/

View File

@ -11,7 +11,6 @@
import os
import socket
import sys
import tempfile
import webbrowser
from typing import Annotated, Any, Union
from urllib.parse import urljoin
@ -47,7 +46,6 @@ try:
except ImportError:
logger.critical('Uvicorn import error. Glances cannot start in web server mode.')
sys.exit(2)
import builtins
import contextlib
import threading
import time
@ -469,13 +467,6 @@ class GlancesRestfulApi:
HTTP/400 if plugin is not found
HTTP/404 if others error
"""
if self.args.debug:
fname = os.path.join(tempfile.gettempdir(), 'glances-debug.json')
try:
with builtins.open(fname) as f:
return f.read()
except OSError:
logger.debug(f"Debug file ({fname}) not found")
# Update the stat
self.__update_stats()

View File

@ -268,7 +268,7 @@ please rename it to "{plugin_path.capitalize()}Plugin"'
# It's a weak cache to avoid updating the same plugin too often
# Note: the function always return None
@weak_lru_cache(maxsize=128, ttl=1)
@weak_lru_cache(ttl=1)
def update_plugin(self, p):
"""Update stats, history and views for the given plugin name p"""
self._plugins[p].update()

View File

@ -0,0 +1,52 @@
Pre-requisites:
- Docker needs to be installed on your system
- https://gethomepage.dev/installation/docker/
Start Docker:
cd ./tests-data/issues/issue3322-homepage/
sh ./run-homepage.sh
Access to the interface:
firefox http://localhost:3000/
Edit the ./config/widgets.yaml file and add (replace 192.168.1.26 by your local IP @):
- glances:
url: http://192.168.1.26:61208
# username: user # optional if auth enabled in Glances
# password: pass # optional if auth enabled in Glances
version: 4 # required only if running glances v4 or higher, defaults to 3
cpu: true # optional, enabled by default, disable by setting to false
mem: true # optional, enabled by default, disable by setting to false
cputemp: true # disabled by default
uptime: true # disabled by default
disk: / # disabled by default, use mount point of disk(s) in glances. Can also be a list (see below)
diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk
expanded: true # show the expanded view
label: MyMachine # optional
And the ./config/services.yaml (replace 192.168.1.26 by your local IP @):
- Glances:
- CPU Usage:
widget:
type: glances
url: http://192.168.1.26:61208
version: 4 # required only if running glances v4 or higher, defaults to 3
metric: cpu
- MEM Usage:
widget:
type: glances
url: http://192.168.1.26:61208
version: 4 # required only if running glances v4 or higher, defaults to 3
metric: memory
- Network Usage:
widget:
type: glances
url: http://192.168.1.26:61208
version: 4 # required only if running glances v4 or higher, defaults to 3
metric: network:wlp0s20f3

View File

@ -0,0 +1,7 @@
docker run --rm \
--name homepage \
-p 3000:3000 \
-e HOMEPAGE_ALLOWED_HOSTS=localhost:3000,0.0.0.0:3000 \
-v ./config:/app/config \
-v /var/run/docker.sock:/var/run/docker.sock \
ghcr.io/gethomepage/homepage:latest

View File

@ -0,0 +1,18 @@
Pre-requisites:
- Docker needs to be installed on your system
- https://www.home-assistant.io/installation/linux/#install-home-assistant-container
Start Docker:
cd ./tests-data/issues/issue3333-homeassistant/
sh ./run-homeassistant.sh
Access to the interface:
firefox http://localhost:8123/
And install the Glances plugin.
Parameters / Services / + Add / Glances
Stats will be refreshed every 5 minutes.

View File

@ -0,0 +1,9 @@
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=Europe/Paris \
-v ./config:/config \
-v /run/dbus:/run/dbus:ro \
--network=host \
ghcr.io/home-assistant/home-assistant:stable

View File

@ -16,9 +16,25 @@ def test_perf_update(glances_stats):
"""
Test Glances perf.
"""
perf_timer = Timer(6)
test_duration = 12 # seconds
perf_timer = Timer(test_duration)
counter = 0
from_cache = 0
from_update = 0
previous_interrupts_gauge = None
while not perf_timer.finished():
glances_stats.update()
# interrupts_gauge should always increase
interrupts_gauge = glances_stats.get_plugin('cpu').get_raw().get('interrupts_gauge')
if interrupts_gauge is not None:
if interrupts_gauge == previous_interrupts_gauge:
from_cache += 1
else:
from_update += 1
previous_interrupts_gauge = interrupts_gauge
counter += 1
assert counter > 6
print(f"{counter} iterations. From cache: {from_cache} | From update: {from_update}")
assert counter > test_duration
assert from_update < from_cache
assert from_cache >= test_duration * 10
assert from_update >= (test_duration / 2) - 1