Handle exceptions reading json file and parsing json data
This commit is contained in:
parent
a94e755b96
commit
d5a501c59b
1 changed files with 9 additions and 3 deletions
|
@ -60,12 +60,18 @@ class restic_exporter:
|
|||
print(f"{self.metric_name}_{counter}{labels} {float(self.summary[counter])} {self.summary['timestamp']}")
|
||||
|
||||
def _read_summary_from_json(self, json_file):
|
||||
with open(json_file, 'r') as file_pointer:
|
||||
content = file_pointer.readlines()
|
||||
try:
|
||||
with open(json_file, 'r') as file_pointer:
|
||||
content = file_pointer.readlines()
|
||||
except Exception as error:
|
||||
self._log.error(f"Error reading file '{json_file}'. Check permissions. {error}")
|
||||
|
||||
self.summary = {}
|
||||
for line in content:
|
||||
line_data = json.loads(line)
|
||||
try:
|
||||
line_data = json.loads(line)
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
self._log.error(f"Error decoding line '{line}'. {error}")
|
||||
if 'message_type' in line_data and line_data['message_type'] == 'summary':
|
||||
self.summary = line_data
|
||||
if 'snapshot_id' in line_data:
|
||||
|
|
Loading…
Reference in a new issue