Skip to content

Commit

Permalink
コスト管理(予算と割当て制限)のチュートリアルを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
TomokoKonishi committed Sep 11, 2024
1 parent 60f1cf4 commit d5fe3cb
Show file tree
Hide file tree
Showing 23 changed files with 210 additions and 0 deletions.
210 changes: 210 additions & 0 deletions tutorials/_intermediates/budget_quota.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
---
title: "予算と割当て制限を設定してコストを適正化する"
excerpt: "予期せぬコスト増加を避けるために、テナンシの管理者側で予算(Budget)機能と、割当て制限(Quota)機能を使って適切にコスト管理をしていきましょう"
order: "105"
tags:
- intermediate
- governance
header:
teaser: "/intermediates/budget_quota/cost.png"
overlay_image: "/intermediates/budget_quota/cost.png"
overlay_filter: rgba(34, 66, 55, 0.7)
#link:
---

**チュートリアル一覧に戻る :** [Oracle Cloud Infrastructure チュートリアル](../..)
<br>



必要な時に迅速にリソースを作成して利用することができるのがクラウドのメリットですが、使った分のコストは支払う必要があります。OCIの支払いの方式は、

- 前払い制で事前購入したサブスクリプションから使った分を消費していく方式(Universal Credit Annual Flex) と、
- 後払い制で使った分があとから請求される方式(Pay as you go, PAYG)

の大きく二種類がありますが、いずれの方式にしても、たとえば利用者が増えたりして利用が拡大していくと当初予定していた以上にリソースを使ってコスト消費も増えていく可能性があります。

予期せぬコスト増を避けるためには、テナンシの管理者側で現状のコスト状況を把握し、予算(Budget)機能と、割当て制限(Quota)機能を使って適切にコスト管理をしていきましょう。



