如何在 ubuntu 中安装最新版本的 prometheus/promtool?

ana*_*abu 8 rules grafana prometheus prometheus-alertmanager

我下载的prometheus版本是2.3.2

wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz
Run Code Online (Sandbox Code Playgroud)

untared 和 prometheus 已经作为服务运行。

我想使用 promtool 验证我的 Prometheus 警报管理器规则。从下面的博客创建了一个规则。

https://petargitnik.github.io/blog/2018/01/04/how-to-write-rules-for-prometheus

当我运行 promtool 检查规则 /etc/prometheus/prometheus.rules.yml

它说,没有安装 Promtheus,所以使用 apt get prometheus 再次安装

但这是安装了旧版的 promtool,这里是版本详细信息:

    root@UTVA-kafka-msg-size-2mb-02509:/home/ubuntu# promtool version
prometheus, version 0.16.2+ds (branch: debian/sid, revision: 0.16.2+ds-1ubuntu1)

build user:       pkg-go-maintainers@lists.alioth.debian.org
  build date:       20160408-04:15:29
  go version:       go1.6
Run Code Online (Sandbox Code Playgroud)

Prometheus 版本 2 使用 yml 文件作为规则,较旧的使用一些不同的文件,所以我的 promtool 检查规则失败了。

谁能建议如何升级最新的promtool?

谢谢。

use*_*304 8

您可以使用go直接从 github 安装最新/所需版本。请确保您有设置。为方便起见,还将 GOPATH 添加到您的 PATH,例如对于 ZSH:

export PATH=$PATH:$GOPATH/bin
Run Code Online (Sandbox Code Playgroud)

然后您可以使用go get以下方法安装它:

GO111MODULE=on go get github.com/prometheus/prometheus/cmd/promtool
Run Code Online (Sandbox Code Playgroud)

现在您的 PATH 中有 GOPATH,您可以简单地从 shell 调用它:

?  ~ promtool --version
promtool, version  (branch: , revision: )
 build user:
 build date:
 go version:       go1.12.7
Run Code Online (Sandbox Code Playgroud)

编辑:

确保您GO111MODULE=ongo命令前加上目录,因为vendor目录已被删除

  • 使用 https 方案的“go get”不起作用。正确的是 `go get github.com/prometheus/prometheus/cmd/promtool` (2认同)

vic*_*era 8

更新的答案:

从 Go >= 1.16 开始,您不应再go get在特定项目之外进行全局安装。

通常你想使用go install

# This won't work
go install github.com/prometheus/prometheus/cmd/promtool@latest
Run Code Online (Sandbox Code Playgroud)

但 promtool 不是 github.com/prometheus/prometheus 上的主要项目,因此这是行不通的。

您可以使用以下命令即时下载最新的 promtool 二进制文件并将其解压缩到当前目录:

VERSION=$(curl -Ls https://api.github.com/repos/prometheus/prometheus/releases/latest | jq ".tag_name" | xargs | cut -c2-)
wget -qO- "https://github.com/prometheus/prometheus/releases/download/v${VERSION}/prometheus-$VERSION.linux-amd64.tar.gz" \
  | tar xvzf - "prometheus-$VERSION.linux-amd64"/promtool --strip-components=1
Run Code Online (Sandbox Code Playgroud)

请注意,api.github.com如果您在短时间内进行多次呼叫,则呼叫会受到 IP 限制。

如果你想安装Alertmanager CLI amtool,更简单:

# This takes 450Mb, look for the alternative
go install github.com/prometheus/alertmanager/cmd/amtool@latest
Run Code Online (Sandbox Code Playgroud)

但这会占用您磁盘 450Mb 的空间。要仅使用 25Mb aprox,请改为:

# This takes 450Mb, look for the alternative
go install github.com/prometheus/alertmanager/cmd/amtool@latest
Run Code Online (Sandbox Code Playgroud)

最后,如果您对 linting 规则感兴趣,请查看CloudFlare 的pint(阅读此博客文章):

VERSION=$(curl -Ls https://api.github.com/repos/prometheus/alertmanager/releases/latest | jq ".tag_name" | xargs | cut -c2-)
wget -qO- "https://github.com/prometheus/alertmanager/releases/download/v${VERSION}/alertmanager-$VERSION.linux-amd64.tar.gz" \
  | tar xvzf - "alertmanager-$VERSION.linux-amd64"/amtool --strip-components=1
Run Code Online (Sandbox Code Playgroud)