Debug the PR. First rush.

This commit is contained in:
nicolargo 2025-01-04 15:03:16 +01:00
parent e1190ad92c
commit 61b3a19ab0
5 changed files with 36 additions and 31 deletions

View File

@ -550,6 +550,11 @@ disable=False
# Events will be merged
;min_interval=6
[tailer]
disable=False
filename=/var/log/syslog
lines=10
##############################################################################
# Browser mode - Static servers definition
##############################################################################

View File

@ -804,13 +804,21 @@ class _GlancesCurses:
for p in self._right_sidebar():
if (hasattr(self.args, 'enable_' + p) or hasattr(self.args, 'disable_' + p)) and p in stat_display:
self.new_line()
if p == 'processlist':
if p in ['processlist', 'programlist']:
p_index = self._right_sidebar().index(p) + 1
self.display_plugin(
stat_display['processlist'],
stat_display[p],
display_optional=(self.term_window.getmaxyx()[1] > 102),
display_additional=(not MACOS),
max_y=(
self.term_window.getmaxyx()[0] - self.get_stats_display_height(stat_display['alert']) - 2
self.term_window.getmaxyx()[0]
- sum(
[
self.get_stats_display_height(stat_display[i])
for i in self._right_sidebar()[p_index:]
]
)
- 2
),
)
else:

View File

@ -84,6 +84,7 @@
<glances-plugin-containers v-if="!args.disable_containers" :data="data"></glances-plugin-containers>
<glances-plugin-process :data="data"></glances-plugin-process>
<glances-plugin-alert v-if="!args.disable_alert" :data="data"></glances-plugin-alert>
<glances-plugin-tailer v-if="!args.disable_tailer" :data="data"></glances-plugin-tailer>
</div>
</div>
</div>
@ -125,7 +126,7 @@ import GlancesPluginUptime from './components/plugin-uptime.vue';
import GlancesPluginVms from './components/plugin-vms.vue';
import GlancesPluginWifi from './components/plugin-wifi.vue';
import GlancesPluginTailer from './components/plugin-tailer.vue';
import uiconfig from './uiconfig.json';
export default {

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# This file is part of Glances.
#
@ -15,13 +14,12 @@ This plugin tails a file (given by the user), displaying:
- last N lines
"""
import os
import time
import datetime
import os
from typing import Optional
from glances.logger import logger
from glances.plugins.plugin.model import GlancesPluginModel
from glances.globals import bytes2human
# -----------------------------------------------------------------------------
# Globals
@ -58,6 +56,7 @@ items_history_list = [
# Plugin class
# -----------------------------------------------------------------------------
class PluginModel(GlancesPluginModel):
"""Tailer plugin main class.
@ -78,9 +77,9 @@ class PluginModel(GlancesPluginModel):
# We want to display the stat in the TUI
self.display_curse = True
# Optionally read from the config file [tail] section
# Optionally read from the config file [tailer] section
# e.g.:
# [tail]
# [tailer]
# filename=/var/log/syslog
# lines=10
self.default_filename = config.get_value(self.plugin_name, 'filename', default='/var/log/syslog')
@ -162,7 +161,6 @@ class PluginModel(GlancesPluginModel):
def _tail_file(self, filename, num_lines):
"""Return (total_line_count, list_of_last_N_lines)."""
lines = []
with open(filename, 'rb') as f:
# If the file is huge, you might want a more efficient way to read
# the last N lines rather than reading the entire file.
@ -188,12 +186,12 @@ class PluginModel(GlancesPluginModel):
for stat_dict in self.get_raw():
fsize = stat_dict.get("file_size", 0)
# Example: decorate if file > 1GB
if fsize > 1024 ** 3:
if fsize > 1024**3:
self.views[stat_dict[self.get_key()]]["file_size"]["decoration"] = self.get_alert(
fsize, header='bigfile'
)
def msg_curse(self, args=None, max_width=None):
def msg_curse(self, args=None, max_width: Optional[int] = None) -> list[str]:
"""Return the dict (list of lines) to display in the TUI."""
ret = []
@ -201,13 +199,6 @@ class PluginModel(GlancesPluginModel):
if not self.stats or self.is_disabled():
return ret
if max_width:
name_max_width = max_width - 20
else:
# No max_width defined
logger.debug(f"No max_width defined for the {self.plugin_name} plugin, it will not be displayed.")
return ret
# Header
ret.append(self.curse_add_line("FILE TAILER PLUGIN", "TITLE"))
@ -224,21 +215,21 @@ class PluginModel(GlancesPluginModel):
# 1) Filename
msg_filename = f"File: {filename}"
ret.append(self.curse_add_line(msg_filename[:name_max_width], "NORMAL"))
ret.append(self.curse_add_line(msg_filename))
# 2) File size + last modified time
msg_meta = (f"Size: {bytes2human(file_size)}, "
f"Last Modified: {last_modified}, "
f"Total Lines: {line_count}")
msg_meta = (
f"Size: {self.auto_unit(file_size)}, " f"Last Modified: {last_modified}, " f"Total Lines: {line_count}"
)
ret.append(self.curse_new_line())
ret.append(self.curse_add_line(msg_meta, "NORMAL"))
ret.append(self.curse_add_line(msg_meta))
# 3) Last N lines
ret.append(self.curse_new_line())
ret.append(self.curse_add_line("Last lines:", "NORMAL"))
ret.append(self.curse_add_line("Last lines:"))
for line in last_lines:
ret.append(self.curse_new_line())
ret.append(self.curse_add_line(f" {line}", "NORMAL"))
ret.append(self.curse_add_line(f" {line}"))
ret.append(self.curse_new_line())