This project is a solution for collecting statistics from a network of IP addresses, providing insights into ping performance, packet loss, and more. It demonstrates a minimalistic Ruby non-Rails tech stack and is containerized using Docker for easy setup.
- Language: Ruby
- Framework: Grape
- Database: PostgreSQL (with Timescale Hypertables), Redis
- ORM: Sequel
- Testing: RSpec
- Containerization: Docker
- Data Ingestion: Periodically collects ping data, such as Round-Trip Time (RTT), packet loss status, timestamps, etc in background Sidekiq jobs.
- Data Processing: Processes and stores data in PostgreSQL, utilizing hypertables index for efficient time-series management.
- Statistics Calculation: Utilizes
QueryStatisticsService
for aggregating statistical information like average RTT, maximum/minimum RTT, median RTT, standard deviation of RTT, and loss percentage. - API Exposure
The API is designed to manage IP addresses, allowing enabling/disabling of statistics collection, retrieval of statistics, and deletion of IP addresses. It's built using the Grape framework.
- Endpoint:
POST /api/v1/ips
- Parameters:
ip
(String): IP Address (IPv4/IPv6)enabled
(Boolean): Enable flag
- Response: IP object
- Endpoint:
POST /api/v1/ips/:id/enable
- Response: IP object
- Endpoint:
POST /api/v1/ips/:id/disable
- Response: IP object
- Endpoint:
GET /api/v1/ips/:id/stats
- Parameters:
time_from
(DateTime): Start time for statisticstime_to
(DateTime): End time for statistics
- Response: Statistics object
- Endpoint:
DELETE /api/v1/ips/:id
- Response: Success message
docker compose up
Access the Application:
Open your browser or API client and navigate to http://localhost:3000
endpoints.
To run the tests, execute the following command inside the Docker container:
docker exec -it <container_id> rspec spec