| Server IP : 172.67.134.114 / Your IP : 162.159.115.41 Web Server : Apache/2.4.37 System : Linux almalinux.duckdns.org 4.18.0-553.111.1.el8_10.x86_64 #1 SMP Sun Mar 8 20:06:07 EDT 2026 x86_64 User : ricodeal ( 1046) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/self/root/bin/ |
Upload File : |
#!/usr/libexec/platform-python
import logging
from subprocess import Popen, PIPE
import time
# grab the top five memory consuming processes, returning them in a string of
# of the format:
#
# name1:kB1,name2:kB2,...,name5:kB5
def topProcesses():
output = Popen(["ps", "-eo", "comm,rss", "--sort", "-rss", "--no-headers"], stdout=PIPE, universal_newlines=True).communicate()[0]
top5 = output.split("\n")[:5]
return ",".join("%s:%s" % (proc[0], proc[1]) for proc in (s.split() for s in top5))
def logit():
buffers = 0
cached = 0
memTotal = 0
memFree = 0
swapTotal = 0
swapFree = 0
with open("/proc/meminfo") as f:
for line in f.readlines():
if line.startswith("Buffers:"):
buffers = line.split()[1]
elif line.startswith("Cached:"):
cached = line.split()[1]
elif line.startswith("MemTotal:"):
memTotal = line.split()[1]
elif line.startswith("MemFree:"):
memFree = line.split()[1]
elif line.startswith("SwapTotal:"):
swapTotal = line.split()[1]
elif line.startswith("SwapFree:"):
swapFree = line.split()[1]
d = {"memUsed": int(memTotal)-int(memFree)-int(cached)-int(buffers),
"swapUsed": int(swapTotal)-int(swapFree),
"procs": topProcesses()}
mem_logger.debug("%(memUsed)d %(swapUsed)d %(procs)s", d)
mem_logger = logging.getLogger("memLog")
mem_logger.setLevel(logging.DEBUG)
handler = logging.FileHandler("/tmp/memory.dat")
handler.setLevel(logging.DEBUG)
handler.setFormatter(logging.Formatter("%(asctime)s %(message)s", "%H:%M:%S"))
mem_logger.addHandler(handler)
while True:
logit()
time.sleep(1)