how to install latest version of prometheus/promtool in ubuntu?
Asked Answered
T

3

13

I downloaded my prometheus version is 2.3.2

wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz

untared and prometheus already running as service.

I want to verify my Prometheus alert manager rule using promtool. created one rule from below blog.

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

when I run the promtool check rules /etc/prometheus/prometheus.rules.yml

it says, Promtheus not installed, so installed again using apt get prometheus

but this is installed older verion of promtool, here is version details:

    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:       [email protected]
  build date:       20160408-04:15:29
  go version:       go1.6

Prometheus version 2 using yml file for rules, older usign some different one, so my promtool check-rules is failing.

Can anyone suggest how to upgrade latest promtool?

Thanks.

Tycho answered 22/2, 2019 at 2:22 Comment(0)
A
9

Updated answer:

Starting with Go >= 1.16 you should no longer use go get to globally install outside a specific project.

Usually you would like to use go install:

# This won't work
go install github.com/prometheus/prometheus/cmd/promtool@latest

But promtool is not the main project on github.com/prometheus/prometheus, so that will not work.

You can download and uncompress the latest promtool binary on the fly to the current directory using:

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

Take into consideration that calls to api.github.com are IP throttle if you make many in a short time.

If you want to install Alertmanager CLI amtool, it's simpler:

# This takes 450Mb, look for the alternative
go install github.com/prometheus/alertmanager/cmd/amtool@latest

But that will take 450Mb from your disk. To use only 25Mb aprox, instead:

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

Lastly, if you are interested in linting rules, take a look at pint from CloudFlare (read this blog post):

VERSION=$(curl -Ls https://api.github.com/repos/cloudflare/pint/releases/latest | jq ".tag_name" | xargs | cut -c2-)
wget -qO- "https://github.com/cloudflare/pint/releases/download/v${VERSION}/pint-$VERSION-linux-x86_64.tar.gz" \
  | tar xvzf - pint-linux-amd64 && mv pint-linux-amd64 pint
Annamarieannamese answered 24/7, 2022 at 10:22 Comment(0)
S
8

You can use go to install the latest/desired version directly from github. Make sure you have go setup. For convenience also add GOPATH to your PATH, e.g. for ZSH:

export PATH=$PATH:$GOPATH/bin

And then you can install it using go get:

GO111MODULE=on go get github.com/prometheus/prometheus/cmd/promtool

Now that you have GOPATH in your PATH you can simply call it from your shell:

➜  ~ promtool --version
promtool, version  (branch: , revision: )
 build user:
 build date:
 go version:       go1.12.7

EDIT:

Make sure you prepend GO111MODULE=on to the go command as the vendor directory has been removed

Sheriesherif answered 30/9, 2019 at 12:55 Comment(2)
go get with the https scheme don't work. Correct is go get github.com/prometheus/prometheus/cmd/promtoolEllingston
Since 1.17 go get does not work anymore for installing commands. However I could not install it using go install neither. It complains about the go.mod file containing replace directives. Any idea? go.dev/doc/go-get-install-deprecationDanieu
E
0

I had to include the branch:

GO111MODULE=on go get -v github.com/prometheus/prometheus/cmd/promtool@master
Eng answered 16/2, 2022 at 12:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.