Your question is Automate an Operational Task. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Nielsen ONE operations periodically reviews host telemetry to identify sustained CPU pressure. Given CPU samples for multiple hosts, return one alert for every run of consecutive high-usage windows.
For each host, sort samples by timestamp. A window is high usage when the arithmetic mean of its window_size consecutive CPU readings is greater than or equal to threshold. A run qualifies when it contains at least required_windows consecutive high-usage windows. Return one alert for each qualifying run.
Implement detect_resource_alerts(samples, window_size, threshold, required_windows).
samples is a list of dictionaries with integer host, integer timestamp, and numeric cpu fields.window_size, required_windows, and timestamps are positive integers.threshold and cpu are floating-point values. CPU values are percentages from 0 through 100.host and then start_timestamp.host, start_timestamp, and end_timestamp. The interval spans from the first sample in the qualifying run to the last sample in its final qualifying window.def detect_resource_alerts(samples, window_size, threshold, required_windows):