During the second round of an SRE interview, I was asked to write two Python scripts on CodeShare.
1. Disk Usage Monitoring Script
Write a Python script that:
> Checks disk usage on the system
Parses the output to identify filesystems using more than 80% of available disk space
> Prints a warning for each filesystem that exceeds the threshold
> Exits with a non-zero status code if any filesystem breaches the threshold, making it suitable for use in CI/CD pipelines or cron jobs
2. Microservice Health Check Script
Write a Python script that:
> Checks the health of multiple HTTP service endpoints
> Measures and records response times
Flags services as:
> DOWN if they return a non-200 status code or timeout
> SLOW if the response time exceeds 2 seconds
> Generates a structured health report with timestamps
> Exits with a non-zero status code if any service is unhealthy, allowing integration with CI/CD pipelines, monitoring systems, or alerting workflows