Improve issue stdout

This commit is contained in:
nicolargo 2023-05-07 12:36:52 +02:00
parent 38d0e706d7
commit 2633757929
3 changed files with 25 additions and 14 deletions

View File

@ -10,10 +10,13 @@ For an enhancement or new feature: Describe your needs.
#### Versions #### Versions
* Glances & psutil (glances -V): * Glances & psutil (glances -V): `To be completed`
* Operating System (lsb_release -a): * Operating System (lsb_release -a): `To be completed`
* How do you install Glances (Pypi package, script, package manager, source): * How do you install Glances (Pypi package, script, package manager, source): `To be completed`
#### Logs #### Configuration and log file
You can also pastebin the Glances logs file (https://glances.readthedocs.io/en/latest/config.html#logging) You can also [pastebin](https://pastebin.com/):
* the Glances configuration file (https://glances.readthedocs.io/en/latest/config.html#location)
* the Glances log file (https://glances.readthedocs.io/en/latest/config.html#logging)

View File

@ -22,11 +22,15 @@ A clear and concise description of what you expected to happen.
**Screenshots** **Screenshots**
If applicable, add screenshots to help explain your problem. If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):** **Environement (please complete the following information):**
- OS: [e.g. GNU/Linux Ubuntu 20.04] - OS: [e.g. GNU/Linux Ubuntu 20.04]
- Glances Version [output of glances -V] - Glances Version [output of glances -V]
- Glances logs file [output of tail -10 <glances logs file>] - Glances logs file [output of tail -10 <glances logs file>]
- Glances test [output of glances --issue] (only available with Glances 3.1.7 or higher) - Glances test [output of glances --issue] (only available with Glances 3.1.7 or higher)
```
Copy paste output of glances --issue here
```
**Additional context** **Additional context**
Add any other context about the problem here. Add any other context about the problem here.

View File

@ -12,8 +12,8 @@
import os import os
import sys import sys
import platform import platform
import shutil
import time import time
import pprint
from glances.timer import Counter from glances.timer import Counter
from glances import __version__, psutil_version from glances import __version__, psutil_version
@ -21,10 +21,7 @@ from glances import __version__, psutil_version
import psutil import psutil
import glances import glances
try: TERMINAL_WIDTH = 79
TERMINAL_WIDTH = shutil.get_terminal_size(fallback=(79, 24)).columns
except Exception:
TERMINAL_WIDTH = 79
class colors: class colors:
@ -105,6 +102,10 @@ class GlancesStdoutIssue(object):
stats._plugins[plugin].update() stats._plugins[plugin].update()
# Get the stats # Get the stats
stat = stats.get_plugin(plugin).get_export() stat = stats.get_plugin(plugin).get_export()
# Hide private information
if plugin == 'ip':
for key in stat.keys():
stat[key] = '***'
except Exception as e: except Exception as e:
stat_error = e stat_error = e
if stat_error is None: if stat_error is None:
@ -113,14 +114,17 @@ class GlancesStdoutIssue(object):
) )
if isinstance(stat, list) and len(stat) > 0 and 'key' in stat[0]: if isinstance(stat, list) and len(stat) > 0 and 'key' in stat[0]:
key = 'key={} '.format(stat[0]['key']) key = 'key={} '.format(stat[0]['key'])
message = colors.ORANGE + key + colors.NO + str(stat)[0 : TERMINAL_WIDTH - 41 - len(key)] stat_output = pprint.pformat([stat[0]], compact=True, width=120, depth=3)
message = colors.ORANGE + key + colors.NO + '\n' + stat_output[0:-1] + ', ...' + stat_output[-1]
else: else:
message = colors.NO + str(stat)[0 : TERMINAL_WIDTH - 41] message = '\n' + colors.NO + pprint.pformat(stat, compact=True, width=120, depth=2)
else: else:
result = (colors.RED + '[ERROR]' + colors.BLUE + ' {:.5f}s '.format(counter.get())).rjust( result = (colors.RED + '[ERROR]' + colors.BLUE + ' {:.5f}s '.format(counter.get())).rjust(
41 - len(plugin) 41 - len(plugin)
) )
message = colors.NO + str(stat_error)[0 : TERMINAL_WIDTH - 41] message = colors.NO + str(stat_error)[0: TERMINAL_WIDTH - 41]
# Display the result
self.print_issue(plugin, result, message) self.print_issue(plugin, result, message)
# Display total time need to update all plugins # Display total time need to update all plugins