database: track unsafe shutdowns
Keep track of the number of unsafe shutdowns a machine experiences. This data is useful in diagnosing potential file system issues and issues with the datbase itself. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
9a316fe84a
commit
c9a958f861
|
@ -104,6 +104,15 @@ class MoonrakerDatabase:
|
|||
debug_counter)
|
||||
if debug_counter:
|
||||
logging.info(f"Database Debug Count: {debug_counter}")
|
||||
|
||||
# Track unsafe shutdowns
|
||||
unsafe_shutdowns: int = self.get_item(
|
||||
"moonraker", "database.unsafe_shutdowns", 0)
|
||||
logging.info(f"Unsafe Shutdown Count: {unsafe_shutdowns}")
|
||||
# Increment unsafe shutdown counter. This will be reset if
|
||||
# moonraker is safely restarted
|
||||
self.insert_item("moonraker", "database.unsafe_shutdowns",
|
||||
unsafe_shutdowns + 1)
|
||||
self.server.register_endpoint(
|
||||
"/server/database/list", ['GET'], self._handle_list_request)
|
||||
self.server.register_endpoint(
|
||||
|
@ -392,6 +401,12 @@ class MoonrakerDatabase:
|
|||
return {'namespace': namespace, 'key': key, 'value': val}
|
||||
|
||||
def close(self) -> None:
|
||||
# Decrement unsafe shutdown counter
|
||||
unsafe_shutdowns: int = self.get_item(
|
||||
"moonraker", "database.unsafe_shutdowns", 0)
|
||||
self.insert_item("moonraker", "database.unsafe_shutdowns",
|
||||
unsafe_shutdowns - 1)
|
||||
|
||||
# log db stats
|
||||
msg = ""
|
||||
with self.lmdb_env.begin() as txn:
|
||||
|
|
Loading…
Reference in New Issue