构建blackbox导出程序时出错

时间:2016-06-05 02:41:52

标签: prometheus

我是Prometheus的新手,目前正在尝试解决构建blackbox导出器(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

请告知。

2 个答案:

答案 0 :(得分:4)

在构建可执行文件时,

go会在src $GOPATH子文件夹中查找。有关此问题的文档,请参阅https://golang.org/doc/code.html#GOPATH。我能够使用make构建可执行文件,但go install需要更少的步骤。

这些步骤对我有用:

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

如果未遇到任何错误,则可执行文件应位于$GOPATH/bin/blackbox_exporter。可执行文件需要能够找到blackbox.yml中的$GOPATH/src/blackbox_exporter。我使用:

运行可执行文件
cd $GOPATH/src/blackbox_exporter
$GOPATH/bin/blackbox_exporter

答案 1 :(得分:1)

遇到同样的错误,没有一个答案奏效;解决了它:

$go version
go version go1.7 linux/amd64

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