Skip to content

Commit

Permalink
top option
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed May 28, 2024
1 parent 49ba3b0 commit ff19108
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 4 additions & 0 deletions heimdallr/configuration/heimdallr_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
GPU_INTERVAL_ID = "gpu-interval"
GPU_INTERVAL_MS = MQTT_PUBLISH_INTERVAL_SEC * 1000

TOP_TABLES_ID = "top-tables"
TOP_INTERVAL_ID = "top-interval"
TOP_INTERVAL_MS = MQTT_PUBLISH_INTERVAL_SEC * 1000 * 10

DU_TABLES_ID = "du-tables"
DU_INTERVAL_ID = "du-interval"
DU_INTERVAL_MS = MQTT_PUBLISH_INTERVAL_SEC * 1000 * 10
Expand Down
44 changes: 42 additions & 2 deletions heimdallr/entry_points/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import socket
import time
from typing import Any
from uuid import uuid4

import dash
import flask
Expand Down Expand Up @@ -83,7 +84,7 @@

# CLIENT_ID = str(uuid.getnode())
HOSTNAME = socket.gethostname()
CLIENT_ID = HOSTNAME
CLIENT_ID = HOSTNAME+uuid4().hex
MQTT_CLIENT = Client(
client_id=CLIENT_ID,
protocol=MQTTv5,
Expand Down Expand Up @@ -238,11 +239,50 @@ def update_table(n: int) -> Div:
return Div(compute_machines)


@DASH_APP.callback(
Output(ALL_CONSTANTS.TOP_TABLES_ID, "children"),
[Input(ALL_CONSTANTS.TOP_INTERVAL_ID, "n_intervals")],
)
def update_top_table(n: int) -> Div:
"""description"""
global GPU_STATS
global MQTT_CLIENT

MQTT_CLIENT.loop()

compute_machines = []

if len(DU_STATS) > 0:
df = to_overall_du_process_df(DU_STATS.as_dict())
else:
df = DataFrame(["No data"], columns=("data",))

compute_machines.append(
DataTable(
id="du-table-0",
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("records"),
page_size=ALL_CONSTANTS.TABLE_PAGE_SIZE,
# style_as_list_view=True,
style_data_conditional=[
{"if": {"row_index": "odd"}, "backgroundColor": "rgb(50, 50, 50)"},
{"if": {"row_index": "even"}, "backgroundColor": "rgb(60, 60, 60)"},
],
style_header={
"backgroundColor": "rgb(30, 30, 30)",
"fontWeight": "bold",
},
)
)

return Div(compute_machines)


@DASH_APP.callback(
Output(ALL_CONSTANTS.DU_TABLES_ID, "children"),
[Input(ALL_CONSTANTS.DU_INTERVAL_ID, "n_intervals")],
)
def update_table(n: int) -> Div:
def update_du_table(n: int) -> Div:
"""description"""
global GPU_STATS
global MQTT_CLIENT
Expand Down
5 changes: 5 additions & 0 deletions heimdallr/utilities/publisher/system_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ def get_list_of_process_sorted_by_memory(
list_of_proc_objects.append(proc_info)
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass

sorted_entries = sorted(
list_of_proc_objects, key=lambda proc_obj: proc_obj["vms"], reverse=True
)

if top_k:
sorted_entries = sorted_entries[:top_k]

return {v["pid"]: select_dict(v, "vms", *attrs) for v in sorted_entries}


Expand All @@ -55,9 +58,11 @@ def main():
def all_info_procs():
"""description"""
list_of_process_names = list()

for proc in psutil.process_iter():
p_info_dict = proc.as_dict()
list_of_process_names.append(p_info_dict)

for elem in list_of_process_names:
print(elem)

Expand Down

0 comments on commit ff19108

Please sign in to comment.