exporter暴漏的数据以下边的方式进行呈现
# HELP node_filesystem_free_bytes Filesystem free space in bytes. #解释
# TYPE node_filesystem_free_bytes gauge #数据类型
node_filesystem_free_bytes{device="/dev/mapper/centos_test- root",fstype="xfs",mountpoint="/"} 1.163782144e+10 #metric和对应的值
node_filesystem_free_bytes{device="/dev/sda1",fstype="xfs",mountpoint="/boot"} 7.6972032e+07
node_filesystem_free_bytes{device="rootfs",fstype="rootfs",mountpoint="/"} 1.163782144e+10
node_filesystem_free_bytes{device="tmpfs",fstype="tmpfs",mountpoint="/run"} 9.43960064e+08
node_filesystem_free_bytes{device="tmpfs",fstype="tmpfs",mountpoint="/run/user/0"} 1.90795776e+08
# HELP node_filesystem_readonly Filesystem read-only status.
# TYPE node_filesystem_readonly gauge
node_filesystem_readonly{device="/dev/mapper/centos_test-root",fstype="xfs",mountpoint="/"} 0
node_filesystem_readonly{device="/dev/sda1",fstype="xfs",mountpoint="/boot"} 0
node_filesystem_readonly{device="rootfs",fstype="rootfs",mountpoint="/"} 0
node_filesystem_readonly{device="tmpfs",fstype="tmpfs",mountpoint="/run"} 0
node_filesystem_readonly{device="tmpfs",fstype="tmpfs",mountpoint="/run/user/0"} 0
然后prometheus拉取瞬时的(那一刻的数据)exporter暴露的数据,以时间序列的格式存储在自身的tsdb(时间序列数据库)数据库,当在prometheus web查询时,获取的数据也是那一瞬间的数据,可称作瞬时向量。存储在tsdb的数据格式如下:
<--------------- metric ---------------------><-timestamp -><-value->
up{instance="192.168.71.21:9100",job="node_exporter"}@1600572300 =>1
up{instance="192.168.71.22:9100",job="node_exporter"}@1600572300 =>0
up{instance="localhost:9090",job="prometheus"}@1600572300 =>1
标签匹配(瞬时向量)
根据标签进行匹配,获取的值是那一瞬间的值
node_filesystem_avail_bytes{device="/dev/mapper/centos_test-root"}
node_filesystem_avail_bytes{device!="/dev/mapper/centos_test-root"}
node_filesystem_avail_bytes{mountpoint=~"/boot|/|/run"}
node_filesystem_avail_bytes{mountpoint=~!"/boot|/|/run"}
范围查询(区间向量查询)
查询一定时间范围内的数据
node_memory_MemFree_bytes{}[1m]
时间单位有:
时间位移查询
查询之前某个时间点的数据,也是瞬时向量
node_memory_MemFree_bytes{} offset 1m
数学运算符
布尔运算
==
(相等)!=
(不相等)>
(大于)<
(小于)>=
(大于等于)<=
(小于等于)布尔操作符,改变运算行为,使结果输出为1或0,符合运算就输出0,否则输出1
metric{label=value} > bool 100
集合运算符
操作符优先级
^
*, /, %
+, -
==, !=, <=, <, >=, >
and, unless
or
向量与向量之间的计算
像
node_filesystem_avail_bytes / ignoring(device,fstype,mountpoint) group_left up
1. 按照mode计算cpu平均使用时间
avg(node_cpu_seconds_total) by (mode)
2. 计算http请求数前5位的时间序列
topk(5,prometheus_http_requests_total)
1. 根据2小时内的数据,计算未来4个小时,磁盘剩余空间是否为0
predict_linear(node_filesystem_files_free{device="/dev/mapper/centos_test-root"}[2h],4*3600)<0
2. 标签替换
格式
label_replace(v,dest_label,dest_value,replace_label,regx)