一、什么是Prometheus
Prometheus
是最后在SoundCloud
上构建的开源零碎监督和警报工具包 。是一个工夫序列数据库。工夫序列数据
:即按雷同时序(雷同名称和标签
),以工夫维度存储的间断的数据汇合。
二、Prometheus的个性
- 多维的数据模型
- 灵便的查询语言 PromQL
- 不依赖分布式存储;单个服务器节点是自治的
- 工夫序列收集通过HTTP上的拉模型进行
- 通过两头网关反对推送工夫序列
- 通过服务发现或动态配置发现指标
- 多种图形和仪表板反对模式
三、反对的指标类型
1、Counter 计数器
用于保留枯燥递增
的数值,只能是负数,不能是正数,不可缩小,然而能够重置为0。 比方: 某个http申请的拜访次数。
2、Gauge 仪表盘
用于保留有着起伏变动的值,能够减少也能够较少。比方: 内存的应用状况
3、Histogram 直方图
直方图对察看值(通常是申请持续时间或响应大小之类的货色)进行采样,并将其计数在可配置的存储桶中。 它还提供所有察看值的总和。
4、Summary 摘要
相似于直方图,摘要会采样察看值(通常是申请持续时间和响应大小之类的货色)。 尽管它还提供了观测值的总数和所有观测值的总和,但它在滑动工夫窗口内计算可配置的分位数
四、Prometheus单机部署
1、下载
Prometheus下载地址
2、下载之后解压重命名文件夹
1、文件夹内容
prometheus-2.25.0├── LICENSE├── NOTICE├── console_libraries│ ├── menu.lib│ └── prom.lib├── consoles│ ├── index.html.example│ ├── node-cpu.html│ ├── node-disk.html│ ├── node-overview.html│ ├── node.html│ ├── prometheus-overview.html│ └── prometheus.html├── prometheus (启动文件)├── prometheus.yml (配置文件)└── promtool
2、prometheus
为启动文件,默认启动会加载和它同级的prometheus.yml
配置文件。
3、prometheus.yml
为配置文件
3、启动 prometheus
1、显示prometheus命令反对的所有命令行参数
./prometheus -h
2、指定运行配置文件
./prometheus --config.file="prometheus.yml"
3、批改运行端口
./prometheus --web.listen-address="0.0.0.0:9080"
留神:
如果批改了默认的9090
端口,则须要批改 prometheus.yml
中默认监控本人的端口。
4、批改数据存储目录和数据保留工夫
./prometheus --storage.tsdb.path="data/" --storage.tsdb.retention.time="15d"
5、 查看版本号
./prometheus --version
6、验证配置文件是否正确
./promtool check config prometheus.yml
启动命令:
/Users/huan/soft/prometheus/prometheus-2.25.0/prometheus \--config.file="/Users/huan/soft/prometheus/prometheus-2.25.0/prometheus.yml" \--web.listen-address="0.0.0.0:9080" \--storage.tsdb.retention.time="15d" \&
五、启动界面
1、拜访指标数据
http://localhost:9080/metrics
2、拜访图形化界面(表达式浏览器)
http://localhost:9080/graph
六、配置node_exporter监控零碎主机
1、下载并解压
# wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.darwin-amd64.tar.gz# tar -zxvf node_exporter-1.1.1.darwin-amd64.tar.gz# mv node_exporter-1.1.1.darwin-amd64 node_exporter-1.1.1
2、启动node_exporter
./node_exporter --web.listen-address=":9081"
1、应用 --help
查看可用的命令行配置项
2、应用 --web.listen-address
指定启动的端口
3、拜访度量指标数据
http://localhost:9081/metrics
4、集成到 Prometheus 中
批改 prometheus.yml
文件,减少:
scrape_configs:- job_name: 'node-exporter' static_configs: - targets: ['localhost:9081']
5、查看node_exporter是否集成胜利
七、参考文档
- https://prometheus.io/docs/concepts/metric_types/
- https://prometheus.io/download/