How the bill adds up
A cloud bill is a sum of meters, each rate × quantity. Servers are billed per hour while switched on, busy or idle. Storage is billed per GB-month, data sent out per GB. This Python function prices servers.
Four web servers run all month. An average month has 730 hours (365 × 24 ÷ 12). At an example rate of $0.10 per server-hour, cost(4, 730) is 4 × 730 × 0.10 = $292.
Two test (dev) servers also run 730 hours: cost(2, 730) = $146. Nobody uses them at night or at weekends, but switched on means billed. The month comes to $438.
Find and cut the waste
Who spends what? Cost allocation tags, labels such as env=prod and env=dev, mark each resource. The bill then splits by tag: dev is $146 of $438, a third, for servers idle most of the week.
Monitoring shows the four web servers average 20% CPU: more than the load needs. Two servers at 40% still leave headroom. Rightsizing matches capacity to real use: cost(2, 730) = $146, half the web bill.
The dev servers are only needed in working hours: 10 hours a day, 22 workdays, 220 hours. A scheduler stops them at night and at weekends. cost(2, 220) = $44 instead of $146.
The web servers run every hour of every month. Committing to that use for one or three years earns a discount (AWS Savings Plans, Google committed use discounts). At an example 30% off: cost(2, 730, 0.07) = $102.20.
print(web + dev) shows 146.2. The same service now costs $146.20 a month instead of $438: two thirds less. Users see no change; only paid-for idleness was removed.
Keep it in check
A budget states the expected spend, here $200 a month, with an alert at 80% ($160). Budget tools warn you when actual or forecast cost crosses it. $146.20 is 73%: fine. The old $438 would have tripped it.
FinOps, the practice of managing cloud spend as a team, tracks unit cost: spend ÷ useful work. With 10,000 orders, $146.20 ÷ 10,000 ≈ 1.5 cents an order. If orders double and the bill does not, each order gets cheaper.
What happens
;; step 1/10 · meters
bill = Σ rate × quantity
servers $ per server-hour (on = billed)
storage $ per GB-month
egress $ per GB sent out
def cost(n, hours, rate=0.10):
return round(n * hours * rate, 2)
The $0.10 per server-hour rate, the 30% discount, the CPU figures, the $200 budget and the 10,000 orders are example numbers. Real prices vary by provider, region and machine type; the arithmetic is exact. A stopped instance has no hourly compute charge, but its attached disks (EBS volumes) are still billed, so scheduled dev servers cost a little more than $44 in real life.