-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Interactive Debug Bar: Toggle-able interface providing real-time perf…
…ormance metrics and MQTT status
- Loading branch information
Showing
9 changed files
with
362 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
.env | ||
.env | ||
__pycache__ | ||
|
||
static/mqttui-logo-svg.svg | ||
static/mqttui-logo.png | ||
|
||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import time | ||
import psutil | ||
from flask import request | ||
from threading import Lock | ||
import logging | ||
|
||
class DebugBarPanel: | ||
def __init__(self, name): | ||
self.name = name | ||
self.data = {} | ||
|
||
def record(self, key, value): | ||
self.data[key] = value | ||
|
||
def get_data(self): | ||
return self.data | ||
|
||
class DebugBar: | ||
def __init__(self): | ||
self.panels = {} | ||
self.enabled = False | ||
self.start_time = None | ||
self.lock = Lock() | ||
try: | ||
self.process = psutil.Process() | ||
except Exception as e: | ||
logging.error(f"Failed to initialize psutil Process: {e}") | ||
self.process = None | ||
|
||
def add_panel(self, name): | ||
with self.lock: | ||
if name not in self.panels: | ||
self.panels[name] = DebugBarPanel(name) | ||
|
||
def record(self, panel, key, value): | ||
with self.lock: | ||
if panel in self.panels: | ||
self.panels[panel].record(key, value) | ||
|
||
def start_request(self): | ||
self.start_time = time.time() | ||
|
||
def end_request(self): | ||
if self.start_time: | ||
duration = time.time() - self.start_time | ||
self.record('request', 'duration', f"{duration:.2f}s") | ||
self.start_time = None | ||
|
||
def get_data(self): | ||
with self.lock: | ||
#self.update_performance_metrics() | ||
return {name: panel.get_data() for name, panel in self.panels.items()} | ||
|
||
def enable(self): | ||
self.enabled = True | ||
|
||
def disable(self): | ||
self.enabled = False | ||
|
||
debug_bar = DebugBar() | ||
|
||
# Initialize default panels | ||
debug_bar.add_panel('mqtt') | ||
debug_bar.add_panel('request') | ||
debug_bar.add_panel('performance') | ||
|
||
def debug_bar_middleware(): | ||
debug_bar.start_request() | ||
debug_bar.record('request', 'path', request.path) | ||
debug_bar.record('request', 'method', request.method) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
Flask==2.0.1 | ||
Flask-SocketIO==5.1.1 | ||
paho-mqtt==1.5.1 | ||
Werkzeug==2.0.1 | ||
Werkzeug==2.0.1 | ||
psutil==5.9.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.