轉載:https://www.jianshu.com/p/67087e164144
安裝啓動Grafana
brew install Grafana
brew services start grafana
啓動後,通過http://localhost:3000/訪問,用戶名和密碼都是admin,如圖:
安裝啓動Prometheus
brew install prometheus
brew services start prometheus
安裝啓動node_exporter
brew install node_exporter
brew services start node_exporter
啓動後,可以通過http://localhost:9100/查看,如圖:
安裝啓動mysqld_exporter
docker pull prom/mysqld-exporter
docker run -d -p 9104:9104 -e DATA_SOURCE_NAME="username:passwd@(localhost:3306)/dbname" prom/mysqld-exporter
安裝啓動cadvisor
#安裝
docker pull google/cadvisor:latest
#啓動
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
啓動後,訪問http://localhost:8080/metrics,查看暴露給Prometheus的數據。
訪問http://localhost:8080/containers/,查看各個container的數據,如圖:
配置Prometheus
配置文件默認放在/usr/local/etc/prometheus.yml,重啓服務生效
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
labels:
instance: prometheus
- job_name: "node_exporter"
static_configs:
- targets: ["localhost:9100"]
labels:
instance: node_exporter
- job_name: mysqld_exporter
static_configs:
- targets: ['localhost:9104']
labels:
instance: mysqld_exporter
- job_name: 'cadvisor'
static_configs:
- targets: ['127.0.0.1:8080']
labels:
instance: cadvisor
啓動後,可以通過http://localhost:9090/打開,查詢go_threads語句,如圖:
配置Grafana的Prometheus數據源
首先找到Configuration的Data Sources,
然後Add data source,添加Prometheus
設置Prometheus的URL,Save&Test,添加完成。
添加dashboard
直接import Prometheus Stats等dashboard
點擊進入Prometheus Stats,如圖:
作者:土豆特別想爬山
鏈接:https://www.jianshu.com/p/67087e164144
來源:簡書
著作權歸作者所有。商業轉載請聯繫作者獲得授權,非商業轉載請註明出處。