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

ZeroDivisionError when server has no swap #318

Closed
iuridiniz opened this issue Sep 21, 2022 · 1 comment · Fixed by #320
Closed

ZeroDivisionError when server has no swap #318

iuridiniz opened this issue Sep 21, 2022 · 1 comment · Fixed by #320
Assignees
Labels

Comments

@iuridiniz
Copy link

Hello

Description
When the machine has no swap, the pg_activity does not open

Software version: 3.0.0

Steps to reproduce:
Configure a machine with no swap, launch pg_activity

Expected results:
pg_activity opens

Actual results:
pg_acrivity crashes with ZeroDivisionError: division by zero

root@db1:~# pg_activity 

Traceback (most recent call last):
  File "/usr/local/bin/pg_activity", line 8, in <module>
    sys.exit(main())
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/cli.py", line 407, in main
    ui.main(term, dataobj, host, args)
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/ui.py", line 250, in main
    width=width,
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/views.py", line 572, in screen
    width=width,
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/views.py", line 124, in wrapper
    for line in func(term, *args, **kwargs):
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/views.py", line 324, in header
    [f"{render(free)} ({render(system_info.swap.pct_free)}) free"],
  File "/usr/local/pythonenv/pg_activity/lib/python3.7/site-packages/pgactivity/types.py", line 704, in pct_free
    return Pct(self.free * 100 / self.total)
ZeroDivisionError: division by zero
root@db1:~# free
              total        used        free      shared  buff/cache   available
Mem:       32296672     6219592      571240      622296    25505840    25097340
Swap:             0           0           0
root@evoluxio-db1:~# 
@blogh blogh self-assigned this Sep 26, 2022
@blogh blogh added the bug label Sep 26, 2022
blogh added a commit to blogh/pg_activity that referenced this issue Sep 26, 2022
In cases where there is no swap we don't display a percentage.
The case with zero memory is also covered event if it's not realistic it
doesn't cost much to do it.

Issue dalibo#318
blogh added a commit to blogh/pg_activity that referenced this issue Sep 26, 2022
In cases where there is no swap we don't display a percentage.
The case with zero memory is also covered event if it's not realistic it
doesn't cost much to do it.

Issue dalibo#318
blogh added a commit to blogh/pg_activity that referenced this issue Sep 26, 2022
In cases where there is no swap we don't display a percentage.
The case with zero memory is also covered event if it's not realistic it
doesn't cost much to do it.

Issue dalibo#318
blogh added a commit that referenced this issue Sep 27, 2022
In cases where there is no swap we don't display a percentage.
The case with zero memory is also covered event if it's not realistic it
doesn't cost much to do it.

Issue #318
blogh added a commit to blogh/pg_activity that referenced this issue Sep 27, 2022
* Fix a division by zero where there is no swap (dalibo#318) (Reported by
  @iuridiniz)
@blogh blogh mentioned this issue Sep 27, 2022
blogh added a commit that referenced this issue Sep 27, 2022
* Fix a division by zero where there is no swap (#318) (Reported by
  @iuridiniz)
@blogh
Copy link
Collaborator

blogh commented Sep 27, 2022

thanks for reporting this !

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