-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add structured exception data to debug
This adds explicit dumping ground for exceptions we're generating on TrueNAS.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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 |
---|---|---|
@@ -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)] |
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