什么是Prometheus
Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. Since its inception in 2012, many companies and organizations have adopted Prometheus, and the project has a very active developer and user community. It is now a standalone open source project and maintained independently of any company. To emphasize this, and to clarify the project’s governance structure, Prometheus joined the Cloud Native Computing Foundation in 2016 as the second hosted project, after Kubernetes.
Prometheus collects and stores its metrics(指标) as time series (时间序列)data, i.e. metrics information is stored with the timestamp(时间戳) at which it was recorded, alongside optional key-value pairs called labels.
Prometheus是一个开源系统监控和警报工具包,是一个独立的开源项目
为什么需要监控?
及时发现问题,提醒工程师尽快去解决问题,减少损失,提高产品品质,增加客户的信任
Prometheus架构
exporters:
理解为植入客户机的一个程序,程序专门收集客户机数据,发送给Prometheus服务器
pull:
普罗米修斯服务器每隔一段时间去拉客户机 short_ived job:短时间运行的程序
pushgateway:
短时间运行的程序可以主动将数据push到pushgateway,临时集中存放数据,Prometheus服务器去pushgateway拿取
那么是push好还是pull好?(pull主动,push被动)
1、数据实时性(最新鲜的数据)
push有一定优势
2、服务器的负载,网络的负载(数据的可控性)
pull较好
是pull还是push取决于我们的服务
promQL:
Prometheus时序数据库的查询语言
grafana:
是一个图形展示的软件,到Prometheus时序数据库里面拿数据,以图形展示出来
安装和配置
编译安装
1、官网下载源码包
2、建立prometheus文件夹
mkdir /prometheus
3、把压缩包移到文件夹
mv prometheus-2.29.1.linux-amd64.tar.gz /prometheus/
4、为了方便启动,添加环境变量
PATH=$PATH:/prometheus/prometheus-2.29.1.linux-amd64
which prometheus
/prometheus/prometheus-2.29.1.linux-amd64/prometheus
5、启动程序
prometheus 启动程序
或者
./prometheus --config.file=prometheus.yml
容器安装
1、拉去镜像
docker run -d -p 9090:9090 --name prom-1 prom/prometheus
2、创建容器并启动
docker run -d -p 9090:9090 --name sc-prom-1 prom/prometheus