Skip to content

Commit

Permalink
ctop: Add include and except family attributes
Browse files Browse the repository at this point in the history
Signed-off-by: iipeace <[email protected]>
  • Loading branch information
iipeace committed Nov 4, 2023
1 parent 737f51f commit 4049524
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 51 deletions.
76 changes: 39 additions & 37 deletions guider/guider.conf
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,34 @@

- FIELD
< common >
- apply: activation flag (true/false)
- after: uptime condition for event handling
- before: uptime condition for event handling
- caution: caution (string)
- command: command set for handling the started event
- comp: check compare operation (big, less, eq)
- include: task filter for inclusion
- except: task filter for exclusion
- explain: description (string)
- goneshot: global oneshot flag (true/false)
- interval: duration condition for event (tick)
- lcommand: command set for handling the finished event
- lock: global lock flag to handle the event exclusively (true/false)
- max: maximum count for event handling (tick)
- message: event message (string)
- multicond: multiple condition flag for event (true/false)
- oneshot: one-time event handling flag (true/false)
- perm: permission requirement (root)
- rafter: runtime condition for event handling
- rbefore: runtime condition for event handling
- re: regex filter flag for logs (true/false)
- refresh: restart timer for items disabled by oneshot (tick)
- signal: signal timer for command task (tick{:SIGNAL})
- skip: global skip count flag (tick)
- taskmon: monitoring status for tasks (true/false)
- type: interval value type (avg/min/max)
- apply: activation flag (true/false)
- after: uptime condition for event handling
- before: uptime condition for event handling
- caution: caution (string)
- command: command set for handling the started event
- comp: check compare operation (big, less, eq)
- includeOR: task OR filter for inclusion
- includeAND: task AND filter for inclusion
- exceptOR: task OR filter for exclusion
- exceptAND: task AND filter for exclusion
- explain: description (string)
- goneshot: global oneshot flag (true/false)
- interval: duration condition for event (tick)
- lcommand: command set for handling the finished event
- lock: global lock flag to handle the event exclusively (true/false)
- max: maximum count for event handling (tick)
- message: event message (string)
- multicond: multiple condition flag for event (true/false)
- oneshot: one-time event handling flag (true/false)
- perm: permission requirement (root)
- rafter: runtime condition for event handling
- rbefore: runtime condition for event handling
- re: regex filter flag for logs (true/false)
- refresh: restart timer for items disabled by oneshot (tick)
- signal: signal timer for command task (tick{:SIGNAL})
- skip: global skip count flag (tick)
- taskmon: monitoring status for tasks (true/false)
- type: interval value type (avg/min/max)

< cpu >
- total: total CPU usage for system/process/thread (%)
Expand Down Expand Up @@ -354,14 +356,14 @@

"*": [
{
"apply": "False",
"apply": "false",
"total": 95,
"interval": 3,
"oneshot": "true",
"refresh": 30,
"lock": "true",
"perm": "root",
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["CMD_TTOP_PROC"],
"explain": "monitor CPU usage for all processes except for b.out"
},
Expand All @@ -371,7 +373,7 @@
"pri": "R90",
"oneshot": "true",
"refresh": 30,
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["CMD_TTOP_PROC"],
"explain": "monitor CPU priority for all processes except for b.out"
}
Expand Down Expand Up @@ -462,7 +464,7 @@
"perm": "root",
"oneshot": "true",
"lock": "true",
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["CMD_LEAK_1G"],
"explain": "monitor RSS for all processes"
},
Expand Down Expand Up @@ -496,7 +498,7 @@
"size": 310,
"perm": "root",
"oneshot": "true",
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["SAVE:3s"],
"message": "GPU memory usage for the specific process is high",
"explain": "monitor GPU-dedicated memory for all processes"
Expand Down Expand Up @@ -529,7 +531,7 @@
"*": {
"apply": "false",
"swap": 100,
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["CMD_MTOP"],
"explain": "monitor swapped out memory for all processes"
}
Expand All @@ -554,7 +556,7 @@
"write": "100M",
"perm": "root",
"interval": 2,
"except": ["b.out"],
"exceptOR": ["b.out"],
"command": ["CMD_DISKTOP_TOTAL"],
"explain": "monitor block I/O usage for all processes"
},
Expand Down Expand Up @@ -590,7 +592,7 @@
"usagePer": 99,
"free": 100,
"interval": 5,
"except": ["/dev/loop*"],
"exceptOR": ["/dev/loop*"],
"perm": "root",
"oneshot": "true",
"command": ["CMD_DISKTOP"],
Expand Down Expand Up @@ -628,7 +630,7 @@
"recv": "1G",
"trans": "500M",
"interval": 3,
"except": ["lo"],
"exceptOR": ["lo"],
"perm": "root",
"command": ["CMD_NETTOP"],
"explain": "monitor network usage for all devices"
Expand Down Expand Up @@ -676,7 +678,7 @@
"oneshot": "true",
"refresh": 100,
"command": ["CMD_FTOP_PROC"],
"except": ["*.out", "screen"],
"exceptOR": ["*.out", "screen"],
"explain": "monitor file descriptors of the all processes"
},

