👻
grafana をdockerコンテナで実行する
はじめに
前回の記事で prometheusu の導入が完了しました。今回は grafana を dockerコンテナで実行します。
実行環境と作業の流れ
監視サーバー : Dockerコンテナ(MacBookAir上で構築)
監視対象 : Fedoraサーバー(VMWare仮想マシン)
※ 以下手順で作業していきます。
prometheusu のコンテナで環境を構築する
grafana のコンテナ環境を構築する ← ※今回はここです
prometheus から取得したデータを grafana で可視化する
grafana の起動
前回作成した docker-compose.yml に grafana を追加します。
% vi docker-compose.yml
% cat docker-compose.yml
services:
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- '9090:9090'
volumes:
- './prometheus.yml:/etc/prometheus/prometheus.yml'
- 'prometheus-data:/prometheus'
# 以下を追記
grafana:
image: grafana/grafana
# grafana サービスを追加
container_name: grafana
# コンテナ名は grafana
ports:
- "3000:3000"
# 3000番ポートをホストとバインド(Web UI用)
volumes:
- grafana-data:/var/lib/grafana
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
# デフォルトログインは admin / admin
volumes:
prometheus-data: {}
# 以下を追記
grafana-data: {}
# grafana のデータも永続化
ファイルに追記できたので、コンテナを起動します。
% docker compose up -d
[+] Running 11/11
✔ grafana Pulled 15.7s
✔ 6e174226ea69 Already exists 0.0s
✔ 7dddffca83ce Pull complete 0.7s
✔ 9691c2dd855f Pull complete 1.0s
✔ 4f4fb700ef54 Pull complete 1.0s
✔ ed1560304a04 Pull complete 1.4s
✔ 2ce358c7b01f Pull complete 1.4s
✔ b6ebfdec01b6 Pull complete 6.8s
✔ bda7c0844a58 Pull complete 10.2s
✔ 8159b0c4827c Pull complete 10.2s
✔ 804b0b457a89 Pull complete 10.2s
[+] Running 3/3
✔ Volume "prometheus_grafana-data" Created 0.0s
✔ Container prometheus Running 0.0s
✔ Container grafana Started 0.3s
コンテナ起動後 http://localhost:3000 にアクセスしてみます。
ログイン画面
トップ画面
ログインできました。これで grafana の構築は完了です。
さいごに
以上で grafana の導入は完了となります。次の記事で prometheusu で収集したデータを grafana で可視化する作業を行いたいと思います。
Discussion