Skip to content

Commit

Permalink
top: Add multiple screen printer for remote monitoring
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Jan 1, 2024
1 parent 73e7363 commit cc21555
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 21 deletions.
2 changes: 1 addition & 1 deletion guider/guider
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Guider Launcher
#
# Copyright (c) 2016-2023 Peace Lee <[email protected]>
# Copyright (c) 2016-2024 Peace Lee <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
Expand Down
98 changes: 78 additions & 20 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# -*- coding: utf-8 -*-

__author__ = "Peace Lee"
__copyright__ = "Copyright 2015-2023, Guider"
__copyright__ = "Copyright 2015-2024, Guider"
__module__ = "guider"
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "231230"
__revision__ = "240101"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -34308,7 +34308,7 @@ def printHelp(force=False, isExit=True):
-w <TIME:FILE{:VALUE}> set additional command
-x <IP:PORT> set local address
-X <REQ@IP:PORT> set request address
-N <REQ@IP:PORT> set report address
-N <REQ@IP:PORT> set report addresses
-S <CHARACTER{:VALUE}> sort by key
[ c:cpu / m:mem / p:pid / N:name / b:block / w:wfc
n:new / f:file / r:runtime / s:swap / e:exectime
Expand Down Expand Up @@ -34795,7 +34795,8 @@ def printHelp(force=False, isExit=True):
# {0:1} {1:1} -X REPORT@5555

- {3:1} {2:1} and report to 192.168.0.5:5555 in real-time
# {0:1} {1:1} -e r -N [email protected]:5555
# {0:1} {1:1} -e r -N [email protected]:5555, [email protected]:5555
# {0:1} {1:1} -e r -N [email protected]:5555, [email protected]:5555

- Print monitoring data from remote server with host name filter
# {0:1} {1:1} -x 5555 -X -q HOSTFILTER:"*LINUX*"
Expand Down Expand Up @@ -39017,7 +39018,7 @@ def _getDesc(s, t=0):
# {0:1} {1:1} "./**" -q PRINTFILE, NRMSG:1 -dL
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10, USEUPTIME
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:2023-04-11T01:30:00Z, UNTIL:2023-04-13T00:00:00Z
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:2024-04-11T01:30:00Z, UNTIL:2024-04-13T00:00:00Z
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10 -J
# {0:1} {1:1} "./*.dlt" -q FINDFILE, TAIL:-2000, UNTIL:-10, SETCURRENT:1234.123

Expand Down Expand Up @@ -135724,16 +135725,13 @@ def handleServerResponse(self, packet):
SysMgr.printErr("failed to send ACK to server")

# check hostname #
hostname = SysMgr.lastHost
hostname = str(SysMgr.lastHost)
if data.startswith(SysMgr.magicStr):
dataset = data.split(SysMgr.magicStr, 2)
if len(dataset) > 2:
SysMgr.lastHost = hostname = dataset[1]
SysMgr.lastHost = hostname = str(dataset[1])
data = dataset[2]

# update host list #
SysMgr.hostList["%s:%s" % (ip, port)] = hostname

# REPORT service #
if data[0] == "{" and data.strip()[-1] == "}":
# convert report data to dictionary type #
Expand Down Expand Up @@ -135764,20 +135762,80 @@ def handleServerResponse(self, packet):

# PRINT service #
else:
# check host filter #
SysMgr.waitUserInput(0.000001, msg="DEFAULT")

# get host filter #
hostFilter = SysMgr.environList.get("HOSTFILTER", [])
if not UtilMgr.isValidStr(str(hostname), hostFilter):

# check host filter #
hostaddr = "%s:%s" % (ip, port)
if not UtilMgr.isValidStr(
hostaddr, hostFilter
) and not UtilMgr.isValidStr(hostname, hostFilter):
return

# realtime mode #
if not SysMgr.outPath:
SysMgr.printPipe(data, flush=True)
# buffered mode #
# save host data #
if hostaddr in SysMgr.hostList:
SysMgr.hostList[hostaddr]["hostname"] = hostname
else:
SysMgr.addProcBuffer(data)
SysMgr.hostList[hostaddr] = {
"hostname": hostname,
"surface": "",
}

# flush buffer #
SysMgr.clearPrint()
# save screen data #
SysMgr.hostList[hostaddr]["surface"] = data.rstrip().split("\n")

# init screen vars #
nrLine = 0
nrSurface = 0
isMulti = True
fullSurface = ""
nrScreen = len(SysMgr.hostList)
if SysMgr.streamEnable or SysMgr.outPath:
windowSize = SysMgr.ttyRows = sys.maxsize
else:
windowSize = long(SysMgr.ttyRows / nrScreen) - 2

# composite surfaces #
for n, v in SysMgr.hostList.items():
try:
surface = v["surface"]
name = "%s(%s)" % (v["hostname"], n)

# last surface #
if nrSurface == nrScreen - 1:
cutSize = SysMgr.ttyRows - nrLine - 2
window = surface[:cutSize]
else:
window = surface[:windowSize]
nrLine += len(window) + 2

splitLineColor = UtilMgr.convColor(
"%s%s" % (name, splitLine[: -len(name)]), "GREEN"
)

fullSurface += "%s\n" % splitLineColor
fullSurface += "\n".join(window) + "\n\n"

nrSurface += 1

# handle per-node output file #
if SysMgr.outPath:
pass
except SystemExit:
sys.exit(0)
except KeyboardInterrupt:
sys.exit(0)
except:
pass

# clear screen #
if not SysMgr.outPath and not SysMgr.streamEnable:
SysMgr.clearScreen()

# print screen #
SysMgr.printPipe(fullSurface.rstrip())

def requestService(self):
if not SysMgr.remoteServObj or not SysMgr.localServObj:
Expand Down Expand Up @@ -136424,7 +136482,7 @@ def checkServer(self):

# wrong request or just data from server #
else:
SysMgr.printErr(
SysMgr.printWarn(
"failed to recognize the request from client (%s:%s)"
% (ip, port)
)
Expand Down

0 comments on commit cc21555

Please sign in to comment.