nicolargo / glances

Glances an Eye on your system. A top/htop alternative for GNU/Linux, BSD, Mac OS and Windows operating systems.
http://nicolargo.github.io/glances/
Other
26.56k stars 1.52k forks source link

Disable UI if an error occurs and if an export module is enabled #2589

Closed matthabjan closed 6 months ago

matthabjan commented 11 months ago

I am running glances (either dev, but I have also tried latest-full) in docker mode on a Raspberry Pi4 (Debian 11 as OS). I use it to export glances output into InfluxDB2, also running in the same docker stack.

Glances is running and keeps exporting data. However, when the containers are running I get the following "error" messages on every refresh:

Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/app/glances/main.py", line 18, in glances.main() File "/app/glances/init.py", line 183, in main start(config=core.get_config(), args=core.get_args()) File "/app/glances/init.py", line 106, in start mode = GlancesMode(config=config, args=args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/glances/standalone.py", line 106, in init self.screen = GlancesCursesStandalone(config=config, args=args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/glances/outputs/glances_curses.py", line 142, in init self.screen = curses.initscr() ^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/curses/init.py", line 29, in initscr setupterm(term=_os.environ.get("TERM", "unknown"), _curses.error: setupterm: could not find terminal

I am using the following docker compose file:

---
version: "3.5"
services:
  influxdb2:
    image: influxdb:latest
    container_name: influxdb2
    restart: unless-stopped
    networks:
      - gig-net
    volumes:
      - /var/lib/docker/volumes/influxdb2/data:/var/lib/influxdb2
      - /var/lib/docker/volumes/influxdb2/config:/etc/influxdb2
    ports:
      - "8086:8086"

  glances:
    image: nicolargo/glances:dev
    container_name: glances
    pid: host
    network_mode: host
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/lib/docker/glances/glances.conf:/etc/glances.conf
    environment:
      - GLANCES_OPT=--export influxdb2
      - TZ=Europe/Berlin
    restart: unless-stopped

networks:
  gig-net:
    name: gig-net
    driver: bridge

My glances.conf file looks like this:

[global]
refresh=10
check_update=false
history_size=1200

[influxdb2]
host=localhost
port=8086
protocol=http
org=[MYORG]
bucket=[MYBUCKET]
token=[SECRET TOKEN]
interval=20

This error message can be muted by adding "--quiet" to GLANCES_OPT in the docker-compose file, but not sure if this is the expected behavior? Especially since I am seeing considerable spiking of the CPU load on every refresh.

nicolargo commented 11 months ago

Hi @matthabjan

depending of what you want to do..

If you want to display the Glances curses interface from your docker-compose, please add the following option to the Glances Docker service:

   stdin_open: true 
   tty: true

But if you only want to export stats to InfluxDB, just use the --quiet option.

In future version (Glances 4), the exception will be catched and Glances will start the export even if a terminal is not found.

nicolargo commented 11 months ago

Done on the develop branch.

matthabjan commented 11 months ago

I have just tested with your new dev release (4.0.0.0_beta01). I think it now works as expected. My docker file (without the --quiet flag):

version: "3.5"
services:
  glances:
    image: nicolargo/glances:dev
    container_name: glances
    pid: host
    network_mode: host
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/lib/docker/glances/glances.conf:/etc/glances.conf
    environment:
      - GLANCES_OPT=--export influxdb2
      - TZ=Europe/Berlin
    restart: unless-stopped

The ouput of my glances docker log:

2023-10-29 13:25:06,774 -- INFO -- Start Glances 4.0.0_beta01
2023-10-29 13:25:06,775 -- INFO -- CPython 3.11.6 (/venv/bin/python3) and psutil 5.9.6 detected
2023-10-29 13:25:06,785 -- INFO -- Read configuration file '/etc/glances.conf'
2023-10-29 13:25:06,934 -- INFO -- Start GlancesStandalone mode
2023-10-29 13:25:07,854 -- ERROR -- containers (Podman) plugin - Can't connect to Podman (http://%2Frun%2Fuser%2F1000%2Fpodman%2Fpodman.sock/v4.7.0/libpod/_ping (HEAD operation failed))
2023-10-29 13:25:09,580 -- INFO -- Connected to InfluxDB server version v2.7.3 (ready for queries and writes)
2023-10-29 13:25:10,894 -- INFO -- Cannot init the curses library, quiet mode on and export.

That's fantastic. Thank you for the quick solution!