grafanaとpostgresを連携してみた【docker-compose】


起動方法

git clone https://github.com/guedim/grafana-postgres.git
docker-compose up -d

grafanaへログイン

ブラウザから http://localhost:3000/ へアクセス
user : admin
password: foobar
でログインする。
(grafana-postgres/grafana/dashboard/post.sh にて設定してある)

grafanaのGUIでの設定方法

Add data sourceを押して、postgresを設定する
一番難しいところが以下の設定場所。Host名がlocalhost:5432ではなくて、postgres:5432に設定する


入力後、Save & Testを押してDatabase Connection OKが出れば連携完了。

テーブルを可視化

dashboard > table > edit でsql文を書ける画面が出てくる。
https://github.com/guedim/grafana-postgres.git には元々データが入っているので、そのデータを表示した。

postgres のデータをみる

docker-compose exec postgres bash
su postgres
psql
\d #テーブル一覧表示
\l #database一覧を表示
\d account_metrics #カラム一覧を表示 カラムなのでデータベースを指定してから 
\q #exit