Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Health Checker

A simple Python command-line tool that pings public REST APIs, logs their HTTP status codes and response times, and reports a health summary.

Features

  • Check one or more URLs passed directly via --urls, or load a list from a file
  • Logs results to both the console and a log file (api_health.log by default)
  • Captures connection errors and timeouts gracefully (no crashes on bad hosts)
  • Supports repeated check cycles on an interval (basic uptime monitoring)
  • Exits with a non-zero status code if any endpoint is unhealthy, so it can be plugged into CI/CD pipelines or cron jobs

Setup

pip install -r requirements.txt

Usage

Check specific URLs:

python health_checker.py --urls https://api.github.com https://httpbin.org/status/500

Check URLs listed in a file (one per line):

python health_checker.py --file urls.txt

Repeat checks every 60 seconds, 5 times:

python health_checker.py --file urls.txt --interval 60 --repeat 5

Custom timeout and log file:

python health_checker.py --file urls.txt --timeout 5 --log-file my_log.log

Example output

2026-06-30 10:00:01 [INFO] Starting health checks for 4 URL(s).
2026-06-30 10:00:01 [INFO] https://api.github.com -> 200 OK (142.31 ms)
2026-06-30 10:00:02 [INFO] https://httpbin.org/status/200 -> 200 OK (98.04 ms)
2026-06-30 10:00:02 [WARNING] https://httpbin.org/status/500 -> 500 UNHEALTHY (101.22 ms)
2026-06-30 10:00:03 [INFO] https://jsonplaceholder.typicode.com/posts/1 -> 200 OK (88.76 ms)
2026-06-30 10:00:03 [INFO] Summary: 3/4 endpoints healthy

Project structure

api-health-checker/
├── health_checker.py   # main script
├── requirements.txt    # dependencies
├── urls.txt             # sample list of URLs to check
└── README.md

What this demonstrates

  • Backend scripting and automation with Python
  • HTTP request handling using the requests library
  • Structured error handling (timeouts, connection errors, bad status codes)
  • CLI design with argparse
  • Logging best practices (file + console handlers)

About

A Python CLI tool that pings REST APIs, logs HTTP status codes and response times, and reports endpoint health.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages