Prometheus 是由 SoundCloud 开源监控告警解决方案,从 2012 年开始编写代码,再到 2015 年 github 上开源以来,已经吸引了 9k+ 关注,以及不少大公司的使用;2016 年 Prometheus 成为继 k8s 后,第二名 CNCF(Cloud Native Computing Foundation) 成员。html
多维 数据模型(时序由 metric 名字和 k/v 的 labels 构成)。
灵活的查询语句(PromQL)。
无依赖存储,支持 local 和 remote 不一样模型。
采用 http 协议,使用 pull 模式,拉取数据,简单易懂。
监控目标,能够采用服务发现或静态配置的方式。
支持多种统计数据模型,图形化友好。node
Prometheus Server, 主要用于抓取数据和存储时序数据,另外还提供查询和 Alert Rule 配置管理。
client libraries,用于对接 Prometheus Server, 能够查询和上报数据。
push gateway ,用于批量,短时间的监控数据的汇总节点,主要用于业务数据汇报等。
exporters ,部署在客户端的agent 例如汇报机器数据的 node_exporter, 汇报 MongoDB 信息的 MongoDB exporter 等等。
alertmanager 用于告警通知管理的linux
从这个架构图,也能够看出 Prometheus 的主要模块包含, Server, Exporters, Pushgateway, PromQL, Alertmanager, WebUI 等。git
它大体使用逻辑是这样:
Prometheus server 按期从静态配置的 targets 或者服务发现的 targets 拉取数据。
当新拉取的数据大于配置内存缓存区的时候,Prometheus 会将数据持久化到磁盘(若是使用 remote storage 将持久化到云端)。
Prometheus 能够配置 rules,而后定时查询数据,当条件触发的时候,会将 alert 推送到配置的 Alertmanager。
Alertmanager 收到警告的时候,能够根据配置,聚合,去重,降噪,最后发送警告。
能够使用 API, Prometheus Console 或者 Grafana 查询和聚合数据。github
以上内容转载:https://songjiayang.gitbooks.io/prometheus/content/introduction/what.htmlweb
(1)下载安装包https://prometheus.io/download/ 至指定目录如/Download
shell>gwet https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.darwin-amd64.tar.gzshell
(2)解压prometheus
shell>tar -xvzf ~/Download/prometheus-2.13.1.linux-amd64.tar.gz
shell>mv prometheus-2.13.1.linux-amd64 prometheus
shell>cd prometheus
shell>ls prometheus
prometheus 启动文件
prometheus.yml 配置文件
data 存储文件vim
(3)检查prometheus版本
shell> ./prometheus version 缓存
prometheus, version 2.13.0 (branch: HEAD, revision: 6ea4252299f542669aca11860abc2192bdc7bede) build user: root@f30bdad2c3fd build date: 20191004-11:25:34 go version: go1.13.1
(4)启动prometheus server
shell> ./prometheus #正常启动会输出不少信息架构
level=info ts=2019-10-17T09:29:45.851Z caller=main.go:332 msg="Starting Prometheus" version="(version=2.13.0, branch=HEAD, revision=6ea4252299f542669aca11860abc2192bdc7bede)"
(5)查看端口监听,监听端口9090
shell>netstat -tunlp | grep prometheus
tcp6 0 0 :::9090 :::* LISTEN 31879/./prometheus
(6)经过web访问http://IP:9090
(7)以服务的方式启动
shell>vim /etc/systemd/system/prometheus.service
[Unit] Description=Prometheus Monitoring System Documentation=Prometheus Monitoring System [Service] ExecStart=/Download/prometheus/prometheus \ --config.file /Download/prometheus/prometheus.yml \ --web.listen-address=:9090 [Install] WantedBy=multi-user.target
shell> systemctl daemon-reloadshell> systemctl enable prometheusshell> systemctl start prometheus