概要
Hyper-Vクラスタ環境のCluster Shared VolumeをPrometheusで監視する。
- PrometheusでCluster Shared Volumeのmetricsを取得して監視する
- wmi_exporterのtextfile collectorを使用する
- Cluster Shared Volumeのボリューム情報はpowershellを使って取得する
- powershellスクリプトは、タスクスケジューラで1日1回実行する
ちなみに、wmi_exporterではローカルディスクのメトリクスを取得できるが、Cluster Shared Volumeのメトリクスは取得できない。
参考
以下を参考にしました。 github.com
要約すると、workaround として、スケジュールされたタスクと組み合わせてtextfile collectorを使って実現できる。
また、以下の投稿のpowershellスクリプトを参考にしました。
@jrcresawn you could try my own version, which I wrote a few days ago.
https://gist.github.com/basroovers/91c99d919cb0769b3d257692ed4ef99e
I'm running it via Task Scheduler but I rather have it started from wmi_exporter itself, the way Telegraf does it.
textfile collectorについて
textfile collectorについては、こちら github.com
- 他の処理によって書かれたファイルから、メトリクスを作成する
- デフォルトで有効なので、簡単に使える。
- デフォルトでは、C:\Program Files\wmi_exporter\textfile_inputs\ フォルダ配下の.promファイルのみが読み取られる。
- ファイルの場所は、--collector.textfile.directory オプションで指定可能
- このtextfile_inputs フォルダは、wmi_exporterのインストール時に作成されている
- .promファイルは、空の行で終わる必要がある。
環境
- 仮想化ホスト Windows Server 2012 R2
- wmi_exporter 0.10.2
Powershellスクリプトの作成
要件
- Cluster Shared Volumeのディスク容量情報をファイルに出力する
- 使用率等を計算したいので、ボリュームのサイズと、空き容量をそれぞれ出力する
csv-to-prom.ps1
※powershellの構文は、環境によって異なる。
# variables $csv_size_promLocation = "C:\Program Files\wmi_exporter\textfile_inputs\csv_size.prom" $csv_free_promLocation = "C:\Program Files\wmi_exporter\textfile_inputs\csv_free.prom" Import-Module FailoverCluster $clustername = Get-Cluster $objs = @() $CurrentFree = @{} $csvs = Get-ClusterSharedVolume foreach ( $csv in $csvs ) { $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo foreach ( $csvinfo in $csvinfos ) { $obj = New-Object PSObject -Property @{ Name = $csv.Name Path = $csvinfo.FriendlyVolumeName Size = $csvinfo.Partition.Size FreeSpace = $csvinfo.Partition.FreeSpace UsedSpace = $csvinfo.Partition.UsedSpace PercentFree = $csvinfo.Partition.PercentFree } $objs += $obj } } Set-Content -Path $csv_size_promLocation -Encoding Ascii -Value "" Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "# HELP win_csv_disksize Clustered Shared Volume disk size. `n" Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "# TYPE win_csv_disksize gauge `n" Set-Content -Path $csv_free_promLocation -Encoding Ascii -Value "" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "# HELP win_csv_freespace Clustered Shared Volume disk size. `n" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "# TYPE win_csv_freespace gauge `n" foreach ( $k in $objs) { Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "win_csv_disksize{name=""$($k.Name)""} $($k.Size)`n" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "win_csv_freespace{name=""$($k.Name)""} $($k.FreeSpace)`n" }
出力結果
csv_size.prom
# HELP win_csv_disksize Clustered Shared Volume disk size. # TYPE win_csv_disksize gauge win_csv_disksize{name="volume1"} 2997416357888 win_csv_disksize{name="volume2"} 2997416357888 win_csv_disksize{name="volume3"} 2997416357888
csv_free.prom
# HELP win_csv_freespace Clustered Shared Volume free space. # TYPE win_csv_freespace gauge win_csv_freespace{name="volume1"} 807385362432 win_csv_freespace{name="volume2"} 1439418380288 win_csv_freespace{name="volume3"} 3793255264256
wmi_exporterでの確認
C:\Program Files\wmi_exporter\textfile_inputs\フォルダに、.promファイルが生成されると、wmi_exporterのメトリクスが表示される。
win_csv_freespaceの場合
Element | Value |
---|---|
win_csv_freespace{instance="Server01:9182", job="windows", name="volume1"} | 807385362432 |
win_csv_freespace{instance="Server01:9182", job="windows", name="volume2"} | 1439418380288 |
win_csv_freespace{instance="Server01:9182", job="windows", name="volume3"} | 3793255264256 |
タスクスケジューラの登録
- タスクスケジューラを起動
- タスクスケジューラライブラリに、新規フォルダーを作成(OS標準のものと分けるために)
- タスクの作成
- [全般]タブ
- 名前: csv-to-prom.ps1の実行
- 説明:任意
- 「ユーザーがログオンしているかどうかにかかわらず実行する」を選択
- 「最上位の特権で実行する」をチェック
- [トリガー]タブ
- 毎日、開始の日時と時刻(任意)
- [操作]タブ
- プログラム/スクリプト: C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe
- 引数の追加: -c "C:\Scripts\csv-to-prom.ps1"
- 実行するアカウントを入力
Grafanaでの表示
最終的に、以下のようなグラフを生成した。設定方法は、省略。
Volume Name | Size | Used | Avail | Usage |
---|---|---|---|---|
volume1 | 3.00TB | 2.19TB | 807.63GB | 7.2% |
volume2 | 3.00TB | 1.56TB | 1.44TB | 52.0% |
volume3 | 3.00TB | 2.40TB | 593.30GB | 80.2% |
このグラフは、以下のダッシュボード・テンプレートのグラフ「Disk Space Used Base(EXT4/XFS)」を参考に作成した。
以上