用Go (Ubuntu)编译失败



我正在尝试为Prometheus安装OpenVPN出口商,无论如何我已经将出口商下载到我的桌面,将该目录添加到我的$GOPATH路径,每当我尝试运行:

go build -o openvpn_exporter main.go

我收到消息:

src/github.com/prometheus/client_golang/prometheus/desc.go:22:2: cannot find package "github.com/cespare/xxhash/v2" in any of:
/usr/local/go/src/github.com/cespare/xxhash/v2 (from $GOROOT)
/home/ubuntu/openvpn_exporter-0.3.0/src/github.com/cespare/xxhash/v2 (from $GOPATH)
src/google.golang.org/protobuf/encoding/protowire/wire.go:15:2: cannot find package "math/bits" in any of:
/usr/local/go/src/math/bits (from $GOROOT)
/home/ubuntu/openvpn_exporter-0.3.0/src/math/bits (from $GOPATH)
src/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go:19:2: cannot find package "net/http/httptrace" in any of:
/usr/local/go/src/net/http/httptrace (from $GOROOT)
/home/ubuntu/openvpn_exporter-0.3.0/src/net/http/httptrace (from $GOPATH)

这是主要的。文件:

package main
import (
"flag"
"github.com/kumina/openvpn_exporter/exporters"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"strings"
)
func main() {
var (
listenAddress      = flag.String("web.listen-address", ":9176", "Address to listen on for web interface and telemetry.")
metricsPath        = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
openvpnStatusPaths = flag.String("openvpn.status_paths", "examples/client.status,examples/server2.status,examples/server3.status", "Paths at which OpenVPN places its status files.")
ignoreIndividuals  = flag.Bool("ignore.individuals", false, "If ignoring metrics for individuals")
)
flag.Parse()
log.Printf("Starting OpenVPN Exportern")
log.Printf("Listen address: %vn", *listenAddress)
log.Printf("Metrics path: %vn", *metricsPath)
log.Printf("openvpn.status_path: %vn", *openvpnStatusPaths)
log.Printf("Ignore Individuals: %vn", *ignoreIndividuals)
exporter, err := exporters.NewOpenVPNExporter(strings.Split(*openvpnStatusPaths, ","), *ignoreIndividuals)
if err != nil {
panic(err)
}
prometheus.MustRegister(exporter)
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`
<html>
<head><title>OpenVPN Exporter</title></head>
<body>
<h1>OpenVPN Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}

您的本地go安装有问题。我建议重新安装到最后一个版本。

我能够通过Docker重现导出器的安装。

FROM golang:1.16.7-buster
RUN go get github.com/kumina/openvpn_exporter
RUN ls -la $GOPATH/bin
> DOCKER_BUILDKIT=0 docker build --no-cache -t butuzov/none .
Sending build context to Docker daemon   5.12kB
Step 1/3 : FROM golang:1.16.7-buster
1.16.7-buster: Pulling from library/golang
627b765e08d1: Already exists 
c040670e5e55: Already exists 
073a180f4992: Already exists 
bf76209566d0: Already exists 
6182a456504b: Already exists 
636ca4e39e2f: Already exists 
9bf36a081430: Already exists 
Digest: sha256:8e8910fa802194a30d5ebfbf3065d304e9e853ac50466c523be07ca657d9d6a1
Status: Downloaded newer image for golang:1.16.7-buster
---> 0821480a2b48
Step 2/3 : RUN go get github.com/kumina/openvpn_exporter
---> Running in f6b8b33eaedb
go: downloading github.com/kumina/openvpn_exporter v0.3.0
go: downloading github.com/prometheus/client_golang v0.9.1
go: downloading github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39
go: downloading github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910
go: downloading github.com/golang/protobuf v1.2.0
go: downloading github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973
go: downloading github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
Removing intermediate container f6b8b33eaedb
---> 609cfb4b4638
Step 3/3 : RUN ls -la $GOPATH/bin
---> Running in 82ed751fa209
total 9332
drwxrwxrwx 1 root root    4096 Aug 11 13:56 .
drwxrwxrwx 1 root root    4096 Aug 11 13:56 ..
-rwxr-xr-x 1 root root 9545202 Aug 11 13:56 openvpn_exporter
Removing intermediate container 82ed751fa209
---> a86de0dbc366
Successfully built a86de0dbc366
Successfully tagged butuzov/none:latest
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

最新更新