Prometheus的架构及持久化
原文: https://my.oschina.net/go4it/blog/855598
Prometheus是什么
Prometheus是一个开源的系统监控和报警工具,特点是
- 多维数据模型(时序列数据由metric名和一组key/value组成)
- 在多维度上灵活的查询语言(PromQl)
- 不依赖分布式存储,单主节点工作.
- 通过基于HTTP的pull方式采集时序数据
- 可以通过push gateway进行时序列数据推送(pushing)
- 可以通过服务发现或者静态配置去获取要采集的目标服务器
- 多种可视化图表及仪表盘支持
pull方式
Prometheus采集数据是用的pull也就是拉模型,通过HTTP协议去采集指标,只要应用系统能够提供HTTP接口就可以接入监控系统,相比于私有协议或二进制协议来说开发、简单。
push方式
对于定时任务这种短周期的指标采集,如果采用pull模式,可能造成任务结束了,Prometheus还没有来得及采集,这个时候可以使用加一个中转层,客户端推数据到Push Gateway缓存一下,由Prometheus从push gateway pull指标过来。(需要额外搭建Push Gateway,同时需要新增job去从gateway采数据)
组成及架构
- Prometheus server 主要负责数据采集和存储,提供PromQL查询语言的支持
- 客户端sdk 官方提供的客户端类库有go、java、scala、python、ruby,其他还有很多第三方开发的类库,支持nodejs、php、erlang等
- Push Gateway 支持临时性Job主动推送指标的中间网关
- PromDash 使用rails开发的dashboard,用于可视化指标数据
exporters 支持其他数据源的指标导入到Prometheus,支持数据库、硬件、消息中间件、存储系统、http服务器、jmx等
alertmanager 实验性组件、用来进行报警
- prometheus_cli 命令行工具
- 其他辅助性工具
架构图如下:
默认配置
docker exec -it a9bd827a1d18 less /etc/prometheus/prometheus.yml
得到
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first.rules"
# - "second.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
scrape_interval 这里是指每隔15秒钟去抓取数据(
这里)evaluation_interval 指的是计算rule的间隔
Push Gateway
pushgateway有单独的镜像
docker pull prom/pushgateway
对于喜欢用push模式的应用来说,可以专门搭建一个push gateway,来适配一下。
storage
prometheus使用了G家的LevelDB来做索引(PromSQL重度依赖LevelDB),对于大量的采样数据有自己的存储层,Prometheus为每个时序数据创建一个本地文件,以1024byte大小的chunk来组织。
磁盘文件
Prometheus在storage.local.path指定的路径存储文件,默认为./data。关于chunk编码有三种
- type 0
第一代的编码格式,simple delta encoding
- type 1
目前默认的编码格式,double-delta encoding
- type 2
variable bit-width encoding,facebook的时间序列数据库Beringei采用的编码方式
内存使用
prometheus在内存里保存了最近使用的chunks,具体chunks的最大个数可以通过storage.local.memory-chunks来设定,默认值为1048576,即1048576个chunk,大小为1G。 除了采用的数据,prometheus还需要对数据进行各种运算,因此整体内存开销肯定会比配置的local.memory-chunks大小要来的大,因此官方建议要预留3倍的local.memory-chunks的内存大小。
As a rule of thumb, you should have at least three times more RAM available than needed by the memory chunks alone
可以通过server的metrics去查看prometheus_local_storage_memory_chunks以及process_resident_memory_byte两个指标值。
prometheus_local_storage_memory_chunks
The current number of chunks in memory, excluding cloned chunks 目前内存中暴露的chunks的个数
process_resident_memory_byte
Resident memory size in bytes 驻存在内存的数据大小
prometheus_local_storage_persistence_urgency_score 介于0-1之间,当该值小于等于0.7时,prometheus离开rushed模式。 当大于0.8的时候,进入rushed模式
prometheus_local_storage_rushed_mode 1表示进入了rushed mode,0表示没有。进入了rushed模式的话,prometheus会利用storage.local.series-sync-strategy以及storage.local.checkpoint-interval的配置加速chunks的持久化。
storage参数
docker run -p 9090:9090 \
-v /tmp/prometheus-data:/prometheus-data \
prom/prometheus \
-storage.local.retention 168h0m0s \
-storage.local.max-chunks-to-persist 3024288 \
-storage.local.memory-chunks=50502740 \
-storage.local.num-fingerprint-mutexes=300960
storage.local.memory-chunks
设定prometheus内存中保留的chunks的最大个数,默认为1048576,即为1G大小
storage.local.retention
用来配置采用数据存储的时间,168h0m0s即为24*7小时,即1周
storage.local.series-file-shrink-ratio
用来控制序列文件rewrite的时机,默认是在10%的chunks被移除的时候进行rewrite,如果磁盘空间够大,不想频繁rewrite,可以提升该值,比如0.3,即30%的chunks被移除的时候才触发rewrite。
storage.local.max-chunks-to-persist
该参数控制等待写入磁盘的chunks的最大个数,如果超过这个数,Prometheus会限制采样的速率,直到这个数降到指定阈值的95%。建议这个值设定为storage.local.memory-chunks的50%。Prometheus会尽力加速存储速度,以避免限流这种情况的发送。
storage.local.num-fingerprint-mutexes
当prometheus server端在进行checkpoint操作或者处理开销较大的查询的时候,采集指标的操作会有短暂的停顿,这是因为prometheus给时间序列分配的mutexes可能不够用,可以通过这个指标来增大预分配的mutexes,有时候可以设置到上万个。
storage.local.series-sync-strategy
控制写入数据之后,何时同步到磁盘,有'never', 'always', 'adaptive'. 同步操作可以降低因为操作系统崩溃带来数据丢失,但是会降低写入数据的性能。 默认为adaptive的策略,即不会写完数据就立刻同步磁盘,会利用操作系统的page cache来批量同步。
storage.local.checkpoint-interval
进行checkpoint的时间间隔,即对尚未写入到磁盘的内存chunks执行checkpoint操作。
doc
Prometheus的架构及持久化的更多相关文章
- Prometheus监控学习笔记之Prometheus的架构及持久化
0x00 Prometheus是什么 Prometheus是一个开源的系统监控和报警工具,特点是 多维数据模型(时序列数据由metric名和一组key/value组成) 在多维度上灵活的查询语言(Pr ...
- Prometheus Operator 架构 - 每天5分钟玩转 Docker 容器技术(178)
本节讨论 Prometheus Operator 的架构.因为 Prometheus Operator 是基于 Prometheus 的,我们需要先了解一下 Prometheus. Prometheu ...
- Prometheus Operator 架构【转】
本节讨论 Prometheus Operator 的架构.因为 Prometheus Operator 是基于 Prometheus 的,我们需要先了解一下 Prometheus. Prometheu ...
- Kubernetes部署Prometheus+Grafana(非存储持久化方式部署)
1.在master节点处新建一个文件夹,用于保存下载prometheus+granfana的yaml文件 mkdir /root/prometheus cd /root/prometheus git ...
- Prometheus监控学习记录
官方文档 Prometheus基础文档 从零开始:Prometheus 进阶之路:Prometheus —— 技巧篇 进阶之路:Prometheus —— 理解篇 prometheus的数据类型介绍 ...
- 添加Access-Control-Allow-Origin主机头, 授权资源跨站访问
时间 2014-09-24 22:02:48 All by Neil 原文 https://blog.byneil.com/添加access-control-allow-origin主机头-授权资 ...
- Prometheus 架构 - 每天5分钟玩转 Docker 容器技术(83)
Prometheus 是一个非常优秀的监控工具.准确的说,应该是监控方案.Prometheus 提供了监控数据搜集.存储.处理.可视化和告警一套完整的解决方案. 让我们先来看看 Prometheus ...
- Redis持久化、主从与哨兵架构详解
目录 Redis持久化 RDB快照(snapshot) AOF(append-only file) AOF重写 Redis 4.0 混合持久化 Redis数据备份策略: Redis主从架构 Redis ...
- Prometheus介绍
Prometheus的主要特点 Prometheus 属于一站式监控告警平台,依赖少,功能齐全.Prometheus 支持对云的或容器的监控,其他系统主要对主机监控.Prometheus 数据查询语句 ...
随机推荐
- 鼠标滑过GridView的数据行时修改行的背景颜色
基本原理可以参考另一篇文章:鼠标滑过table时修改表格行的背景颜色 下面是针对GridView实现该效果的代码:就是编写GridView控件的RowDataBound事件的代码. protected ...
- poj 2068 Nim(博弈dp)
Nim Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 1403 Accepted: 791 Description Le ...
- ASIHttpRequest请求HTTPS
一种方法 ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:[NSURLURLWithString:bodyString]]; [requ ...
- java.lang.IllegalStateException——好头疼
在我东,下下来一个项目总会出现启动不了的问题,这些问题往往在编译的时候发现不了,当你的服务器启动的时候,就是一片片的报错,有些问题可以通过异常的提示信息,判断出来哪里配置错了,但是也有些情况下,从异常 ...
- SNF开发平台-SNF.CodeGenerator-升级生成BS页面代码-支持视图-数据库配置-快速开发者的利器
有一段时间没有进行总结SNF快速开发平台了,这段时间把今年在框架升级部分进行整理说明. 下面就把代码生成器升级部分介绍一下: 1.新增BS页面生成代码 2.新增视图支持 3.新增 数据库配置 1.新增 ...
- 第三部分:Android 应用程序接口指南---第二节:UI---第一章 用户界面和布局
第1章 用户界面和布局 应用程序的用户界面就是用户能看到并可以与它交互的任何东西.Android提供多种预置的UI组件,如结构化布局对象和允许你为应用程序创建图形用户界面的UI控件.Android也会 ...
- 语音识别(SR)的秘密
语音识别(SR)功能是当今国外操作系统的标准特征,而国产操作系统根本不具备这样的特质,并且国家队没有相关的主观动力.去开发实际可用的语音识别系统.与国外相比,国产操作系统落后了一大节子,怪谁? 如何让 ...
- 【iCore1S 双核心板_FPGA】例程六:状态机实验——状态机使用
核心代码: module FSM( input CLK_12M, input FPGA_KEY, output FPGA_LEDR, output FPGA_LEDG, output FPGA_LED ...
- AtomicInteger 源码阅读
Package java.util.concurrent.atomic 这是一个小工具包,它的实际作用是提供了很多个无阻塞的线程安全的变量操作工具. 无阻塞的线程安全:其含义就是不使用 synchro ...
- Java知多少(84)图形界面之布局设计
在界面设计中,一个容器要放置许多组件,为了美观,为组件安排在容器中的位置,这就是布局设计.java.awt中定义了多种布局类,每种布局类对应一种布局的策略.常用的有以下布局类: FlowLayout, ...