Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when reading timezone for generating alert #2659

Closed
erincerys opened this issue Jan 15, 2024 · 2 comments · Fixed by #2742
Closed

Crash when reading timezone for generating alert #2659

erincerys opened this issue Jan 15, 2024 · 2 comments · Fixed by #2742
Labels
Milestone

Comments

@erincerys
Copy link

erincerys commented Jan 15, 2024

Describe the bug
Program throws a traceback and exits when attempting to generate a timestamp for an an event alert.

To Reproduce
Steps to reproduce the behavior:

  1. On an ArchLinux system, with glances installed from the glances-git AUR package, set the timezone to America/Los_Angeles with timedatectl
  2. Run glances, and wait for or create a condition that would cause an event alert, such as by using stress to consume >80% CPU

Expected behavior
Timezone is properly read to format the timestamp for the event alert.

Environment (please complete the following information)

  • Operating System (lsb_release -a or OS name/version): Arch Linux
  • Glances & psutil versions: Glances v4.0.0_beta01 with PsUtil v5.9.7
  • How do you install Glances (Pypi package, script, package manager, source): glances-git (3.4.0.r351.g36ed96b-1) from AUR
  • Glances test (only available with Glances 3.1.7 or higher):
===============================================================================
Glances 4.0.0_beta01 (/usr/lib/python3.11/site-packages/glances/__init__.py)
Python 3.11.6 (/usr/bin/python)
PsUtil 5.9.7 (/usr/lib/python3.11/site-packages/psutil/__init__.py)
===============================================================================
alert         [OK]    0.00001s
[]
amps          [OK]    0.05047s key=name
[{'count': 0,
 'countmax': None,
 'countmin': 1.0,
 'key': 'name',
 'name': 'Dropbox',
 'refresh': 3.0,
 'regex': True,
 'result': None,
 'timer': 2.3304715156555176}, ...]
cloud         [OK]    0.00002s
{}
connections   [NA]
containers    [OK]    0.00132s
[]
core          [OK]    0.00064s
{'log': 24, 'phys': 12}
cpu           [OK]    0.00022s
{'cpucore': 24,
'ctx_switches': 76886,
'guest': 0.0,
'guest_nice': 0.0,
'idle': 97.0,
'interrupts': 31429,
'iowait': 0.3,
'irq': 0.2,
'nice': 0.0,
'soft_interrupts': 8661,
'softirq': 0.1,
'steal': 0.0,
'syscalls': 0,
'system': 1.2,
'time_since_update': 2.1425039768218994,
'total': 5.6,
'user': 1.2}
diskio        [OK]    0.00064s key=disk_name
[{'alias': 'ssd3',
 'disk_name': 'sda',
 'key': 'disk_name',
 'read_bytes': 16384,
 'read_count': 4,
 'time_since_update': 2.0573959350585938,
 'write_bytes': 52736,
 'write_count': 18}, ...]
folders       [OK]    0.00002s key=path
[REDACTED]
fs            [OK]    0.00073s key=mnt_point
[{'device_name': '/dev/mapper/linux-root',
 'free': 5195567104,
 'fs_type': 'ext4',
 'key': 'mnt_point',
 'mnt_point': '/',
 'percent': 89.6,
 'size': 52521566208,
 'used': 44624867328}, ...]
