2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

OCI VM(Linux/Windows)のディスク使用率を監視

Last updated at Posted at 2023-05-18

概要

OCI上に作成したVMのディスク使用率が閾値を超えた場合にアラートメールを送信する設定を行いました。

VMログ(/var/logやWindowsイベント)から特定メッセージを検出してメール送信をする流れはこちらの記事をご参照ください。

作成

■Linux Disk使用率超過メッセージ

以下のようにDFコマンドからDisk使用率を抜き出して80%を超えると/var/log/messagesにメッセージを出力するシェルスクリプトを作成してcrontabで定期実行します。

diskusage.sh
#!/usr/bin/bash

DISKTHRES=80
DISKUSAGE=$(df | grep '/dev/mapper/ocivolume-root' | awk '{ print $5 }' | sed 's/%//')

if [ $((DISKUSAGE)) -gt $((DISKTHRES)) ]; then
   logger -t diskusage 'Disk usage exceeds 80%'
fi

■Windows Disk使用率超過メッセージ
パフォーマンスモニターでDisk使用率を監視して80%を超えるとWindowsイベントsystemにメッセージを出力するタスクを起動します。

タスクスケジューラでDiskusagealertというタスクを作成します。
image.png

image.png

プログラム:eventcreate
引数: /t ERROR /id 100 /l system /so diskusagecheck /d "Disk usage exceeds 80%"
image.png

パフォーマンスモニターでディスク使用率を監視する定義を行います。
パフォーマンスモニターでデータコレクターセット>>ユーザー定義を選択して右クリック>>
新規作成>>データコレクターセットを選択
image.png
名前を入力して、手動で作成するを選択
image.png
パフォーマンスモニターの警告を選択
image.png
追加を選択
image.png
LogcalDisk %Free Spaceを選択し対象のドライブを選択
image.png
20(%)より下になると警告すよう設定し完了
image.png

Datacollector01を右クリックしてプロパティを開く
サンプルの間隔を設定
image.png
実行するタスクにDiskusagealertを設定
image.png

右クリックまたはcmdで開始
パフォーマンスモニターで開始
image.png

コマンドで開始

C:\Windows\system32>logman start Diskusage
The command completed successfully.

C:\Windows\system32>logman

Data Collector Set                      Type                          Status
-------------------------------------------------------------------------------
Diskusage                               Alert                         Running


The command completed successfully.

Windows再起動後にモニター再開するために、タスクスケジューラ等で設定が必要です。

■ログ・グループ作成
OCIメニューから監視および管理>>ロギング>>ログ・グループを選択しログ・グループ作成を押下
image.png

■ログ作成
OCIメニューから監視および管理>>ロギング>>ログを選択しカスタムログ作成
【Linux /var/log用の設定】
image.png
ファイルパスを/var/log/messagesに設定
image.png
【Windows イベント system用の設定】
image.png
Windowsイベントのsystemを指定
image.png

■サービスコネクタの作成
取得したログから"Disk usage exceeds"のメッセージを検出してメトリック値を作成します。
OCIメニューから監視および管理>>ロギング>>サービスコネクタを選択しサービスコネクタ作成
【Linux /var/log用の設定】
image.png
【Windows イベント system用の設定】
image.png

■アラームの作成
メトリックを元にアラームを生成します。
OCIメニューから監視および管理>>モニタリング>>アラーム定義をアラーム作成
image.png

■稼働確認
Linux/WindowsいずれもDisk使用率が80%を超えると以下のようにアラート検知しました。
image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?