采用普罗米修斯(Prometheus )监控各个指标的含义,类型,以及格式

1. Prometheus 监控指标的类型

普罗米修斯主要有四种类型的监控指标:

  1. Counter类型的指标:其工作方式和计数器一样,只增不减(除非系统发生重置)。常见的监控指标,如机器的启动时间(node_cpu),HTTP访问量(http_requests_total)等。可以通过PromQL语句对这些指标进行分析,如:
    查询当前系统中,访问量前10的HTTP地址:
topk(10, http_requests_total)
  1. Gauge即仪表类型的指标,侧重于反应系统的当前状态,样本数据可增可减。如CPU使用率(node_memory_MemFree,主机当前空闲的内容大小),内存使用率(node_memory_MemAvailable,可用内存大小),集群节点个数,大部分监控数据都是这种类型的。
    如可通过PromQL内置函数delta()可以获取样本在一段时间返回内的变化情况。例如,计算CPU温度在两个小时内的差异:
delta(cpu_temp_celsius{
    
    host="zeus"}[2h])
  1. Histogram:也就是直方图类型的metric, 能够分组分区间显示指标的信息。例如,统计延迟在0 ~ 10ms之间的请求数有多少而10~20ms之间的请求数就可采用这种方式。注意他与summary的区别。
  2. summary:好像不是很好翻译,个人认为是表示分位数(quantile)的信息。分位数0.5表示前50%的数据是什么水平,现实生活中的例子比如班上所有学生身高的中位数,同样的分位数0.9表示前90%身高的划分位置。
    这个可以参考官方文档上的例子:

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

2. Prometheus 监控指标的格式

2. 1 时间序列

这就涉及到Prometheus存储数据的方式是时间序列的,所谓的时间序列其实就是关于指标的集合,只不过这些指标是按照时间顺序排列的。

每条time-series通过指标名称(metrics name)和一组标签集(labelset)命名。如下所示,可以将time-series理解为一个以时间为Y轴的数字矩阵:
^
│ . . . . . . . . . . . . . . . . . . . node_cpu{cpu=“cpu0”,mode=“idle”}
│ . . . . . . . . . . . . . . . . . . . node_cpu{cpu=“cpu0”,mode=“system”}
│ . . . . . . . . . . . . . . . . . . node_load1{}
│ . . . . . . . . . . . . . . . . . .
v
<------------------ 时间 ---------------->

在time-series中的每一个点称为一个样本(sample),样本由以下三部分组成:
指标(metric):metric name和描述当前样本特征的labelsets;
时间戳(timestamp):一个精确到毫秒的时间戳;
样本值(value): 一个float64的浮点型数据表示当前样本的值。
如:http_request_total{status=“200”, method=“GET”}@1434417561287 => 94334

2.2 metric格式

每一条metric的格式是:

< metric name>{
    
    < label name>=< label value>, ...}

其中以__作为前缀的标签,是系统保留的关键字,只能在系统内部使用。
注意: 实际获取的信息可能不仅仅包含metric,还有一些注释,他们都以#开头,其中HELP用于解释当前指标的含义,TYPE则说明当前指标的数据类型。

如下面这条信息,就包含了两条metric。

# HELP node_cpu Seconds the cpus spent in each mode.
# TYPE node_cpu counter
node_cpu{
    
    cpu="cpu0",mode="idle"} 362812.7890625
# HELP node_load1 1m load average.
# TYPE node_load1 gauge
node_load1 3.0703125

参考资料:

  1. https://yunlzheng.gitbook.io/prometheus-book/parti-prometheus-ji-chu/promql/prometheus-metrics-types#counter-zhi-zeng-bu-jian-de-ji-shu-qi
  2. https://www.modb.pro/db/45956

猜你喜欢

转载自blog.csdn.net/Sansipi/article/details/127042853
今日推荐