/alarm

Alarm - web application error alarm

Primary LanguageJavaScript

Assuming that 3 points.

We can raise an event everyTime the logError is called with the error parameter. This way we can separate the manual logging in the text file from the handling of the "counter". Let's call this event ERROR_THROW, and that event should have the ERROR_DATE in UTC.

We will register a handler for ERROR_THROW so every time the event is emitted: Let's assume that we've some sort of store like 'Redis' (https://redis.io/). That store will have two variabls there:

  • ERRORS_COLLECTION (Date[])
  • APP_NOTIFYING (bool)

Algorythm

  • ADD ERROR_DATE TO ERRORS_COLLECTION.
  • QUERY APP_NOTIFYING.
    • IF APP_NOTIFYING IS false:
      • QUERY ERRORS_COLLECTION.count() FROM 1 minute BEFORE TO ERROR_DATE. (*)
      • IF COUNT > 10:
        • SET APP_NOTIFYING TO true.
        • NOTIFY AND WAIT_FOR RESPONSE.
        • SET_TIMEOUT 1 minute TO:
          • SET APP_NOTIFYING to false.
          • RUN FROM WITH NOW_DATE (*).

This solution provides:

  • Faster access to the information than reading the file.
  • Scalation alternative if the web application starts to run in multiple servers.