|NO.Z.00304|——————————|CloudNative|——|KuberNetes&运维.V24|——|监控.v01|PromQL查询_实例|
一、PromQL基本操作
### --- 通过Prometheus通过自带的WEB-UI来查询
~~~ # 查询方式一: 瞬时向量:包含该时间序列中最新的样本值
~~~ # 查询方式二: 区间向量:带时间戳的:一段时间范围内的数据
### --- 操作符优先级:
~~~ ^
~~~ * / %
~~~ + -
~~~ == != <= < >= >
~~~ And unless
~~~ or
一、Prometheus查询实例:瞬时向量:查询当前的请求数
### --- 瞬时向量:查询当前的请求数
~~~ # ——>瞬时向量:Enable query history——>http_request_total(查询当前的请求数)
~~~ ——>Execute——>查询出当前https请求的向量:当前最新的向量
~~~ # ——>瞬时向量:
~~~ 查看30分钟之前的瞬时向量:值为2 offset 30m
~~~ # ——>瞬时向量:Enable query history
~~~ ——>http_request_total{endpoint="http",handler="/datasources/proxy/:id/*",instance="172.17.125.18:3000",job="grafana",method="get",namespace="monitoring",pod="grafana-5d9d5f67c4-68kxb",service="grafana",statuscode="502"} offset 30m
~~~ ——>Execute——>这个表达式符合规则的有15个——>当前值为15——>END


二、区间向量:
### --- 区间向量:
~~~ ——>区间向量:当前值:默认即是1
~~~ ——>Enable query history——>http_request_total{endpoint="http",handler="/",instance="172.17.125.18:3000",job="grafana",method="get",namespace="monitoring",pod="grafana-5d9d5f67c4-68kxb",service="grafana",statuscode="200"}
~~~ ——>Execute——>这个表达式符合规则的就这一个——>当前的值是1
~~~ # ——>区间向量:最近5分钟的向量值:[5m]
~~~ ——>若是需要查看最近5分钟的数据:需要在表达式后面加上——>表达式[5m]——>Execute——>当前的值是5——>是一个时间戳:是可以转换时间的——>END
~~~ # ——>区间向量:1个小时之前5分钟的向量:[5m] offset 1h
~~~ ——>offset:查看多少分钟之前的数据:offset 30m:30分钟
~~~ ——>表达式[5m]——>后面追加offsete 1h——>Execute



Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了