1、下载镜像包
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
2、启动node-exporter
docker run -d -p 9101:9100 \
--name node-exporter \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
prom/node-exporter
3、启动cAdvisor
来收集容器信息 所有节点运行以下命令来安装cAdvisor
docker run -d \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:rw \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ -v "/etc/localtime:/etc/localtime" \ google/cadvisor:latest
启动prometheus
新建目录prometheus,编辑配置文件prometheus.yml
mkdir /data/prometheus
cd /data/prometheus/
vim prometheus.yml
内容如下:
# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. scrape_configs: # The job name is added as a label `job=` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: #监听的地址 - targets: ['localhost:9090','192.168.91.132:8080','192.168.91.132:9100']
docker run -d \ -p 9091:9090 \
--name prometheus \ -v /data/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \ prom/prometheus
4、启动grafana
新建空文件夹grafana-storage,用来存储数据
mkdir -p /data/grafana-storage
设置权限
chmod 777 -R /data/grafana-storage
因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!
docker run -d \ -p 3000:3000 \ --name=grafana \ -v /data/grafana-storage:/var/lib/grafana \ grafana/grafana
5、Grafana使用技巧
docker主机监控模板 193
linux主机监控模板 9276
redis主机监控模板 763
mysql主机监控模板 11323
Docker监控平台prometheus和grafana,监控redis,mysql,docker,服务器信息