一、prometheus本地存储
prometheus有着非常高效的时间序列数据存储方法,每个采样数据仅仅占用3.5byte的空间
默认情况下,prometheus将采集到的数据存储在本地的TSDB数据库中,路径默认为prometheus安装目录的data目录下,数据写入过程先把数据写入wal日志并存放在内存,然后2小时后将内存的数据保存至一个新的block块,同时再把新采集的数据写入内存并在2小时后保存至一个新的block块,以此类推
1.1、block简介
每个block为一个data目录中以01开头的存储目录,如下:
1.2、block的特性
block块会压缩、合并历史数据块,以及删除过期的数据块,随着压缩、合并,block块数量会减少,在压缩过程中会发生三件事:定时执行压缩、合并小的block到大的block、清理过期的块
每个块有4部分组成:
1.3、本地存储配置参数
1 2 3 4 5 6 7 8 9 10 11 12 | --config. file = "prometheus.yml" # 指定配置文件 --web.listen-address= "0.0.0.0:9090" # 指定监听地址 --storage.tsdb.path= "data/" # 指定数据存储目录 --storage.tsdb.retention.size=B,KB,MB,GB,TB,PB,EB # 指定chunk大小,默认512M --storage.tsdb.retention. time = # 数据保存时长,默认15天 --query.timeout=2m # 大查询超时时间 --query.max-connections=512 # 大查询并发数 --web. read -timeout=5m # 大空闲超时时间 --web.max-connections=512 # 大并发连接数 --web. enable -lifecycle # 启用api动态加载功能 |
二、prometheus远端存储VictoriaMetrics
GITHUB地址:https://github.com/VictoriaMetrics/VictoriaMetrics
官网地址:https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html
2.1、组件介绍
vminsert:写入组件,vminsert负责接收数据写入并根据对度量名称及其所有标签的一致hash结果将数据分散写入不同的后端vmstorage节点之间,vminsert默认端口8480
vmstorage:存储原始数据并返回给定时间范围内给定标签过滤器的查询数据,默认端口8482
vmselect:查询组件,连接vmstorage,默认端口8481
其他可选组件:
vmagent:是一个很小但功能很强大的代理,它可以从node_exporter各种来源收集度量数据,并将它们存储在VictoriaMetrics或任何其他支持远程写协议的与prometheus兼容的存储系统中,有点prometheus server的意向
vmalert:替换prometheus server,以VictoriaMetrics为数据源,基于兼容prometheus的告警规则,判断数据是否异常,并将产生的通知发送给alertmanager
vmgateway:读写VictoriaMetrics数据的代理网关,可实现限速和访问控制等功能,目前为企业版组件
vmctl:VictoriaMetrics的命令行工具,目前主要用于将prometheus、opentsdb等数据源的数据迁移到VictoriaMetrics
2.2、部署VictoriaMetrics集群
分别在各个victoriametrics服务器进行安装配置
1 2 3 4 5 | tar xf victoria-metrics-amd64-v1.71.0-cluster. tar .gz vminsert-prod vmstorage-prod vmselect-prod mv vminsert-prod vmstorage-prod vmselect-prod /usr/local/bin |
环境简介
1 2 3 4 5 6 | 192.168.88.200 prometheus 192.168.88.201 victoriametrics-server1 # 启动vminsert、vmstorage、vmselect三个组件 192.168.88.202 victoriametrics-server2 # 启动vminsert、vmstorage、vmselect三个组件 192.168.88.203 victoriametrics-server3 # 启动vminsert、vmstorage、vmselect三个组件 192.168.88.204 node1 192.168.88.205 node2 |
2.2.1、部署vmstorage-prod组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # service文件 root@prometheus-victoriametrics1:~ # vim /etc/systemd/system/vmstorage.service [Unit] Description=Vmstorage Server After=network.target [Service] Restart=on-failure WorkingDirectory= /tmp ExecStart= /usr/local/bin/vmstorage-prod -loggerTimezone Asia /Shanghai -storageDataPath /data/vmstorage-data -httpListenAddr :8482 -vminsertAddr :8400 -vmselectAddr :8401 [Install] WantedBy=multi-user.target # 启动 root@prometheus-victoriametrics1:~ # systemctl daemon-reload root@prometheus-victoriametrics1:~ # systemctl restart vmstorage.service root@prometheus-victoriametrics1:~ # netstat -tnlp | grep -E "8482|8400|8401" tcp 0 0 0.0.0.0:8400 0.0.0.0:* LISTEN 1529 /vmstorage-prod tcp 0 0 0.0.0.0:8401 0.0.0.0:* LISTEN 1529 /vmstorage-prod tcp 0 0 0.0.0.0:8482 0.0.0.0:* LISTEN 1529 /vmstorage-prod |
2.2.2、部署vminsert-prod组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | root@prometheus-victoriametrics1:~ # vim /etc/systemd/system/vminsert.service [Unit] Description=Vmsinsert Server After=network.target [Service] Restart=on-failure WorkingDirectory= /tmp ExecStart= /usr/local/bin/vminsert-prod -httpListenAddr :8480 -storageNode=192.168.88.201:8400,192.168.88.202:8400,192.168.88.203:8400 [Install] WantedBy=multi-user.target # 启动 root@prometheus-victoriametrics1:~ # systemctl daemon-reload root@prometheus-victoriametrics1:~ # systemctl start vminsert.service root@prometheus-victoriametrics1:~ # netstat -tnlp | grep 8480 tcp 0 0 0.0.0.0:8480 0.0.0.0:* LISTEN 1609 /vminsert-prod root@prometheus-victoriametrics1:~ # |
2.2.3、部署vmselect-prod组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | root@prometheus-victoriametrics1:~ # vim /etc/systemd/system/vmselect.service [Unit] Description=Vmselect Server After=network.target [Service] Restart=on-failure WorkingDirectory= /tmp ExecStart= /usr/local/bin/vmselect-prod -httpListenAddr :8481 -storageNode=192.168.88.201:8401,192.168.88.202:8401,192.168.88.203:8401 [Install] WantedBy=multi-user.target # 启动 root@prometheus-victoriametrics2:~ # systemctl daemon-reload root@prometheus-victoriametrics2:~ # systemctl start vmselect.service root@prometheus-victoriametrics2:~ # netstat -tnlp|grep sele tcp 0 0 0.0.0.0:8481 0.0.0.0:* LISTEN 1337 /vmselect-prod root@prometheus-victoriametrics2:~ # |
2.2.4、验证服务端口
1 2 3 4 5 6 7 8 9 10 11 | curl http: //192 .168.88.201:8480 /metrics curl http: //192 .168.88.201:8481 /metrics curl http: //192 .168.88.201:8482 /metrics curl http: //192 .168.88.202:8480 /metrics curl http: //192 .168.88.202:8481 /metrics curl http: //192 .168.88.202:8482 /metrics curl http: //192 .168.88.203:8480 /metrics curl http: //192 .168.88.203:8481 /metrics curl http: //192 .168.88.203:8482 /metrics |
2.2.5、配置prometheus接入vmstorage-prod存储
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | root@prometheus: /usr/local/prometheus # vim prometheus.yml ............. remote_write: - url: http: //192 .168.88.201:8480 /insert/0/prometheus - url: http: //192 .168.88.202:8480 /insert/0/prometheus - url: http: //192 .168.88.203:8480 /insert/0/prometheus scrape_configs: - job_name: "prometheus" # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: [ "localhost:9090" ] - job_name: "nodes" static_configs: - targets: [ "192.168.88.204:9100" , "192.168.88.205:9100" ] root@prometheus: /usr/local/prometheus # systemctl restart prometheus.service |
2.2.6、配置grafana数据源
URL处填写其中一个vmselect服务的地址 例如:http://192.168.88.201:8481/select/0/prometheus
注意:生产环境中这个应该填写的是负载均衡器的地址
导入模板,数据源选择prometheus-VictoriaMetrics
来源 https://www.cnblogs.com/zhrx/p/16028078.html