Skip to content
Nafis-RohanPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

API Monitoring Dashboard

A Django + Django REST Framework application for registering API endpoints, running automated health checks, storing results, and viewing a live dashboard with uptime percentages and response-time history.

Tech Stack

  • Django & Django REST Framework
  • PostgreSQL
  • requests for HTTP checks
  • django-environ for environment configuration
  • Django templates + Chart.js for the dashboard UI

Setup

  1. Clone the repository

    git clone <your-repo-url>
    cd DjangoAPI
  2. Create and activate a virtual environment

    python -m venv venv
    # Windows
    .\venv\Scripts\Activate.ps1
    # macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables

    Copy .env.example to .env and fill in real values:

    copy .env.example .env   # Windows
    cp .env.example .env     # macOS/Linux

    Required variables:

    • DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT — PostgreSQL connection
    • SECRET_KEY — Django secret key
    • RUN_CHECKS_SECRET_KEY — secret for the external cron trigger endpoint
  5. Create the PostgreSQL database

    Ensure PostgreSQL is running and create a database matching DB_NAME (default: api_db).

  6. Run migrations

    python manage.py migrate
  7. Create a superuser (required for admin and API write access)

    python manage.py createsuperuser
  8. Start the development server

    python manage.py runserver

Running Checks Manually

python manage.py check_endpoints

This checks all active endpoints and prints a summary to stdout.

External Cron Scheduling (/api/run-checks/)

The POST /api/run-checks/ endpoint runs the same logic as the management command. It is protected by the X-RUNNER-KEY header, which must match RUN_CHECKS_SECRET_KEY in your .env.

Example request:

curl -X POST http://127.0.0.1:8000/api/run-checks/ \
  -H "X-RUNNER-KEY: your-run-checks-secret-key-here"

Successful response:

{"checked": 3}

Using cron-job.org (free)

  1. Deploy the app so it is reachable on the public internet.
  2. Create a free account at cron-job.org.
  3. Add a new cron job:
    • URL: https://your-domain.com/api/run-checks/
    • Method: POST
    • Schedule: e.g. every 5 minutes
    • Custom header: X-RUNNER-KEY: <your RUN_CHECKS_SECRET_KEY value>
  4. Save and enable the job.

API Overview

Endpoint Methods Auth
/api/endpoints/ GET (public), POST/PUT/PATCH/DELETE (staff) Staff for writes
/api/endpoints/{id}/stats/ GET (public) None
/api/checks/ GET (public) None
/api/run-checks/ POST X-RUNNER-KEY header only

Screenshot

Assumptions

  • Single-user / single-tenant: no visitor login or multi-project support.
  • Checks use a 10-second timeout and compare the HTTP status code to expected_status_code.
  • Uptime percentage is calculated over the last 50 checks per endpoint.
  • Chart.js is loaded from the jsDelivr CDN (requires internet access in the browser).

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages