数据模型
数据模型
<metric name>{<label name>=<label value>, …}
。一条
promhttp_metric_handler_requests_total{code="200",instance="192.168.0.107:9090",job="prometheus"} 106
除了存储时间序列数据外,
Metrics Name & Label
每条时间序列是由唯一的指标名称和一组标签http_requests_total
这样,它有一些命名规则,可以包字母数字之类的的。通常是以 应用名称开头_监测对像_数值类型_单位
这样。
-
push_total
-
userlogin_mysql_duration_seconds
-
app_memory_usage_bytes
标签 就是对一条时间序列不同维度的识别了,例如 一个
http_requests_total{method="POST",endpoint="/api/tracks"}
针对
Counter:只增不减的计数器
rate(node_network_receive_bytes_total[5m])
[5m]
意为使用过去五分钟的数据进行计算,即会得到过去五分钟的平均值:
{device="lo",instance="localhost:9100",job="node"} 1859.389655172414
{device="wlan0",instance="localhost:9100",job="node"} 1314.5034482758622
sum without(device)(rate(node_network_receive_bytes_total[5m]))
# {instance="localhost:9100",job="node"} 3173.8931034482762
或者我们也可以指定获取某个网卡的数据:
sum without(instance)(rate(node_network_receive_bytes_total{device="eth0"}[5m]))
# {device="eth0",job="node"} 3173.8931034482762
Gauge:可增可减的仪表盘
譬如
sum without(device, fstype, mountpoint)(node_filesystem_size_bytes)
这里的
node_filesystem_free_bytes{device="/dev/sda1",fstype="vfat",
instance="localhost:9100",job="node",mountpoint="/boot/efi"} 70300672
node_filesystem_free_bytes{device="/dev/sda5",fstype="ext4",
instance="localhost:9100",job="node",mountpoint="/"} 30791843840
node_filesystem_free_bytes{device="tmpfs",fstype="tmpfs",
instance="localhost:9100",job="node",mountpoint="/run"} 817094656
node_filesystem_free_bytes{device="tmpfs",fstype="tmpfs",
instance="localhost:9100",job="node",mountpoint="/run/lock"} 5238784
node_filesystem_free_bytes{device="tmpfs",fstype="tmpfs",
instance="localhost:9100",job="node",mountpoint="/run/user/1000"} 826912768
# 聚合的结果如下
{instance="localhost:9100",job="node"} 32511390720
同样地,我们也可以忽略
sum without(device, fstype, mountpoint, instance)(node_filesystem_size_bytes)
{job="node"} 32511390720
您可以对其他聚合使用相同的方法。
max without(device, fstype, mountpoint)(node_filesystem_size_bytes)
# {instance="localhost:9100",job="node"} 30792601600
avg without(instance, job)(process_open_fds)
对于
delta(cpu_temp_celsius{host="zeus"}[2h])
还可以使用
predict_linear(node_filesystem_free{job="node"}[1h], 4 * 3600)
使用Histogram 和Summary 分析数据分布情况
除了
在大多数情况下人们都倾向于使用某些量化指标的平均值,例如
为了区分是平均的慢还是长尾的慢,最简单的方式就是按照请求延迟的范围进行分组。例如,统计延迟在
例如,指标
# 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
从上面的样本中可以得知当前
# 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
与_count
作为后缀_sum
作为后缀
同时对于