Skip to content

Commit

Permalink
Add structured exception data to debug
Browse files Browse the repository at this point in the history
This adds explicit dumping ground for exceptions we're generating
on TrueNAS.
  • Loading branch information
anodos325 committed Dec 31, 2024
1 parent 2a123ac commit f37bc56
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ixdiagnose/plugins/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import json

from .base import Plugin
from .metrics import PythonMetric

LOG_FILES = (
'/var/log/app_lifecycle.log',
'/var/log/app_migrations.log',
'/var/log/failover.log',
'/var/log/middlewared.log',
'/var/log/netdata_api.log',
'/var/log/zettarepl.log'
)


def parse_log_file(path: str) -> list[dict]:
results = []
with open(path, 'r') as f:
for line in f:
if '@cee:{"TNLOG":' not in line:
continue

data = json.loads(line.split('@cee:')[1])
results.append(data['TNLOG'])

return results


def gather_exceptions(client: None, resource_type: str) -> dict:
results = {}
for log in LOG_FILES:
try:
results[log] = parse_log_file(log)
except FileNotFoundError:
pass

return results


class LoggedExceptions(Plugin):
name = 'logged_exceptions'
metrics = [PythonMetric('log_file_exceptions', gather_exceptions, serializable=True)]
2 changes: 2 additions & 0 deletions ixdiagnose/plugins/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .containers import Containers
from .cpu import Cpu
from .cronjob import Cronjob
from .exceptions import LoggedExceptions
from .failover import Failover
from .ftp import FTP
from .hardware import Hardware
Expand Down Expand Up @@ -58,6 +59,7 @@
IPMI,
ISCSI,
LDAP,
LoggedExceptions,
Network,
NFS,
NVME,
Expand Down

0 comments on commit f37bc56

Please sign in to comment.