gpu           [OK]    0.00001s
[]
help          [OK]    0.00000s
None
ip            [NA]
irq           [OK]    0.00104s key=irq_line
[{'irq_line': 'CAL', 'irq_rate': 15078, 'key': 'irq_line', 'time_since_update': 2.162673234939575}, ...]
load          [OK]    0.00002s
{'cpucore': 24, 'min1': 1.08154296875, 'min15': 0.958984375, 'min5': 0.8544921875}
mem           [OK]    0.00007s
{'active': 27866124288,
'available': 39517786112,
'buffers': 382300160,
'cached': 10602590208,
'free': 39517786112,
'inactive': 6151049216,
'percent': 41.3,
'shared': 800821248,
'total': 67340587008,
'used': 27822800896}
memswap       [OK]    0.00013s
{'free': 34359209984,
'percent': 0.0,
'sin': 0,
'sout': 0,
'time_since_update': 2.059211254119873,
'total': 34359734272,
'used': 524288}
network       [OK]    0.00074s key=interface_name
[{'alias': None,
 'cumulative_cx': 9738463519,
 'cumulative_rx': 8543148676,
 'cumulative_tx': 1195314843,
 'cx': 25078,
 'interface_name': 'enp8s0',
 'is_up': True,
 'key': 'interface_name',
 'rx': 7594,
 'speed': 1048576000,
 'time_since_update': 2.058318614959717,
 'tx': 17484}, ...]
now           [OK]    0.00001s
'2024-01-15 07:13:59 PST'
percpu        [OK]    0.00006s key=cpu_number
[{'cpu_number': 0,
 'guest': 0.0,
 'guest_nice': 0.0,
 'idle': 16.0,
 'iowait': 0.0,
 'irq': 0.0,
 'key': 'cpu_number',
 'nice': 0.0,
 'softirq': 0.0,
 'steal': 0.0,
 'system': 0.0,
 'total': 84.0,
 'user': 0.0}, ...]
ports         [OK]    0.00000s
[{'description': 'DefaultGateway',
 'host': '192.168.1.1',
 'indice': 'port_0',
 'port': 0,
 'refresh': 30,
 'rtt_warning': None,
 'status': 0.004357,
 'timeout': 3}]
processcount  [OK]    0.08436s
{'pid_max': 0, 'running': 2, 'sleeping': 370, 'thread': 3208, 'total': 583}
processlist   [OK]    0.00079s
[REDACTED]
psutilversion [OK]    0.00002s
(5, 9, 7)
quicklook     [OK]    0.00024s
{'cpu': 5.6,
'cpu_hz': 3800000000.0,
'cpu_hz_current': 3171024750.0,
'cpu_name': 'AMD Ryzen 9 3900X 12-Core Processor',
'mem': 41.3,
'percpu': [{...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...},
           {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}, {...}],
'swap': 0.0}
raid          [NA]
sensors       [OK]    0.00000s key=label
[{'critical': 84,
 'key': 'label',
 'label': 'Composite',
 'type': 'temperature_core',
 'unit': 'C',
 'value': 37,
 'warning': 84}, ...]
smart         [NA]
system        [OK]    0.00000s
{'hostname': '[REDACTED]',
'hr_name': 'Arch Linux 64bit',
'linux_distro': 'Arch Linux',
'os_name': 'Linux',
'os_version': '6.6.10-zen1-1-zen',
'platform': '64bit'}
uptime        [OK]    0.00010s
{'seconds': 68030}
wifi          [NA]
===============================================================================
Total time to update all stats: 0.18652s
===============================================================================

Additional context
Add any other context about the problem here.

$ systemctl status systemd-timedated
● systemd-timedated.service - Time & Date Service
     Loaded: loaded (/usr/lib/systemd/system/systemd-timedated.service; static)
     Active: active (running) since Mon 2024-01-15 07:21:48 PST; 18s ago
       Docs: man:systemd-timedated.service(8)
             man:localtime(5)
             man:org.freedesktop.timedate1(5)
   Main PID: 986223 (systemd-timedat)
      Tasks: 1 (limit: 77025)
     Memory: 1.2M (peak: 1.5M)
        CPU: 31ms
     CGroup: /system.slice/systemd-timedated.service
             └─986223 /usr/lib/systemd/systemd-timedated

$ timedatectl show
Timezone=America/Los_Angeles
LocalRTC=no
CanNTP=yes
NTP=yes
NTPSynchronized=yes
TimeUSec=Mon 2024-01-15 07:21:06 PST
RTCTimeUSec=Mon 2024-01-15 07:21:06 PST

