Interview Prep/Python for DevOps/Testing, CI/CD, packaging & services

You need to add Prometheus metrics to a Python batch job that runs every 10 minutes. How?

IntermediateScenarioTesting, CI/CD, packaging & services
Answer

Situation read → Short-lived process; Prometheus cannot scrape it reliably.

What I'd do →

  1. Use a dedicated CollectorRegistry, record job_duration_seconds, job_items_processed_total and job_last_success_timestamp_seconds.
  2. push_to_gateway("pushgateway.monitoring:9091", job="reconciler", registry=reg) at the end (also on failure, with a failure gauge).
  3. Alert: time() - job_last_success_timestamp_seconds > 1800.
  4. If it runs on a host with node exporter, the textfile collector is an alternative.

Why → Pushgateway is designed for batch jobs; the last-success timestamp catches every failure mode.

Interview tip → Say Pushgateway is only for batch jobs, not for services.

All Python for DevOps questions Roadmap: Python for automation

More on Testing, CI/CD, packaging & services