対象:自宅PC(Windows 10/11)
ねらい:監視の入口として「自分のPC」を、**可視化(グラフ)**まで一気に到達させる
この記事でやること(ゴール)
- Windows上で Grafana Alloy を動かして、Windowsメトリクス(CPU/メモリ/ディスクなど)を取得
- Prometheus に保存
- Grafana でグラフ化(=「時系列データを触った」体験が完了)
全体構成(ミニマム)
- Windows(ホスト):Grafana Alloy(サービス起動)
- Docker:Prometheus / Grafana
Alloy の prometheus.exporter.windows は windows_exporter を内包し、Windowsの各種メトリクスを出します。
enabled_collectors のデフォルトは ["cpu","logical_disk","net","os","service","system"] です(必要に応じて追加します)。
前提
- Windows に Docker Desktop が入っている
- (推奨)Alloy も Windows にインストール済み(サービスで動く)
1. Docker で Prometheus と Grafana を起動する
フォルダ例:C:\monitoring\
C:\monitoring\
docker-compose.yml
prometheus\
prometheus.yml
grafana\
provisioning\
datasources\
datasource.yml
docker-compose.yml
services:
prometheus:
image: prom/prometheus:latest
container_name: prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
- --web.enable-remote-write-receiver
ports:
- "9090:9090"
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
- grafana_data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning:ro
depends_on:
- prometheus
volumes:
prometheus_data:
grafana_data:
prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
grafana/provisioning/datasources/datasource.yml
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
起動:
cd C:\monitoring
docker compose up -d
確認:
- Prometheus:
http://localhost:9090 - Grafana:
http://localhost:3000(admin / admin)
2. Alloy(Windowsサービス)で Windows メトリクスを取り、Prometheus に送る
2.1 設定ファイルの場所
Alloy のデフォルト設定ファイルは以下です。
%PROGRAMFILES%\GrafanaLabs\Alloy\config.alloy
2.2 config.alloy(最小構成)
Prometheus が remote_write を受けるには --web.enable-remote-write-receiver が必要で、受信エンドポイントは /api/v1/write です。
%PROGRAMFILES%\GrafanaLabs\Alloy\config.alloy を、まずは以下のようにします(既存がある場合は上書きではなく置換・バックアップ推奨)。
// ---- 1) Windows exporter(内蔵) ----
prometheus.exporter.windows "selfpc" {
// まずは “よく使う”ものを明示(必要に応じて増やす)
enabled_collectors = [
"cpu", "logical_disk", "net", "os", "service", "system",
// おすすめ:ダッシュボードや可視化で効く
"memory", "cs",
]
// ドライブレターだけに絞る例(任意)
logical_disk {
include = "^[A-Z]:$"
exclude = "^HarddiskVolume.*$"
}
}
// ---- 2) exporter を scrape ----
prometheus.scrape "selfpc" {
targets = prometheus.exporter.windows.selfpc.targets
forward_to = [prometheus.remote_write.local.receiver]
}
// ---- 3) Prometheus に remote_write ----
prometheus.remote_write "local" {
endpoint {
url = "http://localhost:9090/api/v1/write"
}
}
2.3 Alloy サービス再起動
-
services.mscを開く - Alloy サービスを再起動
3. “入った” を確認する(Prometheus → Grafana)
3.1 Prometheus でメトリクスが見えるか
Prometheus(http://localhost:9090)の検索欄で、次がヒットすればOKです。
3.2 Grafana でグラフ化(最小)
Grafana(http://localhost:3000)→ Explore → データソースに Prometheus を選び、以下をそのまま貼ります。
CPU使用率(%)
100 - (avg by (instance) (rate(windows_cpu_time_total{mode="idle"}[5m])) * 100)
メモリ空き(bytes)
windows_memory_available_bytes
Cドライブ使用率(%)
100 * (1 - (windows_logical_disk_free_bytes{volume="C:"} / windows_logical_disk_size_bytes{volume="C:"}))
補足:logical_disk の size 系は Windows カウンタ由来で更新が遅れることがあります。
(気になる場合はforを長めに取ったアラートにする、などで吸収します)
4. 便利:既製ダッシュボードを一発で入れる(任意)
Grafana には Windows 用ダッシュボードが公開されています。
例:Windows Node All(ID: 19269)(cpu/cs/logical_disk/memory/net/os/system などの collector 前提)
- Grafana → Dashboards → Import → ID を入れる → Import
5. つまずきポイント(最短で潰す)
-
Prometheus にデータが入らない
- Prometheus 起動コマンドに
--web.enable-remote-write-receiverが入っているか - Alloy の remote_write URL が
http://localhost:9090/api/v1/writeになっているか
- Prometheus 起動コマンドに
-
Alloyが起動しない
- Windows イベントビューア(Application)に Alloy のログが出ます(原因の当たりを付けるのが早い)
-
メトリクスが少ない
-
enabled_collectorsにmemoryやcsを追加してみる
-
次回予告(第2回)
第1回で「OS全体のメトリクス」が見えました。次は一歩進めて、
- **自分が気にしてる“身近なログ・イベント”**を扱う(Windowsイベントログ)
- プロセス/サービス監視で「困りごとに直結」させる
をやります。
参考
-
prometheus.exporter.windows(Alloy公式)
https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.exporter.windows/ -
AlloyをWindowsで設定する(configの場所・再起動)
https://grafana.com/docs/alloy/latest/configure/windows/ -
Prometheus HTTP API(remote write receiver /api/v1/write)
https://prometheus.io/docs/prometheus/latest/querying/api/ -
Windows Node All dashboard(ID: 19269)
https://grafana.com/grafana/dashboards/19269-windows-node/





