Home | 简体中文 | 繁体中文 | 杂文 | 知乎专栏 | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 视频教程 | 打赏(Donations) | About
知乎专栏多维度架构 微信号 netkiller-ebook | QQ群:128659835 请注明“读者”

第 1 章 Prometheus

目录

1.1. 安装 Prometheus
1.1.1. Docker 安装
1.1.2. docker swarm
1.1.3. docker-compose
1.2. Prometheus 命令行工具
1.2.1. 刷新配置文件
1.2.2. promtool 配置文件校验工具
1.3. prometheus 配置
1.3.1. rules 规则配置
1.3.1.1. recording rules
1.3.1.2. alerting rules
1.4. PromQL 自定义查询语言
1.4.1. Metrics 格式
1.4.2. metric 类型
1.4.2.1. Counter:只增不减的计数器
1.4.2.2. Gauge:可增可减的仪表盘
1.4.2.3. Histogram
1.4.2.4. Summary
1.4.3. 查询时间序列
1.4.3.1. 标签查询
1.4.3.2. 范围查询
1.4.3.3. 数学运算
1.4.4. 聚合操作
1.4.4.1. rate()
1.4.4.2. topk() 和 bottomk()
1.4.4.3. delta()
1.4.4.4. predict_linear()
1.4.4.5. deriv()
1.4.4.6. sum()
1.4.4.7. avg()
1.4.4.8. min (最小值),max (最大值)
1.4.4.9. count_values()
1.4.4.10. quantile()
1.5. Installing and Configuring Graphite
1.5.1.
1.5.2. 监控 Docker
1.5.3. cadvisor
1.6. Alertmanager
1.6.1. alertmanager.yml 配置文件
1.6.1.1. amtool 配置文件检查工具
1.6.1.2. global 全局配置项
1.6.1.3. route 路由配置
1.6.1.4. receivers 定义警报接收者

1.1. 安装 Prometheus

1.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			
			
			

1.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
			
			

1.1.3. docker-compose