Skip to content

Fridge Monitor (legacy)

Albert Schimpf edited this page May 14, 2020 · 1 revision

Fridge Monitor

This is an old version of the fridge monitor specification which is still running in production since 2 years

Our goal is to monitor the status of a fridge via pings. If it is off for some time, we want an alarm to ring. Additionally, we want to be able to turn the fridge off at night, not ringing the alarm for 30 minutes for a better sleep, because the fridge is in the bedroom.

Our requirements are therefore as follows:

  • The fridge can be pinged at port 80 on some IP address if on, and is not reachable if off
  • The job should ring the alarm if the fridge is not reachable while trying to reboot the fridge
  • If the fridge is on again, the alarm should stop
  • There should be a grace period during which the alarm is not ringed and where the job waits a bit for the fridge to reboot
  • The time how long the fridge is turned off should be accessible via a HTTP GET request
  • The fridge can be turned off for 30 minutes without the alarm ringing with a HTTP GET request. It should turn itself on again after that time.

We can model these requirements as follows.

  • A SocketNode which accepts user input
  • PeriodicNodes which periodically ping and ring the alarm if necessary
  • PingNode to ping the fridge
  • 2 TimerNodes for the error and grace timer

After understanding how these nodes, we connect them together appropriately and generate a control flow graph.

img1

  1. On startup, pings are issued periodically.
  2. If a ping fails, it starts the error timer with a low timeout (unexpected failure of the fridge)
  3. If the error timer expires, it tries to reboot the fridge via a request. It then activates the grace timer.
  4. Grace timer acts as a buffer to allow the fridge some time to reboot. If the fridge is still off after the grace timer expires, periodics beeps are issued every 2.5 seconds.
  5. At any point in time, the ping can succeed again. For this case, every timer is stopped and the periodic beeps stop immediately if activated.
  6. To manually turn off the fridge during nighttime, we prepend a SocketNode which sole purpose is to check the timers and to issue a turn off command and set the error timer to 30 minutes.

We can further improve the scrape file with the following features:

  • By convention, the scraper accepts an .args file with the same name as a .scrape file. We can utilize the args file to parameterize the job for when some changes happen (e.g. IP address changes).

  • We can split the scrape file into fragments grouped by function to produce better looking control flow graphs and increase readability of big scrape files.

We check if the .args file has the correct parameters and start the scrape job.

java -jar scraper-bundled.jar fridgeAlarm.scrape

Race Conditions

The scrape job as defined above assumes ExecNode@3 instantaneously switches the fridge off or at least returns only after the fridge has turned off. If that is not the case, a race condition can occur.

  • Assume that the switch off command was sent successfully and the error timer started for 30 minutes (expected shutdown). Since the fridge is not off yet (assume a delay of 5 seconds), the periodic ping deactives the error timer again.

  • After the fridge actually turns off, the periodic ping detects an unexpected shutdown and rings the alarm.

The solution is to either extend the set_off.fragment to check, whether the fridge has turned off or not, or execute a switch off command which only returns, if the fridge is turned off successfully.

Full Job

The full job specification can be found here.