a stray sheep

お仕事周りの雑記帳

windows_exporter でCPU温度をチェックする

やりたいこと

  • windows_exporter を触ってみる(ひさびさに)。
  • windows_exporter で温度を確認する。
  • PCの温度(=CPU温度)をチェックし、windows_exporterの値の正しさを確認する。

windows_exporterのインストール

  1. https://github.com/prometheus-community/windows_exporter/releases にアクセス
  2. 最新版 v0.20.0を選択して、Assetsから windows_exporter-0.20.0-amd64.exe と windows_exporter-0.20.0-amd64.msi をダウンロード ※どっちかで良いけど、試したいことがあるので両方。

windows_exporterで温度を確認する

温度を確認するために、コレクタ thermalzone のみを使用してメトリクスを収集する。
windows_exporterはインストーラを使ってWindowsサービスとしてセットアップする方法と、実行ファイル単体で実行する方法があるが、それぞれ動かしてみる。

実行ファイル単体で動かす

windows_exporter-0.20.0-amd.exe を使用。

C:\Temp>.\windows_exporter-0.20.0-amd64.exe  --collectors.enabled thermalzone
time="2023-02-17T22:44:13+09:00" level=info msg="Running as HOSTNAME\\USERNAME" source="exporter.go:340"
time="2023-02-17T22:44:13+09:00" level=info msg="Enabled collectors: thermalzone" source="exporter.go:345"
time="2023-02-17T22:44:13+09:00" level=info msg="Starting windows_exporter (version=0.20.0, branch=heads/tags/v0.20.0, revision=677a7c8d67deb99b92f4f24b8c890e0a4c152b0c)" source="exporter.go:397"
time="2023-02-17T22:44:13+09:00" level=info msg="Build context (go=go1.19.1, user=runneradmin@fv-az319-971, date=20221006-09:22:49)" source="exporter.go:398"
time="2023-02-17T22:44:13+09:00" level=info msg="Starting server on :9182" source="exporter.go:401"
time="2023-02-17T22:44:13+09:00" level=info msg="TLS is disabled." source="gokit_adapter.go:38"

http://localhost:9182/metrics にアクセスして収集したメトリクスを確認する。以下は、thermalzone に関するものだけ抜粋して表示。

windows_thermalzone_percent_passive_limit{name="\\_TZ.TZS0"} 100
windows_thermalzone_percent_passive_limit{name="\\_TZ.TZS1"} 100
# HELP windows_thermalzone_temperature_celsius (Temperature)
# TYPE windows_thermalzone_temperature_celsius gauge
windows_thermalzone_temperature_celsius{name="\\_TZ.TZS0"} 45.05000000000001
windows_thermalzone_temperature_celsius{name="\\_TZ.TZS1"} 44.05000000000001
# HELP windows_thermalzone_throttle_reasons (ThrottleReasons)
# TYPE windows_thermalzone_throttle_reasons gauge
windows_thermalzone_throttle_reasons{name="\\_TZ.TZS0"} 0
windows_thermalzone_throttle_reasons{name="\\_TZ.TZS1"} 0

windows_thermalzone_temperature_celsius の値が、44、45なので、摂氏で扱っているようだ。

サービスとして動かす

windows_exporter-0.20.0-amd.msi を使用し、まずはインストールする。

C:\Temp>msiexec /i windows_exporter-0.20.0-amd64.msi  ENABLED_COLLECTORS thermalzone

これを実行すると、インストーラが起動し、windows_exporterがインストールされる。サービスで「windows exporter」を確認できる。

同様に、http://localhost:9182/metrics にアクセスして収集したメトリクスを確認する。以下は、thermalzone に関するものだけ抜粋して表示。

# HELP windows_thermalzone_percent_passive_limit (PercentPassiveLimit)
# TYPE windows_thermalzone_percent_passive_limit gauge
windows_thermalzone_percent_passive_limit{name="\\_TZ.TZS0"} 100
windows_thermalzone_percent_passive_limit{name="\\_TZ.TZS1"} 100
# HELP windows_thermalzone_temperature_celsius (Temperature)
# TYPE windows_thermalzone_temperature_celsius gauge
windows_thermalzone_temperature_celsius{name="\\_TZ.TZS0"} 44.05000000000001
windows_thermalzone_temperature_celsius{name="\\_TZ.TZS1"} 41.05000000000001
# HELP windows_thermalzone_throttle_reasons (ThrottleReasons)
# TYPE windows_thermalzone_throttle_reasons gauge
windows_thermalzone_throttle_reasons{name="\\_TZ.TZS0"} 0
windows_thermalzone_throttle_reasons{name="\\_TZ.TZS1"} 0

パフォーマンスモニタを使って温度を確認する

windows_exporterの値が正しいかを確認するために、パフォーマンスモニターを使用する。

<確認方法>

  1. [コントロールパネル]→[管理ツール]→[パフォーマンスモニター] を開く
  2. パフォーマンスモニターで、[パフォーマンス]→[モニターツール]→[パフォーマンスモニター] を開く
  3. 上部メニューの「+」をクリック
  4. 左側の使用可能なカウンターで、[Thermal Zone Information]→[Temperature]→[<すべてのインスタンス>]を選択して、「追加」をクリック
  5. 上部メニューの左から2個目をクリックして、プロパティを開く
  6. [グラフ]タブで、"垂直スケール"の最大値を"400"に設定する ※温度がケルビンなので変更しないとグラフに見えない。摂氏に換算するには -273する。

図では、平均が317.47となっているので、317.47 - 273 = 摂氏44.47℃ となる。

windows_exporterで抽出した値と同じような値であることが確認でき、windows_exporterで問題なく温度を収集できることを確認できた。