Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 68 章 Prometheus

目录

68.1. 安装 Prometheus
68.1.1. Docker 安装
68.1.2. docker swarm
68.1.3. docker-compose
68.1.4. 防火墙设置
68.2. Prometheus 配置
68.2.1. Prometheus 命令行工具
68.2.2. rules 规则配置
68.2.3. SpringBoot
68.2.4. PromQL 自定义查询语言
68.3. Prometheus Exporter
68.3.1. 监控 Docker
68.3.2. node-exporter
68.3.3. cadvisor
68.3.4. Nginx Prometheus Exporter
68.3.5. Redis
68.3.6. MongoDB
68.3.7. MySQL
68.3.8. Blackbox Exporter(blackbox-exporter)
68.3.9. SNMP Exporter
68.4. Alertmanager
68.4.1. Docker 安装
68.4.2. alertmanager.yml 配置文件
68.4.3. 触发测试
68.4.4. 警报状态
68.5. Grafana
68.5.1. cadvisor
68.5.2. Docker - container summary (Prometheus)

68.1. 安装 Prometheus

68.1.1. Docker 安装

			
docker run -d -p 9090:9090 -v ~/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus -config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000			
			
			

			
docker run -d -p 9100:9100 --user 995:995 \
-v "/:/hostfs" \
--net="host" \
prom/node-exporter \
--path.rootfs=/hostfs	
			
			

检查 node-exporter 是否正常工作

			
$ curl http://localhost:9100/metrics
			
			

安装 grafana

			
$ docker run -d --name grafana -p 3000:3000 --net=host -e "GF_SECURITY_ADMIN_PASSWORD=passw0rd" grafana/grafana			
			
			

-e "GF_SERVER_ROOT_URL=http://grafana.server.name"

			
docker exec -it grafana cat /etc/grafana/grafana.ini > grafana.ini			
			
			

环境变量配置的默认路径

			
环境变量					默认值
GF_PATHS_CONFIG			/etc/grafana/grafana.ini
GF_PATHS_DATA			/var/lib/grafana
GF_PATHS_HOME			/usr/share/grafana
GF_PATHS_LOGS			/var/log/grafana
GF_PATHS_PLUGINS		/var/lib/grafana/plugins
GF_PATHS_PROVISIONING	/etc/grafana/provisioning			
			
			

68.1.2. docker swarm

			
$ docker service create --replicas 1 --name prometheus \
    --mount type=bind,source=`pwd`/prometheus.yml,destination=/etc/prometheus/prometheus.yml \
    --publish published=9090,target=9090,protocol=tcp \
    prom/prometheus
			
			

68.1.3. docker-compose

			

			
			

68.1.4. 防火墙设置

			
firewall-cmd --zone=public --add-port=9090/tcp --permanent
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --zone=public --add-port=9191/tcp --permanent
firewall-cmd --zone=public --add-port=9093/tcp --permanent
firewall-cmd --zone=public --add-port=9323/tcp --permanent
firewall-cmd --reload
			
			

查看端口策略是否已经生效

			
firewall-cmd --permanent --zone=public --list-ports