[予算(Budget)](https://docs.oracle.com/ja-jp/iaas/Content/Billing/Concepts/budgetsoverview.htm)とは、コンパートメントごと、タグごと、テナンシごと(組織管理利用時)に予算金額の設定を行い、設定した金額を超えそうになった場合に管理者にアラートを通知できる機能です。実績値または予測値を用いて、予算金額の何%に達したらメール通知するかを決めることができます。

アラート・メールが通知されたら、管理者側で必要に応じて不要リソースの停止や削除などのコスト低減の対策を行います。

[割当て制限(Quota)](https://docs.oracle.com/ja-jp/iaas/Content/Quotas/home.htm)とは、コンパートメントごとにどのくらいの量のリソースを利用できるかの上限を設定できる機能です。割当て制限が設定されたコンパートメント内で利用者が割当てられた量を超えるリソースを作成しようとするとエラーになります。

本チュートリアルでは、まず「コスト分析」で現状のコストを確認してから、「予算」と「割当て制限」の両方の機能をためしてみます。



**所要時間 :** 作業時間 約30分。(ただし予算は24時間ごとに評価されるため、設定してから24時間たってから予算アラートのメールが受信できているかを確認します。)

**前提条件 :**

1. [チュートリアル入門編(その2)- クラウドに仮想ネットワーク(VCN)を作る](/ocitutorials/beginners/creating-vcn)を通じてVCNの作成が完了しており、そのVCN内にデフォルトのプライベート・サブネットとパブリック・サブネットが作成されていること
2. コンパートメント内になんらかの有償リソースが作成されていて、課金(コスト消費)が発生している状態であること。

**注意 :** チュートリアル内の画面ショットについては、現在のコンソール画面と異なっている場合があります

**目次 :**

1. [コスト分析でコストの確認](#anchor1)
2. [予算の設定](#anchor2)
2. [割当て制限の設定](#anchor3)

<br><br>

<a id="anchor1"></a>

# 1. コスト分析でコストの確認

予算を設定する前に、まずは現時点でのコスト分析を使用してコスト状況を確認していきます。

1. メニュー **`請求とコスト管理`****`コスト分析`** をクリックします。
![img01.png](img01.png)
2. コスト分析ページの **`フィルタ`****`コンパートメント`** を選択します。
![img02.png](img02.png)
3. コンパートメントの選択ウィンドウで対象となる **`コンパートメント名`** を入力して **`適用`** をクリックします。

![img03.png](img03.png)

1. 開始日と終了日はデフォルトの状態でその月の月初から最新までの期間が選択されていることを確認し、**`適用`**をクリックします。画面下の**`コスト詳細(JPY)`**の部分に選択したコンパートメントの金額が表示されます。当月分の **`累積コスト`** がいくらになっているかを確認します。この画像の場合は1,167円となります。
![img04.png](img04.png)







<a id="anchor2"></a>

# 2. 予算の設定

特定のコンパートメントに対しての予算と予算アラート設定して、その閾値に達した際のアラートをとばしてみます。今回は正しくアラート通知が来ることを確認するため、現時点の金額を超える閾値を設定してアラートメールが送信されるかを確認してみます。

1. メニュー **`請求とコスト管理`****`予算`** をクリックします。
![img05.png](img05.png)

2. **`予算の作成`**ボタンをクリックします。
![img06.png](img06.png)

3. 予算の作成画面で以下の項目を入力して、**`作成`**ボタンをクリックします。

- **`名前`** :任意の名前

- **`説明`**:任意の説明

- **`予算範囲`****コンパートメント**(デフォルト)を選択

- **`ターゲット・コンパートメント`**:対象のコンパートメントを選択

- **`スケジュール`****毎月**

- **`予算金額`** :先ほど**コスト分析で確認した累積金額の70%を超える値**を入力。ここでは 1500 を入力。

- **`予算処理を開始する月の日付`****1** (デフォルト)を入力

- **`予算アラート・ルール(オプション`**

- **`しきい値メトリック`****実績支出** を選択

- **`しきい値のタイプ`****予算の比率** を選択

- **`しきい値%`****70%**を入力

- **`電子メール受信者`** :アラートを受信するメールアドレスを入力

- **`電子メール・メッセージ`** :任意。ここでは「これはチュートリアルの予算アラートです。」と入力。

![img07.png](img07.png)
![img08.png](img08.png)

4. 予算が作成できました。まだ予算の評価が行われていないので、支出や期間内の%支出や予測は表示されません。予算アラートは24時間ごとに定期的に評価されるので、このまま1日置いてアラートのメールが送信されるのを待ちます。
![img09.png](img09.png)

5. 24時間以上たってから、指定したメール・アドレスにメールが届いているかを確認します。このようなメールが受信できていれば成功です。![img10.png](img10.png)

6. コンソールからも予算が評価されていることを確認します。メニュー **`請求とコスト管理`****`予算`** をクリックします。この例では、予算額を上回る126.09%の支出となっていて予算アラートの通知対象となったことがわかります。
![img11.png](img11.png)



以上で予算の設定と確認は完了です。実際の環境の予算額に応じて適切な設定を行い、必要があれば不要なリソースを削除したり停止して無駄なコスト消費を抑えるようにしましょう。



<a id="anchor3"></a>

# 3. 割当て制限の設定

次に、コンパートメントに対して特定のコンピュート・インスタンスのシェイプに対する割当て制限を作成し、設定した数より多くのリソースをコンパートメント内に作れないことを確認していきます。



1. メニュー **`ガバナンスと管理`****`割当て制限ポリシー`** をクリックします。
![img12.png](img12.png)

2. 割当て制限ポリシーのページで、**`割当て制限の作成`**をクリックします。
![img13.png](img13.png)

3. 割当て制限ポリシーの作成画面で以下の項目を入力し、**`割り当て制限ポリシーの作成`** をクリックします。一つ目のポリシーで、まず**全てのシェイプのコンピュートのコア数の割当てを削除**してから、二つ目のポリシーで**各シェイプごとの使用可能なコア数を2つまでに制限**します。割当て制限ポリシーは複数のポリシー文を記載する場合上から順に評価されます。

- **`名前`** :任意の名前

- **`説明 `** :任意の説明

- **`割当て制限ポリシー`** :以下の2つのポリシー文を順番に入力する。

- ```
zero compute-core quotas in compartment <コンパートメント名>
```

- ```
set compute-core quota /*-core-count*/, /*-core-ad-count*/ to 2 in compartment <コンパートメント名>
```

- ![img14.png](img14.png)

4. 割当て制限が作成できました。
![img15.png](img15.png)

5. メニュー **`ガバナンスと管理`****`制限、割当ておよび使用状況`** をクリックし、制限、割当ておよび使用状況のページを開きます。以下のフィルタを選択します。

- **`サービス`**`Compute` を選択
- **`スコープ`**`文字列:<リージョン名>-AD-1` を選択。以下の例の場合は「BUkv:AP-TOKYO-1-AD-1
- **`リソース`**`Cores for Standard.E4.Flex and BM.Standard.E4.128 instances` を選択
- **`コンパートメント`** :割当て制限で指定したコンパートメントを選択

![img16.png](img16.png)

6. 「使用可能」 の欄が **2** になっていることがわかります。つまり、このコンパートメントではStandard.E4のOCPU数としては 2 まで使用可能という割当て制限が設定されていることがわかります。
![img17.png](img17.png)

7. コンピュート・インスタンスを実際に作成してみます。メニュー **`コンピュート`****`インスタンス`** をクリックします。**`インスタンスの作成`** ボタンからインスタンスを作成します。コンピュート・インスタンス作成の方法は [チュートリアル入門編(その3) - インスタンスを作成する](https://oracle-japan.github.io/ocitutorials/beginners/creating-compute-instance/) を参考にしてください。

- シェイプの選択で **`VM.Standard.E4.Flex`****`1 OCPU`**で作成してください。(そのほかの設定、イメージやVCNなどはなんでも構いません。)
![img18.png](img18.png)

8. インスタンスのステータスが **`プロビジョニング中`** から **`実行中`** に変わり、インスタンスが正常に作成できたことを確認します。1OCPUであれば割当て制限の範囲内なので問題なく作成ができることが分かります。
![img19.png](img19.png)

9. 続いて、先ほどと同様にもう一つインスタンスを作成してみます。今度は、**2 OCPU** のインスタンスを作成してみます。つまり**合計 3 OCPU**となるので、割当て制限で設定された値を超えることになります。

- シェイプの選択で **`VM.Standard.E4.Flex`****`2 OCPU`** を選択してインスタンスを作成してください。(そのほかの設定、イメージやVCNなどはなんでも構いません。)
![img20.png](img20.png)

10. **`作成`** ボタンをクリックするとこのようなエラーが表示され、コンパートメント割当てを超えるためにインスタンスが作成できないことがわかります。
![img21.png](img21.png)



以上で、このチュートリアルは終わりです。

これらの機能を活用して、適切にコスト管理を行っていきましょう。





Binary file added tutorials/_intermediates/budget_quota/cost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutorials/_intermediates/budget_quota/img21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5fe3cb

Please sign in to comment.