Error building blackbox exporter

2019-09-10 12:23发布

问题:

I am absolutely new to Prometheus and currently trying to troubleshoot the error that is being reflected while building blackbox exporter (https://github.com/prometheus/blackbox_exporter).

[root@sk004 blackbox_exporter]# pwd
/usr/local/blackbox_exporter
[root@sk004 blackbox_exporter]# echo $GOROOT
/usr/local/go/default
[root@sk004 blackbox_exporter]# echo $GOPATH
/usr/local/blackbox_exporter
[root@sk004 blackbox_exporter]# make
>> formatting code
can't load package: package _/usr/local/blackbox_exporter: cannot find package "_/usr/local/blackbox_exporter" in any of:
    /usr/local/go/src/_/usr/local/blackbox_exporter (from $GOROOT)
    /usr/local/blackbox_exporter/src/_/usr/local/blackbox_exporter (from $GOPATH)
make: *** [format] Error 1

Please advise.

回答1:

go looks in the srcsubfolder of $GOPATH when building the executable. See https://golang.org/doc/code.html#GOPATH for documentation about this. I was able to build the executable using make, but go install requires fewer steps.

These steps worked for me:

export GOPATH=/usr/local/go
mkdir -p $GOPATH/src
cd $GOPATH/src
git clone https://github.com/prometheus/blackbox_exporter.git
cd blackbox_exporter
go install

If no errors are encountered, the executable should be located at $GOPATH/bin/blackbox_exporter. The executable needs to be able to find blackbox.yml, which is in $GOPATH/src/blackbox_exporter. I ran the executable using:

cd $GOPATH/src/blackbox_exporter
$GOPATH/bin/blackbox_exporter


回答2:

Ran into same error and none of the answers worked; solved it by:

$go version
go version go1.7 linux/amd64

$go get github.com/prometheus/blackbox_exporter
$go build github.com/prometheus/blackbox_exporter


标签: prometheus