TT Lab
Get started
Learn Learning paths Courses

Capacity Planning and Change Management — Calculate When It Fills, Write Down When to Stop

Calculate When the Disk Fills and Set the Order-By Date

Continue in TT Lab

Goal

From a 120-day disk usage table, remove the one-time step to find the organic growth rate, calculate the days remaining to the threshold and the order deadline, and then turn the same calculation into a script that can run on any table.

Why it matters

The question "what percent is the disk at" is answered by the monitoring screen. What an infrastructure engineer must answer is "by when do we have to order the expansion," and that answer comes from three numbers: growth speed, threshold, and lead time. If you mix a one-time increase such as a migration into the trend, you get over-ordering, and if you ignore growth, you get a stockout. This lab has you find two slopes (the whole period and after the step) side by side so that you see the difference with your own eyes.

The material is in /opt/lab/capacity/forecast/, and the grader computes the expected values from the original material. The script in the last step is also run on a table created anew each time it is graded.

Steps

  1. Copy disk_usage.csv, holdout.csv, and policy.env from /opt/lab/capacity/forecast/ to /root/cap/.
  2. Write date=, used_gb=, and used_pct= (relative to capacity, to one decimal place) to /root/cap/01-now.txt.
  3. Write the least-squares slope over the whole 120 days to /root/cap/02-naive.txt as slope_gb_per_day= (to two decimal places).
  4. Write the day with the biggest increase over the previous day and that increase to /root/cap/03-step.txt as step_date= and step_gb=.
  5. Write the slope from the day after the step to /root/cap/04-organic.txt as slope_gb_per_day=.
  6. Using the organic slope, write days_to_threshold=, threshold_date=, and days_to_full= to /root/cap/05-runway.txt (round the days up).
  7. Write order_by= (the threshold date − LEAD_DAYS) and days_left= to /root/cap/06-order.txt.
  8. Make /root/cap/forecast.py <csv> <용량GB> <임계%> print one line of JSON, {"step_date", "organic_slope", "days_to_threshold"} (the arguments are the CSV file, the capacity in GB, and the threshold percent).

Notes

Copy the material

Copy the set of files in /opt/lab/capacity/forecast/ (disk_usage.csv, holdout.csv, policy.env) to /root/cap/. Do not modify the contents.

Move the directory contents with cp. If you modify the material, the grader tells you it differs from the original.

Write down the current state

Write three lines to /root/cap/01-now.txt: date=<표의 마지막 날짜> (the last date in the table), used_gb=<그날 사용량> (that day's usage), and used_pct=<policy.env 의 CAPACITY_GB 대비 백분율, 소수 첫째 자리> (the percentage relative to CAPACITY_GB in policy.env, to one decimal place).

Look at the last line with tail -1. The percentage is used ÷ capacity × 100, rounded to one decimal place.

Slope over the whole period

Compute the least-squares slope (GB/day) over the whole 120 days and write it to /root/cap/02-naive.txt as slope_gb_per_day=<값, 소수 둘째 자리> (the value, to two decimal places). x is the number of days since the first day.

The slope is Σ(x−x̄)(y−ȳ) / Σ(x−x̄)². Convert the date strings with date.fromisoformat and use the difference from the first day (.days) as x.

Find the step

Find the day whose usage grew the most over the previous day and write step_date=<그날> (that day) and step_gb=<그날의 증가량, 정수> (that day's increase, as an integer) to /root/cap/03-step.txt.

Compute the difference between every pair of adjacent lines and pick the biggest. It stands out because it is tens of times the usual daily increase.

Organic slope

Recompute the least-squares slope using only the days from the day after the step through the last day, and write it to /root/cap/04-organic.txt as slope_gb_per_day=<값, 소수 둘째 자리> (the value, to two decimal places).

Apply the same formula as in step 3 to only the rows after step_date. If it differs greatly from the whole-period slope, that difference is the share where the step was mixed into the slope.

Days remaining

Calculate with the organic slope and write three lines to /root/cap/05-runway.txt: days_to_threshold=<THRESHOLD_PCT 까지 남은 날수, 올림> (the days remaining to THRESHOLD_PCT, rounded up), threshold_date=<마지막 날짜 + 그 날수> (the last date plus that number of days), and days_to_full=<100% 까지 남은 날수, 올림> (the days remaining to 100%, rounded up).

Days remaining = ceil((capacity × ratio − current usage) ÷ slope). Use math.ceil, and add dates with timedelta(days=…).

Order deadline

Write order_by=<threshold_date − LEAD_DAYS> and days_left=<마지막 날짜부터 order_by 까지의 날수> (the number of days from the last date to order_by) to /root/cap/06-order.txt.

LEAD_DAYS is in policy.env. If days_left is a single digit, it should be the first sentence of this report.

A forecast script that runs on any table

Create /root/cap/forecast.py. When called as python3 forecast.py <csv> <용량GB> <임계%> (the CSV file, the capacity in GB, and the threshold percent), it must print one line of JSON to standard output, {"step_date": "YYYY-MM-DD", "organic_slope": <숫자>, "days_to_threshold": <정수>} (a number and an integer). The calculation rules are the same as in steps 4–6. The grader runs this script on holdout.csv and on a table it creates anew each time it grades.

Bundle the calculation of steps 4–6 into functions and take the file and the two numbers from sys.argv. The output needs just one json.dumps. Run it first with python3 forecast.py holdout.csv 1000 80.