如何使用 Promdash 或 Grafana 可视化直方图?

How can I visualize a histogram with Promdash or Grafana?

我被直方图(和摘要)时间序列吸引到普罗米修斯,但我一直未能在 promdash 或 grafana 中显示直方图。我期望的是能够显示:

示例指标是 HTTP 服务器的响应时间。

我认为 Grafana 不支持直方图的条形图。

您可以制作一个标准的非堆叠率图表直方图,由于 Prometheus 直方图是累积的,您将得到您要查找的结果。

上面@brian-brazil 的回答几乎可以工作,还有一些额外的,没有提到的事情要做。

You can do a standard non-stacked graph of the rate a histogram, and as Prometheus histograms are cumulative you'll get the result you're looking for.

  1. Grafana中的x-axis需要在mode series
  2. 如果您为系列使用其他不同的标签,则需要按 le 标签汇总结果

之后你会得到一个漂亮的直方图。唯一让我厌烦的是 grafana 的 x-axis 排序顺序是自然的字符串排序。所以x轴以+Inf开头,然后是0.1,0.2,.. 1,1.5,10,2,...

PS:在 grafana 5.1 there will be working heatmap with prometheus datasource out-of-box. There was an issue 中提供对热图可视化的原生支持,这也适用于(如果您想查看 tendency/history)随着时间的推移可视化直方图。

Grafana v5+ 直接支持将 Prometheus 直方图表示为热图。 http://docs.grafana.org/features/panels/heatmap/#histograms-and-buckets

热图优于直方图,因为直方图不会显示趋势如何随时间变化。所以如果你有一个时间序列直方图,然后使用热图面板来描绘它。

为了帮助您入门,这里有一个示例(针对 Prometheus 数据):

假设您有一个直方图,

http_request_duration_seconds_bucket(le=0.2) 1,
http_request_duration_seconds_bucket(le=0.5) 2,
http_request_duration_seconds_bucket(le=1.0) 2,
http_request_duration_seconds_bucket(le=+inf) 5
http_request_duration_seconds_count 5
http_request_duration_seconds_sum 3.07

您可以使用以下查询将此直方图数据描绘成热图:sum(increase(http_request_duration_seconds_bucket[10m])) by (le),确保将格式设置为“热图”,将图例格式设置为 {{ le }},并设置可视化在面板设置中设置为“热图”。

Grafana 的最新版本具有内置的热图可视化类型,但请谨慎使用它,因为它可能非常 计算量大。

可以通过选择 Graph 可视化然后在 Axes 下为 X-Axis>Mode.

选择 Histogram 来获得直方图

这里是 Grafana 7.03 的例子。 ceph_exporter 收集的数据进入 Prometheus。指标是 ceph_osd_utilization。查询使用模板化变量,但这与这个问题正交。