2026年10月26日

2026年10月26日

サーバーの監視ダッシュボードを構築する方法

はじめに

サーバー監視の事実上のスタンダードは、メトリクス収集に Prometheus、可視化に Grafana を組み合わせる構成です。OS の状態は node_exporter が、Web/DB のメトリクスは各サービス用のエクスポータが提供し、Prometheus がそれらを Pull で集約、Grafana がダッシュボードとアラートを担います。

商用 SaaS(Datadog, New Relic)に比べてコストは抑えられ、オンプレ・クラウド・ハイブリッドのいずれにも対応できます。学習コストは多少ありますが、テンプレート(公式ダッシュボードID 1860 など)を活用すれば1時間程度で「それらしい監視画面」が立ち上がります。

本記事では、Ubuntu 24.04 を例に最小構成でのインストールから、最初のダッシュボード表示、アラートまでを実演します。

症状・背景

監視ダッシュボード構築が必要な場面:

  • サーバー台数が増え、top/df の手動巡回が現実的でなくなった
  • 経営層・顧客に対し、SLA 達成状況を可視化して報告したい
  • 障害発生時に時系列のメトリクスを後追い分析したい
  • 既存の Zabbix から移行して、より柔軟なグラフ作成をしたい

手順・設定方法

ステップ1: node_exporter(監視対象側)をインストール

# バイナリ取得
wget -O /tmp/ne.tgz \
  https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-1.8.2.linux-amd64.tar.gz
sudo tar -xzf /tmp/ne.tgz -C /usr/local/bin/ --strip-components=1 \
  node_exporter-1.8.2.linux-amd64/node_exporter

# systemd ユニット
cat <<'EOF' | sudo tee /etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload && sudo systemctl enable --now node_exporter

ステップ2: Prometheus をインストール

sudo apt install -y prometheus

# /etc/prometheus/prometheus.yml に scrape ターゲットを追記
cat <<'EOF' | sudo tee -a /etc/prometheus/prometheus.yml
  - job_name: 'node'
    static_configs:
      - targets: ['localhost:9100', 'web01:9100', 'db01:9100']
EOF

sudo systemctl restart prometheus
# 確認: http://localhost:9090/targets
curl -s http://localhost:9090/api/v1/targets | head

ステップ3: Grafana をインストールしてダッシュボードを追加

# 公式リポジトリ
sudo apt-get install -y software-properties-common
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" \
  | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install -y grafana
sudo systemctl enable --now grafana-server

# ブラウザで http://host:3000 へアクセス(admin/admin)
# Configuration → Data Sources → Prometheus → URL: http://localhost:9090
# Dashboards → Import → ID:1860 (Node Exporter Full) を取り込む

ステップ4: アラートルールを定義

# /etc/prometheus/rules/host.yml
sudo mkdir -p /etc/prometheus/rules
cat <<'EOF' | sudo tee /etc/prometheus/rules/host.yml
groups:
- name: host
  rules:
  - alert: HighCPU
    expr: 100 - (avg by(instance)(rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 85
    for: 5m
    labels: { severity: warning }
    annotations:
      summary: "{{ $labels.instance }} CPU 85%超"
  - alert: DiskAlmostFull
    expr: (node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100 < 10
    for: 10m
    labels: { severity: critical }
    annotations:
      summary: "{{ $labels.instance }} {{ $labels.mountpoint }} 残り10%未満"
EOF
sudo systemctl reload prometheus

注意事項

  • Prometheus はメトリクスをローカルディスクに保存するため、SSD と容量計画が重要
  • 長期保管は Thanos / Mimir などのリモートストレージを検討
  • node_exporter のポート(9100)は信頼ネットワーク内のみ公開する
  • Grafana の admin 初期パスワードは初回ログインで必ず変更する

まとめ

1. node_exporter: 各サーバーに常駐させ OS メトリクスを公開

2. Prometheus: scrape 設定で対象を一元管理

3. Grafana: ID:1860 の公式ダッシュボードで一気に可視化

4. アラート: PromQL でしきい値ベースの監視を記述

5. 拡張: nginx_exporter / mysqld_exporter で各サービスへ拡張可能

関連記事:

お気軽にご相談ください

お見積りへ お問い合わせへ
▲