ENع
→Cloud cost
الدرس 21 · التشغيل

Cloud cost

لم يُترجم بعد؛ يُعرض باللغة الإنجليزية

14 دقيقة10 خطوات5 أسئلةAdvanced
عن هذا الدرس

A cloud bill is a sum of meters, each rate × quantity, and a server is billed for every hour it is switched on, busy or idle. Follow one month's bill, written as a short Python program: four always-on web servers and two idle test servers cost $438. Tag the costs to find their owners, rightsize, switch off what nobody uses at night and commit to the steady part, and the same service costs $146.20. Then keep it there with a budget alert and a cost per order.

ستتعلّم

حدّد ما تشعر بأنك أتقنته. هذا التقييم الذاتي لا يؤثر في درجة الدرس.

شكل 21 · تفاعلي
01 / 10

Every resource has a meter

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.

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)
جارٍ تحميل الرسم…
أو ← →
اقرأ الدرس خطوة بخطوة
  1. Every resource has a meter

    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.

    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)
  2. Always-on web 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.

    web = cost(4, 730)
      4 servers × 730 h × $0.10 = $292.00
    
    730 h = 365 days × 24 h ÷ 12 months
    bill so far: $292.00
  3. Idle test servers

    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.

    dev = cost(2, 730)
      2 servers × 730 h × $0.10 = $146.00
      used: working hours only
      billed: every hour they are on
    
    bill: $438.00 a month
  4. Tag to find the owner

    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.

    resource      tag        $/month
      web × 4     env=prod   292.00
      dev × 2     env=dev    146.00
    
    dev = 146 / 438 = 1/3 of the bill
    tags must be activated for billing
  5. Rightsize the web tier

    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.

    web = cost(2, 730)
      before: 4 servers at 20% CPU
      after:  2 servers at 40% CPU (same load)
      $292.00 → $146.00
    
    bill: $292.00
  6. Switch off when idle

    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.

    dev = cost(2, 220)
      10 h × 22 workdays = 220 h
      2 servers × 220 h × $0.10 = $44.00
      stopped servers: no hourly charge
      (their disks are still billed)
    
    bill: $190.00
  7. Commit to steady use

    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.

    web = cost(2, 730, 0.07)
      $0.10 × (1 − 0.30) = $0.07 per hour
      2 × 730 × $0.07 = $102.20
      commit only to the steady base
    
    bill: $146.20
  8. The new bill

    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.

    print(web + dev)
    146.2
    
    before  $438.00
    after   $146.20
    saved   $291.80  (67%)
  9. Set a budget and alert

    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.

    budget  $200.00 / month
    alert   at 80% = $160.00 (actual or forecast)
    
    now     $146.20 = 73.1%   ok
    before  $438.00 = 219%   alert
  10. Measure cost per order

    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.

    unit cost = spend ÷ useful work
      $146.20 ÷ 10,000 orders
      = $0.01462 ≈ 1.5¢ per order
    
    was $438.00 ÷ 10,000 = $0.0438

اختبار يتاح بعد الخطوة الأخيرة.