• Prometheus系列第三篇一协议设计


      ^. . . . . . . . . . . . . . . . .   . .   node_cpu{cpu="cpu0",mode="idle"}. . . . . . . . . . . . . . . . . . .   node_cpu{cpu="cpu0",mode="system"}. . . . . . . . . .   . . . . . . . .. . . . . . . . . . . . . . . .   . .  
      v
        <------------------ 时间 ---------------->
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    Counter

    • metric的名称为node_cpu
    # HELP node_cpu Seconds the cpus spent in each mode.
    # TYPE node_cpu counter
    node_cpu{cpu="cpu0",mode="idle"} 362812.7890625
    
    • 1
    • 2
    • 3

    Gauge

    • 表示瞬时量
    # HELP executor_pool_core_threads The core number of threads for the pool
    # TYPE executor_pool_core_threads gauge
    executor_pool_core_threads{application="application",name="globalPubSubSubscriberThreadPoolScheduler",} 4.0
    executor_pool_core_threads{application="application",name="pubSubAcknowledgementExecutor",} 1.0
    executor_pool_core_threads{application="application",name="applicationTaskExecutor",} 8.0
    executor_pool_core_threads{application="application",name="pubsubPublisherThreadPool",} 4.0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    Summary

    从上面的样本中可以得知当前Prometheus Server进行wal_fsync操作的总次数为216次,耗时2.888716127000002s。其中中位数(quantile=0.5)的耗时为0.012352463,9分位数(quantile=0.9)的耗时为0.014458005s。

    • metrics_sum必须存在表示指标样本总值
    • metrics_count必须存在表示指标样本总个体数
    • metrics 每一个值表示单个样本在不同的区间的一个平均值
    • quantile是分位图自带标签
    # HELP prometheus_tsdb_wal_fsync_duration_seconds Duration of WAL fsync.
    # TYPE prometheus_tsdb_wal_fsync_duration_seconds summary
    prometheus_tsdb_wal_fsync_duration_seconds{quantile="0.5"} 0.012352463
    prometheus_tsdb_wal_fsync_duration_seconds{quantile="0.9"} 0.014458005
    prometheus_tsdb_wal_fsync_duration_seconds{quantile="0.99"} 0.017316173
    prometheus_tsdb_wal_fsync_duration_seconds_sum 2.888716127000002
    prometheus_tsdb_wal_fsync_duration_seconds_count 216
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    Histogram

    • le是柱状图自带标签
    • metrics_sum必须存在表示指标样本总值
    • metrics_count必须存在表示指标样本总个体数
    • 每个样本的值表示样本的个数

    又可以叫做累计直方图 比如小于409600样本个数0,但小于6.5536e+06样本个数为780,而总数量780,小于2.62144e+07样本个数为780,也就是说[6.5536e+06,2.62144e+07]样本个数为0

    # HELP prometheus_tsdb_compaction_chunk_range Final time range of chunks on their first compaction
    # TYPE prometheus_tsdb_compaction_chunk_range histogram
    prometheus_tsdb_compaction_chunk_range_bucket{le="100"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="400"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="1600"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="6400"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="25600"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="102400"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="409600"} 0
    prometheus_tsdb_compaction_chunk_range_bucket{le="1.6384e+06"} 260
    prometheus_tsdb_compaction_chunk_range_bucket{le="6.5536e+06"} 780
    prometheus_tsdb_compaction_chunk_range_bucket{le="2.62144e+07"} 780
    prometheus_tsdb_compaction_chunk_range_bucket{le="+Inf"} 780
    prometheus_tsdb_compaction_chunk_range_sum 1.1540798e+09
    prometheus_tsdb_compaction_chunk_range_count 780
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    总结

    • 上述为prometheus最常用4个度量的数据协议格式
    • 这些数据会被写入tsdb
    • 任何自定义的协议符合上述格式,都可以被prometheus体系接收
    • Histogram可以通过histogram_quantile()函数计算出其值的分位数,并且在服务端计算,性能较差
    • summary本身就是分位数数据存储格式,

    备注-协议规范

    如果当前行以# HELP开始,Prometheus将会按照以下规则对内容进行解析,得到当前的指标名称以及相应的说明信息:
    
    # HELP  
    如果当前行以# TYPE开始,Prometheus会按照以下规则对内容进行解析,得到当前的指标名称以及指标类型:
    
    # TYPE  
    TYPE注释行必须出现在指标的第一个样本之前。如果没有明确的指标类型需要返回为untyped。 除了# 开头的所有行都会被视为是监控样本数据。 每一行样本需要满足以下格式规范:
    
    metric_name [
      "{" label_name "=" `"` label_value `"` { "," label_name "=" `"` label_value `"` } [ "," ] "}"
    ] value [ timestamp ]
    其中metric_name和label_name必须遵循PromQL的格式规范要求。value是一个float格式的数据,timestamp的类型为int64(从1970-01-01 00:00:00以来的毫秒数),timestamp为可选默认为当前时间。具有相同metric_name的样本必须按照一个组的形式排列,并且每一行必须是唯一的指标名称和标签键值对组合。
    
    需要特别注意的是对于histogram和summary类型的样本。需要按照以下约定返回样本数据:
    
    类型为summary或者histogram的指标x,该指标所有样本的值的总和需要使用一个单独的x_sum指标表示。
    类型为summary或者histogram的指标x,该指标所有样本的总数需要使用一个单独的x_count指标表示。
    
    对于类型为summary的指标x,其不同分位数quantile所代表的样本,需要使用单独的x{quantile="y"}表示。
    
    对于类型histogram的指标x为了表示其样本的分布情况,每一个分布需要使用x_bucket{le="y"}表示,其中y为当前分布的上位数。同时必须包含一个样本x_bucket{le="+Inf"},并且其样本值必须和x_count相同。
    对于histogram和summary的样本,必须按照分位数quantile和分布le的值的递增顺序排序。
    以下是类型为histogram和summary的样本输出示例:
    
    # A histogram, which has a pretty complex representation in the text format:
    # HELP http_request_duration_seconds A histogram of the request duration.
    # TYPE http_request_duration_seconds histogram
    http_request_duration_seconds_bucket{le="0.05"} 24054
    http_request_duration_seconds_bucket{le="0.1"} 33444
    http_request_duration_seconds_bucket{le="0.2"} 100392
    http_request_duration_seconds_bucket{le="+Inf"} 144320
    http_request_duration_seconds_sum 53423
    http_request_duration_seconds_count 144320
    
    # Finally a summary, which has a complex representation, too:
    # HELP rpc_duration_seconds A summary of the RPC duration in seconds.
    # TYPE rpc_duration_seconds summary
    rpc_duration_seconds{quantile="0.01"} 3102
    rpc_duration_seconds{quantile="0.05"} 3272
    rpc_duration_seconds{quantile="0.5"} 4773
    rpc_duration_seconds_sum 1.7560473e+07
    rpc_duration_seconds_count 2693
    对于某些Prometheus还没有提供支持的编程语言,用户只需要按照以上规范返回响应的文本数据即可
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
  • 相关阅读:
    Pyhon-每日一练(1)
    简易根文件系统构建实验及过程详解
    一篇文章带你了解网页框架——Vue简单入门
    CV计算机视觉每日开源代码Paper with code速览-2023.10.12
    Electron录制应用-打包静态文件问题【命令行ffmpeg导不出视频】
    按权值建树,平面几何
    含镧系配合物荧光/有机硅烷/二氧化硅/二氧化硅气凝胶聚苯乙烯微球改性与制备
    【ACG】博主在专栏更新内容后,及时通知关注他的用户去阅读
    c语言练习题83:#include“ “和#include<>的区别
    Linux-服务管理
  • 原文地址:https://blog.csdn.net/qq_35529969/article/details/126863208