Skip to content

Commit

Permalink
refactor(volumes): Replace redundant strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adityahase committed Jan 2, 2025
1 parent fe52495 commit 62d1457
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions press/api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def poly_get_doc(doctypes, name):
return frappe.get_doc(doctypes[-1], name)


MOUNTPOINT_REGEX = "(/|/opt/volumes/mariadb|/opt/volumes/benches)"


@frappe.whitelist()
def all(server_filter=None): # noqa: C901
if server_filter is None:
Expand Down Expand Up @@ -193,7 +196,7 @@ def usage(name):
lambda x: x,
),
"disk": (
f"""sum(node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"(/opt/volumes/mariadb|/|/opt/volumes/benches)"}} - node_filesystem_avail_bytes{{instance="{name}", job="node", mountpoint=~"(/opt/volumes/mariadb|/|/opt/volumes/benches)"}}) by ()/ (1024 * 1024 * 1024)""",
f"""sum(node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"{MOUNTPOINT_REGEX}"}} - node_filesystem_avail_bytes{{instance="{name}", job="node", mountpoint=~"{MOUNTPOINT_REGEX}"}}) by ()/ (1024 * 1024 * 1024)""",
lambda x: x,
),
"memory": (
Expand All @@ -218,7 +221,7 @@ def total_resource(name):
lambda x: x,
),
"disk": (
f"""sum(node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"(/opt/volumes/mariadb|/|/opt/volumes/benches)"}}) by () / (1024 * 1024 * 1024)""",
f"""sum(node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"{MOUNTPOINT_REGEX}"}}) by () / (1024 * 1024 * 1024)""",
lambda x: x,
),
"memory": (
Expand Down Expand Up @@ -289,7 +292,7 @@ def analytics(name, query, timezone, duration):
lambda x: x["device"],
),
"space": (
f"""100 - ((node_filesystem_avail_bytes{{instance="{name}", job="node", mountpoint=~"(/opt/volumes/mariadb|/|/opt/volumes/benches)"}} * 100) / node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"(/opt/volumes/mariadb|/|/opt/volumes/benches)"}})""",
f"""100 - ((node_filesystem_avail_bytes{{instance="{name}", job="node", mountpoint=~"{MOUNTPOINT_REGEX}"}} * 100) / node_filesystem_size_bytes{{instance="{name}", job="node", mountpoint=~"{MOUNTPOINT_REGEX}"}})""",
lambda x: x["mountpoint"],
),
"loadavg": (
Expand Down Expand Up @@ -549,7 +552,7 @@ def rename(name, title):
doc.save()


def get_timespan_timegrain(duration: str) -> Tuple[int, int]:
def get_timespan_timegrain(duration: str) -> tuple[int, int]:
timespan, timegrain = {
"1 Hour": (60 * 60, 2 * 60),
"6 Hour": (6 * 60 * 60, 5 * 60),
Expand Down

0 comments on commit 62d1457

Please sign in to comment.