一、介绍
1.什么是Prometheus?
普罗米修斯是一个开源的系统监控及报警工具,在2016年加入了Cloud Native Computing Foundation,是继Kubernetes之后的第二个托管项目。
2.Prometheus的特征有什么?
具有由metric名称和键值对标示的时间序列数据的多位数据模型
有一个灵活的查询语言promQL
不依赖分布式存储,只和本地磁盘有关
通过HTTP来拉取(pull)时间序列数据
也支持推送(push)方式添加时间序列数据
多种图形和仪表盘支持
3.Prometheus的组件都有哪些?来张官方图:
Prometheus Server 用于定时抓取数据指标(metrics)、存储时间序列数据(TSDB)
Jobs/exporte 收集被监控端数据并暴露指标给Prometheus
Pushgateway 监控端的数据会用push的方式主动传给此组件,随后被Prometheus 服务定时pull此组件数据即可
Alertmanager 报警组件,可以通过邮箱、微信等方式
Web UI 用于多样的UI展示,一般为Grafana
还有一些例如配置自动发现目标的小组件和后端存储组件
4.什么时候使用Prometheus
监控的对象动态可变,无法预先配置的时候
Prometheus 是专为云环境(k8s/docker)提供的监控工具
想要更直观更简单的直接观察某项指标的数据变化时
5.看到一个写的非常不错的关Prometheus存储的文章
https://www.cnblogs.com/zqj-blog/p/12205063.html
二、搭建
1.安装Prometheus
## 解压安装
tar zxf prometheus-2.22.0.linux-amd64.tar.gz -C /opt/vfan/
mv prometheus-2.22.0.linux-amd64 prometheus-2.22.0
cd prometheus-2.22.0/
## 可以通过--help或--version查看服务启动参数和版本等
./prometheus --help
./prometheus --version
## 启动服务,并指定配置文件
nohup ./prometheus --config.file="prometheus.yml" &> /dev/null &
## 查看端口占用情况(默认9090)
[root@VM-0-10-centos prometheus-2.22.0]# ss -tnlp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=28673,fd=14))
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1306,fd=3))
LISTEN 0 128 :::80 :::* users:(("httpd",pid=31980,fd=4),("httpd",pid=31851,fd=4),("httpd",pid=30055,fd=4),("httpd",pid=21050,fd=4),("httpd",pid=14509,fd=4),("httpd",pid=12678,fd=4),("httpd",pid=12676,fd=4),("httpd",pid=9731,fd=4),("httpd",pid=9678,fd=4),("httpd",pid=2718,fd=4),("httpd",pid=1430,fd=4))
LISTEN 0 128 :::9090 :::* users:(("prometheus",pid=11771,fd=10))
或者直接使用docker容器运行,直接挂载一下配置文件:
docker run \
-p 9090:9090 \