Expand Down Expand Up @@ -795,7 +797,7 @@

"*": {
"apply": "false",
"except": ["b.out", "kworker*"],
"exceptOR": ["b.out", "kworker*"],
"nrCtx": 5000,
"interval": 3,
"command": ["SAVE:3s"],
Expand Down
57 changes: 43 additions & 14 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "231103"
__revision__ = "231104"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -7189,6 +7189,19 @@ def printSyscalls(systable):

sys.exit("%s\ntotal: %s" % (bufstring, len(systable)))

@staticmethod
def isValidStrAll(string, key=None, inc=False, ignCap=False):
if not string or not key:
return False

final = True
for item in key:
if not UtilMgr.isValidStr(string, [item], inc, ignCap):
final = False
break

return final

@staticmethod
def isValidStr(string, key=None, inc=False, ignCap=False):
if not string:
Expand Down Expand Up @@ -7218,14 +7231,14 @@ def isValidStr(string, key=None, inc=False, ignCap=False):
if cond == "*":
return True
elif (
cond.startswith("*")
and cond.endswith("*")
cond[0] == "*"
and cond[-1] == "*"
and cond.strip("*") in string
):
return True
elif cond.startswith("*") and string.endswith(cond[1:]):
elif cond[0] == "*" and string.endswith(cond[1:]):
return True
elif cond.endswith("*") and string.startswith(cond[:-1]):
elif cond[-1] == "*" and string.startswith(cond[:-1]):
return True
elif cond == string:
return True
Expand Down Expand Up @@ -137039,23 +137052,39 @@ def _checkThreshold(cond):
if not type(cond) is dict:
return False

# check apply attribute #
if cond.get("apply") != "true":
return False
# check except attribute #
elif "except" in cond:
def _getTarget(addval, elist):
if "task" in addval:
pid = next(iter(addval["task"]))
etarget = addval["task"][pid]["comm"].lstrip("*")
elif "dev" in addval:
etarget = addval["dev"]
else:
etarget = None
elist = elist if type(elist) is list else [elist]
return etarget, elist

elist = cond["except"]
if etarget and UtilMgr.isValidStr(
etarget, elist if type(elist) is list else [elist]
):
# check apply attribute #
if cond.get("apply") != "true":
return False
# check exceptOR attribute #
elif "exceptOR" in cond:
etarget, elist = _getTarget(addval, cond["exceptOR"])
if etarget and UtilMgr.isValidStr(etarget, elist):
return False
# check exceptAND attribute #
elif "exceptAND" in cond:
etarget, elist = _getTarget(addval, cond["exceptAND"])
if etarget and UtilMgr.isValidStrAll(etarget, elist):
return False
# check includeOR attribute #
elif "includeOR" in cond:
etarget, elist = _getTarget(addval, cond["includeOR"])
if etarget and not UtilMgr.isValidStr(etarget, elist):
return False
# check includeAND attribute #
elif "includeAND" in cond:
etarget, elist = _getTarget(addval, cond["includeAND"])
if etarget and not UtilMgr.isValidStrAll(etarget, elist):
return False

# check oneshot flag #
Expand Down

0 comments on commit 4049524

Please sign in to comment.