安裝啟動(dòng)Grafana
brew install Grafana
brew services start grafana
啟動(dòng)后,通過(guò)http://localhost:3000/訪問(wèn)夜惭,用戶(hù)名和密碼都是admin劳跃,如圖:
安裝啟動(dòng)Prometheus
brew install prometheus
brew services start prometheus
安裝啟動(dòng)node_exporter
brew install node_exporter
brew services start node_exporter
啟動(dòng)后癌蚁,可以通過(guò)http://localhost:9100/查看,如圖:
安裝啟動(dòng)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
安裝啟動(dòng)cadvisor
#安裝
docker pull google/cadvisor:latest
#啟動(dòng)
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
啟動(dòng)后戳寸,訪問(wèn)http://localhost:8080/metrics呈驶,查看暴露給Prometheus的數(shù)據(jù)。
訪問(wèn)http://localhost:8080/containers/疫鹊,查看各個(gè)container的數(shù)據(jù)袖瞻,如圖:
配置Prometheus
配置文件默認(rèn)放在/usr/local/etc/prometheus.yml司致,重啟服務(wù)生效
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
啟動(dòng)后,可以通過(guò)http://localhost:9090/打開(kāi)聋迎,查詢(xún)go_threads語(yǔ)句脂矫,如圖:
配置Grafana的Prometheus數(shù)據(jù)源
首先找到Configuration的Data Sources,
然后Add data source,添加Prometheus
設(shè)置Prometheus的URL,Save&Test,添加完成霉晕。
添加dashboard
直接import Prometheus Stats等dashboard
點(diǎn)擊進(jìn)入Prometheus Stats庭再,如圖: