Skip to content

Instantly share code, notes, and snippets.

@fritshoogland-yugabyte
Last active April 13, 2021 13:24
Show Gist options
  • Save fritshoogland-yugabyte/ead025e3c5a3cde17b0d9921aa13398d to your computer and use it in GitHub Desktop.
Save fritshoogland-yugabyte/ead025e3c5a3cde17b0d9921aa13398d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# this requires some python libraries to be installed:
# BeautifulSoup: sudo pip3 install BeautifulSoup4
# lxml : sudo pip3 install lxml
# humanfriendly: sudo pip3 install humanfriendly
#
from bs4 import BeautifulSoup
import urllib.request as request
import humanfriendly
import re
import sys
server="localhost:7000"
# if a number is set as argument, this is the level up to which is shown.
if len(sys.argv)-1 > 0:
show_level = int(sys.argv[1])+1
else:
show_level = 2+1
try:
with request.urlopen("http://"+server+"/mem-trackers") as response:
http_response = response.read()
except:
print("error reading mem-trackers")
exit(1)
memory_table=[]
soup=BeautifulSoup(http_response, "lxml")
table=soup.find("table", {"class":"table table-striped"})
for row in table.findAll("tr"):
level=row.get("data-depth")
if level is None:
continue
data=row.findAll("td")
memory_table_row=[]
memory_table_row.append(level)
for field in data:
memory_table_row.append(field.text)
memory_table.append(memory_table_row)
# remove: "2.18M (2.84M)"; not sure what each number is, I picked the first one.
for row in memory_table:
row[2]=re.sub('\(.*\)', '', row[2])
# build names to indicate hierarchy
last_level_name = {}
for row in memory_table:
last_level_name[row[0]]=row[1]
row[1]=".".join(last_level_name[str(x)] for x in range(int(row[0])+1))
print("server: "+server)
print("%2s %-80s %16s %16s %16s %6s" % ("Lv", "Subsystem", "Current", "Peak", "Limit", "%"))
for row in memory_table:
if row[0] in [str(x) for x in range(0, show_level)]:
if row[4] == "none":
print("%2d %-80s %16d %16d %16s %6s" % (float(row[0]), row[1], float(humanfriendly.parse_size(row[2], binary=True)), float(humanfriendly.parse_size(row[3], binary=True)), row[4], "none"))
else:
print("%2d %-80s %16d %16d %16d %6s" % (float(row[0]), row[1], float(humanfriendly.parse_size(row[2], binary=True)), float(humanfriendly.parse_size(row[3], binary=True)), float(humanfriendly.parse_size(row[4], binary=True)), round(humanfriendly.parse_size(row[2], binary=True)/humanfriendly.parse_size(row[4], binary=True)*100,2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment