Open3
prometeusの実験
dockerでの実験
ファイル構造
├── docker-compose.yml
├── init.sql
├── .my.cnf
└── prometheus.yml
docker-compose.yml
version: '3.7'
services:
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
command:
- '--config.file=/etc/prometheus/prometheus.yml'
ports:
- "9090:9090"
grafana:
image: grafana/grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: exampledb
ports:
- "3306:3306"
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
mysqld_exporter:
image: prom/mysqld-exporter
volumes:
- ./.my.cnf:/etc/.my.cnf
command:
- '--config.my-cnf=/etc/.my.cnf'
environment:
DATA_SOURCE_NAME: "exporter:password@(mysql:3306)/"
depends_on:
- mysql
ports:
- "9104:9104"
node_exporter:
image: prom/node-exporter
ports:
- "9100:9100"
.my.cnf
[client]
user=exporter
password=password
host=mysql
init.sql
[client]
user=exporter
password=password
host=mysql
itagakimasaki@macpro prometheus_test % cat init.sql
CREATE USER 'exporter'@'%' IDENTIFIED BY 'password';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
FLUSH PRIVILEGES;
prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'mysql'
static_configs:
- targets: ['mysqld_exporter:9104']
- job_name: 'node'
static_configs:
- targets: ['node_exporter:9100']
hostからのexporterの疎通確認。以下にアクセスできればexporterは動作している
node_exporter
mysqld_exporter
- ブラウザで http://localhost:3000 にアクセスし、GrafanaのWebインターフェースにログイン(デフォルトのユーザー名はadmin、パスワードもadmin)。
- 「Add data source」からPrometheusを選択し、URLに http://prometheus:9090 を設定
- 新しいダッシュボードを作成し、パネルを追加して、Prometheusから取得したメトリックスを表示