Data-Monkey/Pi.Alert

Periodic Dropouts Online History

Data-Monkey opened this issue · 13 comments

I'm getting these periodic dropouts in the online history table:

image

image

This might be related to DB locks, but I'm only guessing...

The data should be saved to the DB in this method AFAIK:

https://github.com/Data-Monkey/Pi.Alert/blob/b814a856d0ff4b6c148c844b205528e4246ac3c9/pialert/database.py#LL417C20-L417C20

db.read vs db.read_one issue?

I haven't looked into what this actually does in detail.
Do you have any error messages?
Maybe I am no longer running all the steps in the correct order. If the history runs before a scan runs it might be like that.
Are all the devices that are offline from the same scan-type?

Could it be that these calls return 0?

History_Archived = db.read("SELECT * FROM Devices WHERE dev_Archived = 1")

It's also weird that this keeps happening in-between scans, but the correct values are entered after an actual scan

networkscan passes in the global cycle:

insertOnlineHistory(db,conf.cycle)

Last time this SQL query was changed it was targeting a different DB table... not sure even if cycle is required (maybe removing the where statement would fix this)? Still investigating:

jokob-sk/Pi.Alert@51027f6

Just checked the DB - I think we can safely remove the where clause:

image

Figured it out I think - the method is called even if there is no data in the CurrentScan table. The method is called more often than before (even if a scan is not being processed) so it returns 0. Previously the method was only executed if data in the CurrentScan table were present.

Great Find!
So it must only run after a scan was actually executed.
If all the scans run and found nothing it would be correct to set everything to offline.

Yes, I remember there was a problem that I don't know how to return anything from the scan_network() method into the main loop as it is multiprocessing again. Maybe I need to call one from the other. I think it was all 1 big script before.

Is it ever possible to have no devices in CurrentScan?
The actual host of the docker should always be there, no?
Maybe we can just say if CurrentScan is empty skip the InsertOnlineHistory?

Yeeah, I think that's acceptable - it's only for stats - no other functionality is dependent on it

I added the check to run only if there are records in the CurrentScan table. Also hopefully fixed the read_one() that was not actually working when there was only 1 record in the result!

great! seems fixed:

image