首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >Prometheus监控学习笔记之查询报错could not parse expression: parse error at char 107: range specification must b

Prometheus监控学习笔记之查询报错could not parse expression: parse error at char 107: range specification must b

作者头像
Jetpropelledsnake21
发布2022-05-23 10:36:40
发布2022-05-23 10:36:40
1.1K0
举报
文章被收录于专栏:JetpropelledSnakeJetpropelledSnake

0x00 概述

在进行Prometheus查询或者新增Prometheus Alerts时候,会出现报错could not parse expression: parse error at char 107: range specification must be preceded by a metric selector;

初步看以为是查询语句写错了,其实此处是查询语句包含SubQuery导致的问题,是Prometheus版本过低导致的。

0x01 问题现象

在版本为2.1的Prometheus上查询最近7天的CPU最大利用率的时候,返回报错,报错可以参考此issue,

could not parse expression: parse error at char 107: range specification must be preceded by a metric selector #9

查询语句为:

sum(max_over_time(irate(container_cpu_usage_seconds_total{namespace!='',container_name!='',container_name!='POD}[5m])[7d:1m])*100) by (namespace,container_name)";

查询语句中使用了2个函数,分别为max_over_time和sum;

0x02 问题解决

在Prometheus的理解中,是将max_over_time查询后再进行了sum查询,官方定义为subQuery;

根据官方的文档,subQuery功能是在版本2.7才加入的,所以如果出现以上报错,请检查Prometheus版本是否低于2.7;

如果版本是高于2.7,则说明是查询语句有问题,需要修改查询语句。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-22,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 0x00 概述
  • 0x01 问题现象
  • 0x02 问题解决
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档