Skip to content

Commit

Permalink
feat: Errors in System Health
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 22, 2024
1 parent 2df9e2e commit 7bfa31f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
33 changes: 31 additions & 2 deletions frappe/desk/doctype/system_health_report/system_health_report.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
"failed_emails",
"incoming_emails_last_7_days_column",
"handled_emails",
"unhandled_emails"
"unhandled_emails",
"errors_tab",
"errors_generated_in_last_1_day_section",
"total_errors",
"top_errors",
"column_break_keyz"
],
"fields": [
{
Expand Down Expand Up @@ -132,14 +137,38 @@
"fieldname": "handled_emails",
"fieldtype": "Int",
"label": "Handled Emails"
},
{
"fieldname": "errors_tab",
"fieldtype": "Tab Break",
"label": "Errors"
},
{
"fieldname": "errors_generated_in_last_1_day_section",
"fieldtype": "Section Break",
"label": "Errors generated in last 1 day"
},
{
"fieldname": "total_errors",
"fieldtype": "Int",
"label": "Total Errors"
},
{
"fieldname": "top_errors",
"fieldtype": "Code",
"label": "Top Errors"
},
{
"fieldname": "column_break_keyz",
"fieldtype": "Column Break"
}
],
"hide_toolbar": 1,
"index_web_pages_for_search": 1,
"is_virtual": 1,
"issingle": 1,
"links": [],
"modified": "2024-04-18 18:50:33.486009",
"modified": "2024-04-18 19:11:38.645528",
"modified_by": "Administrator",
"module": "Desk",
"name": "System Health Report",
Expand Down
25 changes: 24 additions & 1 deletion frappe/desk/doctype/system_health_report/system_health_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class SystemHealthReport(Document):
scheduler_status: DF.Data | None
socketio_ping_check: DF.Literal["Fail", "Pass"]
socketio_transport_mode: DF.Literal["Polling", "Websocket"]
top_errors: DF.Code | None
total_background_workers: DF.Int
total_errors: DF.Int
total_outgoing_emails: DF.Int
unhandled_emails: DF.Int
# end: auto-generated types
Expand All @@ -60,6 +62,7 @@ def load_from_db(self):
super(Document, self).__init__({})
self.fetch_background_workers()
self.fetch_email_stats()
self.fetch_errors()

def fetch_background_workers(self):
self.scheduler_status = get_scheduler_status().get("status")
Expand Down Expand Up @@ -92,7 +95,7 @@ def fetch_background_workers(self):
)

def fetch_email_stats(self):
threshold = add_to_date(None, days=-1, as_datetime=True)
threshold = add_to_date(None, days=-7, as_datetime=True)
filters = {"creation": (">", threshold), "modified": (">", threshold)}
self.total_outgoing_emails = frappe.db.count("Email Queue", filters)
self.pending_emails = frappe.db.count("Email Queue", {"status": "Not Sent", **filters})
Expand All @@ -103,6 +106,26 @@ def fetch_email_stats(self):
{"sent_or_received": "Received", "communication_type": "Communication", **filters},
)

def fetch_errors(self):
from terminaltables import AsciiTable

threshold = add_to_date(None, days=-1, as_datetime=True)
filters = {"creation": (">", threshold), "modified": (">", threshold)}
self.total_errors = frappe.db.count("Error Log", filters)

top_errors = frappe.db.sql(
"""select method, count(*) as occurance
from `tabError Log`
where modified > %(threshold)s and creation > %(threshold)s
group by method
order by occurance desc
limit 5""",
{"threshold": threshold},
as_list=True,
)
if top_errors:
self.top_errors = AsciiTable([["Error Title", "Count"], *top_errors]).table

def db_update(self):
raise NotImplementedError

Expand Down

0 comments on commit 7bfa31f

Please sign in to comment.