使用 Prometheus 监控 bash 命令或 shell 脚本的结果

Monitor result of a bash command or shell script using Prometheus

我的需求是监控Kubernetes集群内运行公司的helpdesk系统,例如URLhttps://xyz.zendesk.com

他们提供 API set 来有效监控。

我们可以使用 curl

轻松检查状态
$ curl -s "https://status.zendesk.com/api/components/support?domain=xyz.zendesk.com" | jq '.active_incidents'
[]

以上输出表示根据 zendesk 文档的成功状态。

现在主要的部分是,公司用Prometheus监控一切。

如何让 Prometheus 从这个 curl 命令的输出中检查成功状态?

我已经做了一些研究,发现了一些相关的话题 here and using pushgateway

它们是否适用于我的要求或走错了路线?

您可能(!?)想要的是:

  1. 提供 HTTP(s)(例如 /metrics)端点
  2. 以 Prometheus 的说明格式生成指标
  3. 来自 Zendesk 的 API

NOTE curl only gives you #3

有一些似乎满足要求的解决方案示例,但 none 来自 Zendesk:

https://www.google.com/search?q=%22zendesk%22+prometheus+exporter

还有 >2 个其他 Prometheus 导出器列表(都不包含 Zendesk):

我建议您联系 Zendesk 并询问是否已经有 Prometheus Exporter。没有找到真是令人惊讶。

编写Prometheus Exporter 很简单。 Prometheus Client libraries and Zendesk API client 可用且首选。虽然有可能,但 bash 可能不是最佳选择。

如果 all 你想要做的是获取静态端点,获取 200 响应代码并确认正文是 [],你可以使用普罗米修斯 Blackbox exporter

NOTE Logging and monitoring tools often provide a higher-level tool that provides something analogous to a "universal translator", facilitating translation from 3rd-party systems' native logging|monitoring formats into some canonical form using config rather than code. Although in the logging space, fluentd is an example. To my knowledge, there is no such tool for Prometheus but I sense that there's an opportunity for someone to create one.