暂无图片
暂无图片
2
暂无图片
暂无图片
暂无图片

Grafana 显示有问题 ? 你可能没设好maxDataPoints

TiDB之路 2022-03-04
6892

前言

最近在使用Grafana
的时候,发现了一个时间拉长后峰值被平均的问题。

问题背景

这是我测试环境的TiDB
,可以看到Slow query
面板,当我把时间调整到30 days
之后,最高的大概是1.94 s。

但是当我点这个峰进去看的时候,时间变成了2.08 min

那么这就导致出现了一个问题。

客户: "我想看最近一个月的tps
峰值 ?"

按照我第一种方法查,肯定是错误的,因为这很明显被平均掉了。

原因

这个原因可以归结到一个叫maxDataPoints
的参数上。在Grafana
中它使用Graphite
进行渲染 。查阅Graphite
的文档。

maxDataPoints

Set the maximum numbers of datapoints for each series returned when using json content.

If for any output series the number of datapoints in a selected range exceeds the maxDataPoints value then the datapoints over the whole period are consolidated.

The function used to consolidate points can be set using the consolidateBy function.

maxDataPoints
的作用:

设置使用 json 内容时返回的每个series
图表的最大数据点数。对于任何输出series
图表,选定范围内的数据点数超过 maxDataPoints
值,则合并整个期间的数据点。合并点的函数可以使用 consolidateBy 函数进行设置。

所以我们还需要再查阅 consolidateBy 函数。

consolidateBy
(seriesList, consolidationFunc)

Takes one metric or a wildcard seriesList and a consolidation function name.

Valid function names are ‘sum’, ‘average’/’avg’, ‘min’, ‘max’, ‘first’ & ‘last’.

When a graph is drawn where width of the graph size in pixels is smaller than the number of datapoints to be graphed, Graphite consolidates the values to to prevent line overlap. The consolidateBy() function changes the consolidation function from the default of ‘average’ to one of ‘sum’, ‘max’, ‘min’, ‘first’, or ‘last’. This is especially useful in sales graphs, where fractional values make no sense and a ‘sum’ of consolidated values is appropriate.

当绘制图形时,图形大小的宽度(以像素为单位)小于要绘制的数据点的数量,Graphite
会合并这些值以防止线重叠。函数默认使用average

其实也可以理解,就是比如你只有500像素的图片,但是你要放入20000个像素点,确实会重叠起来。所以它就给你搞平均,因此导致我们看30天的数据的时候显示不正确。

⚠️ 看我框的这两个位置,目前这个 interval 显示的是1小时,表示按照1小时平均绘制的数据点,也就是说这个图表,1小时显示一个点。

比如:
2/19 20:00:00 显示一个点
2/19 21:00:00 显示下一个点

它的公式等于 Max data points / time range
。所以要把这个纠正就需要调大Max data points

当我调整到30000的时候,这里就会显示出按照1分钟来平均。这样的话还是可以显示出峰值的。

后记

这是一个小问题,但是这个问题很容易误导人。不要再踩坑了。

refenerce

https://addshore.com/2018/09/grafana-graphite-and-maxdatapoints-confusion-for-totals/


文章转载自TiDB之路,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论