Prometheus的单机部署

原创
2021/02/28 13:37
阅读数 711

一、什么是Prometheus

Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包 。是一个时间序列数据库。 时间序列数据:即按相同时序(相同名称和标签),以时间维度存储的连续的数据集合。
注意:同一个指标名称上添加、删除、修改标签将会产生一个新的时间序列。如果我们为该时间系列配置了一系列的警报,该警报依赖于指标的标签来评判。如果更改或 添加标签,那么警报将变为无效。

二、Prometheus的特性

  1. 多维的数据模型
  2. 灵活的查询语言 PromQL
  3. 不依赖分布式存储;单个服务器节点是自治的
  4. 时间序列收集通过HTTP上的拉模型进行
  5. 通过中间网关支持推送时间序列
  6. 通过服务发现或静态配置发现目标
  7. 多种图形和仪表板支持模式

三、支持的指标类型

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

下载node_exporter

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是否集成成功

查看node-exporter是否集成成功

七、参考文档

  1. https://prometheus.io/docs/concepts/metric_types/
  2. https://prometheus.io/download/
展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部