$ ls -la /etc/localtime
lrwxrwxrwx 1 root root 41 May 14  2016 /etc/localtime -> ../usr/share/zoneinfo/America/Los_Angeles

$ timedatectl list-timezones | grep 'America/Los_Angeles'
America/Los_Angeles
Traceback (most recent call last):

File "/usr/bin/glances", line 8, in <module>
sys.exit(main())

File "/usr/lib/python3.11/site-packages/glances/__init__.py", line 183, in main
start(config=core.get_config(), args=core.get_args())

File "/usr/lib/python3.11/site-packages/glances/__init__.py", line 129, in start
mode.serve_forever()

File "/usr/lib/python3.11/site-packages/glances/standalone.py", line 180, in serve_forever
while self.__serve_once():

File "/usr/lib/python3.11/site-packages/glances/standalone.py", line 159, in __serve_once
ret = not self.screen.update(self.stats, duration=adapted_refresh)

File "/usr/lib/python3.11/site-packages/glances/outputs/glances_curses.py", line 1233, in update
self.flush(stats, cs_status=cs_status)

File "/usr/lib/python3.11/site-packages/glances/outputs/glances_curses.py", line 1215, in flush
self.display(stats, cs_status=cs_status)

File "/usr/lib/python3.11/site-packages/glances/outputs/glances_curses.py", line 684, in display
__stat_display = self.__get_stat_display(stats, layer=cs_status)

File "/usr/lib/python3.11/site-packages/glances/outputs/glances_curses.py", line 660, in __get_stat_display
ret[p] = stats.get_plugin(p).get_stats_display(args=self.args, max_width=plugin_max_width)

File "/usr/lib/python3.11/site-packages/glances/plugins/plugin/model.py", line 892, in get_stats_display
ret = {'display': display_curse, 'msgdict': self.msg_curse(args), 'align': align_curse}

File "/usr/lib/python3.11/site-packages/glances/plugins/alert/__init__.py", line217, in msg_curse
tz=pytz.timezone(tzname[0] if tzname[0] else 'UTC')))

File "/usr/lib/python3.11/site-packages/pytz/__init__.py", line 177, in timezone
raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'PST'
@nicolargo
Copy link
Owner

Hi @nicolargo

on your system can you enter (and copy/paste the result) of the following command:

$ python
>>> from time import tzname
>>> tzname
('CET', 'CEST')
>>> import pytz
>>> pytz.timezone(tzname[0])
<DstTzInfo 'CET' CET+1:00:00 STD>

Thanks !

@erincerys
Copy link
Author

Here you go!

>>> import time
>>> time.tzname
('PST', 'PDT')
>>> import pytz
>>> pytz.timezone(tzname[0])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/site-packages/pytz/__init__.py", line 177, in timezone
    raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'PST'

Some other information:

>>> print(' '.join(pytz.country_timezones['us']))
America/New_York America/Detroit America/Kentucky/Louisville America/Kentucky/Monticello America/Indiana/Indianapolis America/Indiana/Vincennes America/Indiana/Winamac America/Indiana/Marengo America/Indiana/Petersburg America/Indiana/Vevay America/Chicago America/Indiana/Tell_City America/Indiana/Knox America/Menominee America/North_Dakota/Center America/North_Dakota/New_Salem America/North_Dakota/Beulah America/Denver America/Boise America/Phoenix America/Los_Angeles America/Anchorage America/Juneau America/Sitka America/Metlakatla America/Yakutat America/Nome America/Adak Pacific/Honolulu

>>> 'PST' in pytz.all_timezones
False

I don't really see how this code is expected to work, after reading the pytz docs. All the examples use full-length IANA-specified zone names, and this abbreviated format appears to be the expected result of time.tzname. Maybe I'm missing something.

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 a pull request may close this issue.

2 participants