获取Prometheus中HTTP端点返回的HTTP代码的起始时间点和停止时间点。

huangapple go评论63阅读模式
英文:

Getting a start and stop time points of returning HTTP codes by HTTP endpoint, in Prometheus

问题

让我们假设我们有一天的时间范围 - 00:00 - 23:59,以及一个HTTP端点(由Blackbox-exporter探测),返回的状态码如下:

  • 从00:00到7:00,端点返回200
  • 然后从7:00到7:05返回500
  • 然后从7:05到20:00返回200
  • 然后从20:00到20:10返回404
  • 从20:10到23:59返回200

我能否在Prometheus中以某种方式反映它,即当一个代码结束返回并另一个开始时?而且也许可以在Grafana上以时间范围图的方式输出?

(Note: The code parts have been omitted as requested.)

英文:

Let's assume we have a time range of day - 00:00 - 23:59 and HTTP endpoint(which is being probed by Blackbox-exporter) returns status codes:

  • from 00:00 to 7:00 endpoint was returning 200
  • then from 7:00 to 7:05 was returning 500
  • then from 7:05 to 20:00 was returning 200
  • then from 20:00 to 20:10 was returning 404
  • and from 20:10 to 23:59 was returning 200

Can I reflect it somehow in Prometheus, i.e. when one code ends up being returned and another one started? And maybe it's possible to output somehow in Grafana on a time-range plot?

答案1

得分: 1

If all you want is just to visualize status code, you don't need some clever promQL query for this.

You can simply create "State timeline" panel with probe_http_status_code query.

To make this panel show data in understandable way:

  1. Expand query options (under query), select Legend: Custom, and put {{instance}} into it.
  2. Go to Panel options: Standard options > Color scheme > Single color.
  3. Value mappings: add HTTP codes with corresponding colors. You can make mappings single value or range based.

In the result you'll get something like this:
获取Prometheus中HTTP端点返回的HTTP代码的起始时间点和停止时间点。

英文:

If all you want is just to visualize status code, you don't need some clever promQL query for this.

You can simply create "State timeline" panel with probe_http_status_code query.

To make this panel show data in understandable way:

  1. Expand query options (under query), select Legend: Custom, and put {{instance}} into it.
  2. Go to Panel options: Standard options > Color scheme > Single color.
  3. Value mappings: add HTTP codes with corresponding colors. You can make mappings single value or range based.

In the result you'll get something like this:
获取Prometheus中HTTP端点返回的HTTP代码的起始时间点和停止时间点。

huangapple
  • 本文由 发表于 2023年4月17日 22:44:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定