Uses Concepts of Scheduled Threads to monitor uptime of an application.
The API also provides with simple avg uptime for an API from the time the monitoring Job was created.
A user of the API should be able to register new checks for a website.
A check should have a name, website url, and frequency.
Frequency can be either in minutes or hours.
We choose a minute interval if we want checks to be performed at intervals less than an hour.
Any check more than one hour needs to be configured in hours.
For example, frequency can have a value between 1minute to 59 minutes.
Beyond that it will be in hours like 1 hour, 2 hours. Hours can be maximum till 24 hours.
The above also implies we can’t define frequency as 1 hour 25 mins. For this, we either can have 1 hour or 2 hour.
- Java 8+
- Maven
- Docker (optional)
mvnw clean install -Dmaven.test.skip=true
mvnw spring-boot:run
OR
java -jar target/xup.jar
mvnw clean install -Dmaven.test.skip=true
docker build -t xup_app .
docker run -d -p 8080:8080 xup_app
-
Create A Check
curl --location --request POST 'http://localhost:8080/api/monitors' \ --header 'Content-Type: application/json' \ --data-raw '{ "name": "google-check", "uri": "https://www.google.com", "frequency": 1 }'
-
Get All Checks
curl --location --request GET 'http://localhost:8080/api/monitors'
-
Get Check By Name
curl --location --request GET 'http://localhost:8080/api/monitors/google-check'
-
For Requirement
A user of the API should be able to register new checks for a website. A check should have a name, website url, and frequency. Frequency can be either in minutes or hours. We choose a minute interval if we want checks to be performed at intervals less than an hour. Any check more than one hour needs to be configured in hours. For example, frequency can have a value between 1minute to 59 minutes. Beyond that it will be in hours like 1 hour, 2 hours. Hours can be maximum till 24 hours. The above also implies we can’t define frequency as 1 hour 25 mins. For this, we either can have 1 hour or 2 hour.
I have taken the user input as minutes and validated on the backend for the above stated logic.
I have done this so that the frequency input can remain flexible to changes.A different approach would be to define [Number, Unit] where Unit tells us the Measure in Minutes/Hours
The API doc can be found at Swagger
- Monitors once created cannot be cancelled/updated
- If the system restarts, all scheduled tasks get lost
- Possible Solution -> Can Read From DB to restart the monitors
- With Each Monitor Maintain a boolean to indicate if cancelled or not
- More Granlular Exceptions with Custom Exeptions
- Id For A Monitor can be autogenerated as UUID instead of limiting as a unique string