环境准备
https://golang.org/dl/ 上下载以下包 go1.18.windows-amd64.msi 如果下载不了可能是因为 特殊原因(TZ), 自行使用代理解决 最好花钱购买插件,不然稳定性无法保证,
github上下载 node_exporter-1.3.0和prometheus-2.35.0 (依赖包编译会下载源码 至少准备个5G环境)
另外官方说需要下载 node-v16.15.0-x64.msi 和 npm 猜测是做页面管理编译好像有个web目录.但是对主体应该没影响
首先检查代理环境, 这里必须做修改
go env -w GOSUMDB=off
go env -w GOPROXY=https://goproxy.cn,direct
正常环境如下: go env
PS D:\opensource\prometheus-2.35.0> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\chijing\AppData\Local\go-build
set GOENV=C:\Users\chijing\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\chijing\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\chijing\go set GOPRIVATE=
set GOPROXY=https://goproxy.cn,direct
set GOROOT=D:\Go
set GOSUMDB=off
set GOTMPDIR=
set GOTOOLDIR=D:\Go\pkg\tool\windows_amd64
set GOVCS= set GOVERSION=go1.18 set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\opensource\prometheus-2.35.0\go.mod
set GOWORK=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\chijing\AppData\Local\Temp\go-build1856528722=/tmp/go-build -gno-record-gcc-switches
编译 node_exporter:
cd D:\opensource\node_exporter-1.3.0
go build #会生成 node_exporter.exe 就代表成功
运行exe 输出以下内容则成功:
ts=2022-05-10T03:28:03.587Z caller=node_exporter.go:182 level=info msg="Starting node_exporter" version="(version=, branch=, revision=)"
ts=2022-05-10T03:28:03.588Z caller=node_exporter.go:183 level=info msg="Build context" build_context="(go=go1.18, user=, date=)"
ts=2022-05-10T03:28:14.884Z caller=node_exporter.go:108 level=info msg="Enabled collectors" ts=2022-05-10T03:28:14.885Z caller=node_exporter.go:115 level=info collector=os
ts=2022-05-10T03:28:14.886Z caller=node_exporter.go:115 level=info collector=textfile
ts=2022-05-10T03:28:14.887Z caller=node_exporter.go:115 level=info collector=time ts=2022-05-10T03:28:14.888Z caller=node_exporter.go:199 level=info msg="Listening on" address=:9100 ts=2022-05-10T03:28:14.893Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
另外可在浏览器输入以下地址查看收集得本记机器信息: http://localhost:9100/metrics
mysqld_exporter编译
下载GitHub - prometheus/mysqld_exporter: Exporter for MySQL server metrics 解压后编译会生成mysqld_exporter.exe
PS D:\opensource\prometheus-2.35.0\cmd\prometheus> cd D:\opensource\mysqld_exporter-main
PS D:\opensource\mysqld_exporter-main> go build
go: downloading github.com/go-sql-driver/mysql v1.6.0
go: downloading gopkg.in/ini.v1 v1.66.4
go: downloading golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
go: downloading google.golang.org/protobuf v1.26.0
go: downloading github.com/google/uuid v1.3.0 PS D:\opensource\mysqld_exporter-main>
prometheus 编译
cd D:\opensource\prometheus-2.35.0\cmd\prometheus
go build
cd D:\opensource\prometheus-2.35.0\cmd\promtool
go build
cd D:\opensource\prometheus-2.35.0\web 这里编译没效果 需要nodejs npm 编译一些东西, 如果不编译不影响监控, 只影响后台监控信息展示(如果在Linux系统这里有个makefile脚本,可以调用nodejs +npm将网页打包成app, 但是这个比整个监控系统还大,我没编译)
go build
这里输出除了一大堆下载信息就不会有其他信息, 否则就是编译失败. 如下: PS D:\opensource\prometheus-2.35.0> cd .\web\
PS D:\opensource\prometheus-2.35.0\web> go build
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137
go: downloading github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2
go: downloading github.com/prometheus/client_golang v1.12.1
go: downloading github.com/prometheus/common v0.34.0 go: downloading github.com/prometheus/exporter-toolkit v0.7.1 go: downloading go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.31.0 go: downloading go.uber.org/atomic v1.9.0 go: downloading golang.org/x/net v0.0.0-20220325170049-de3da57026de go: downloading github.com/golang/protobuf v1.5.2 go: downloading go.opentelemetry.io/contrib v0.20.0 go: downloading github.com/julienschmidt/httprouter v1.3.0 go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 go: downloading golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 go: downloading github.com/go-openapi/strfmt v0.21.2 go: downloading github.com/prometheus/alertmanager v0.24.0 go: downloading github.com/prometheus/common/sigv4 v0.1.0 go: downloading github.com/cespare/xxhash/v2 v2.1.2 go: downloading go.opentelemetry.io/otel v1.6.1 go: downloading github.com/cespare/xxhash v1.1.0 go: downloading golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886 go: downloading google.golang.org/protobuf v1.28.0 go: downloading github.com/edsrzf/mmap-go v1.1.0 go: downloading github.com/stretchr/testify v1.7.1 go: downloading go.opentelemetry.io/otel/trace v1.6.1 go: downloading github.com/json-iterator/go v1.1.12 go: downloading github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 go: downloading github.com/oklog/ulid v1.3.1 go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c go: downloading golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a go: downloading github.com/felixge/httpsnoop v1.0.2 go: downloading go.opentelemetry.io/otel/metric v0.28.0 go: downloading github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d go: downloading github.com/go-openapi/errors v0.20.2 go: downloading github.com/mitchellh/mapstructure v1.4.3 go: downloading go.mongodb.org/mongo-driver v1.8.3 go: downloading github.com/aws/aws-sdk-go v1.43.31 go: downloading gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b go: downloading github.com/go-logr/logr v1.2.3 go: downloading go.uber.org/goleak v1.1.12 go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd go: downloading github.com/modern-go/reflect2 v1.0.2 go: downloading github.com/golang/snappy v0.0.4 go: downloading github.com/dennwc/varint v1.0.0 go: downloading github.com/go-openapi/swag v0.21.1 go: downloading github.com/go-openapi/validate v0.21.0 go: downloading github.com/go-logr/stdr v1.2.2 go: downloading github.com/davecgh/go-spew v1.1.1 go: downloading github.com/pmezard/go-difflib v1.0.0 go: downloading golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 go: downloading golang.org/x/text v0.3.7 go: downloading github.com/go-stack/stack v1.8.1 go: downloading github.com/mailru/easyjson v0.7.7 go: downloading github.com/go-openapi/analysis v0.21.2 go: downloading github.com/go-openapi/jsonpointer v0.19.5 go: downloading github.com/go-openapi/loads v0.21.1 go: downloading github.com/go-openapi/spec v0.20.4 go: downloading github.com/josharian/intern v1.0.0 go: downloading github.com/go-openapi/jsonreference v0.19.6 go: downloading github.com/PuerkitoBio/purell v1.1.1 go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 go: downloading github.com/jmespath/go-jmespath v0.4.0 PS D:\opensource\prometheus-2.35.0\web> cd D:\opensource\prometheus-2.35.0\cmd\prometheus PS D:\opensource\prometheus-2.35.0\cmd\prometheus> go build go: downloading github.com/oklog/run v1.1.0 go: downloading go.uber.org/automaxprocs v1.5.1 go: downloading github.com/simonpasquier/klog-gokit v0.3.0 go: downloading github.com/simonpasquier/klog-gokit/v3 v3.0.0 go: downloading go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.6.1 go: downloading go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.6.1 go: downloading go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.6.1 go: downloading go.opentelemetry.io/otel/sdk v1.6.1 go: downloading google.golang.org/grpc v1.45.0 go: downloading go.opentelemetry.io/otel/exporters/otlp v0.20.0 go: downloading github.com/go-kit/kit v0.10.0 go: downloading github.com/Azure/azure-sdk-for-go v63.0.0+incompatible go: downloading github.com/Azure/go-autorest/autorest v0.11.25 go: downloading github.com/Azure/go-autorest/autorest/adal v0.9.18 go: downloading github.com/Azure/go-autorest v14.2.0+incompatible go: downloading github.com/hashicorp/consul/api v1.12.0 go: downloading github.com/digitalocean/godo v1.78.0 go: downloading github.com/miekg/dns v1.1.48 go: downloading github.com/fsnotify/fsnotify v1.5.1 go: downloading google.golang.org/api v0.74.0 go: downloading github.com/hetznercloud/hcloud-go v1.33.1 go: downloading github.com/linode/linodego v1.4.0 go: downloading k8s.io/api v0.23.5 go: downloading k8s.io/apimachinery v0.23.5 go: downloading k8s.io/client-go v0.23.5 go: downloading github.com/docker/docker v20.10.14+incompatible go: downloading github.com/gophercloud/gophercloud v0.24.0 go: downloading github.com/scaleway/scaleway-sdk-go v1.0.0-beta.9 go: downloading github.com/kolo/xmlrpc v0.0.0-20201022064351-38db28db192b go: downloading github.com/go-zookeeper/zk v1.0.2 go: downloading github.com/envoyproxy/go-control-plane v0.10.1 go: downloading github.com/envoyproxy/protoc-gen-validate v0.6.7 go: downloading google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb go: downloading go.opentelemetry.io/proto/otlp v0.12.1 go: downloading go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.6.1 go: downloading github.com/Azure/go-autorest/logger v0.2.1 go: downloading github.com/Azure/go-autorest/tracing v0.6.0 go: downloading github.com/Azure/go-autorest/autorest/date v0.3.0 go: downloading github.com/golang-jwt/jwt/v4 v4.2.0 go: downloading github.com/hashicorp/go-cleanhttp v0.5.1 go: downloading github.com/hashicorp/go-hclog v0.12.2 go: downloading github.com/hashicorp/go-rootcerts v1.0.2 go: downloading github.com/hashicorp/serf v0.9.6 go: downloading cloud.google.com/go/compute v1.5.0 go: downloading github.com/google/go-querystring v1.0.0 go: downloading github.com/go-resty/resty/v2 v2.1.1-0.20191201195748-d7b97669fe48 go: downloading cloud.google.com/go v0.100.2 go: downloading github.com/google/go-cmp v0.5.7 go: downloading github.com/google/gofuzz v1.2.0 go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.1 go: downloading github.com/imdario/mergo v0.3.12 go: downloading github.com/spf13/pflag v1.0.5 go: downloading golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 go: downloading k8s.io/utils v0.0.0-20211116205334-6203023598ed go: downloading github.com/docker/go-units v0.4.0 go: downloading github.com/docker/go-connections v0.4.0 go: downloading github.com/opencontainers/image-spec v1.0.2 go: downloading github.com/containerd/containerd v1.6.1 go: downloading github.com/docker/distribution v2.7.1+incompatible go: downloading github.com/opencontainers/go-digest v1.0.0 go: downloading github.com/cenkalti/backoff/v4 v4.1.2 go: downloading github.com/cenkalti/backoff v2.2.1+incompatible go: downloading github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 go: downloading github.com/grpc-ecosystem/grpc-gateway v1.16.0 go: downloading github.com/fatih/color v1.13.0 go: downloading github.com/mattn/go-colorable v0.1.12 go: downloading github.com/mattn/go-isatty v0.0.14 go: downloading github.com/armon/go-metrics v0.3.3 go: downloading gopkg.in/inf.v0 v0.9.1 go: downloading sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 go: downloading github.com/googleapis/gax-go/v2 v2.2.0 go: downloading go.opencensus.io v0.23.0 go: downloading sigs.k8s.io/yaml v1.2.0 go: downloading github.com/googleapis/gnostic v0.5.5 go: downloading github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1 go: downloading github.com/sirupsen/logrus v1.8.1 go: downloading github.com/Microsoft/go-winio v0.5.1 go: downloading github.com/hashicorp/go-immutable-radix v1.2.0 go: downloading github.com/hashicorp/golang-lru v0.5.4 go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da go: downloading k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 go: downloading github.com/Azure/go-autorest/autorest/validation v0.3.1 go: downloading github.com/Azure/go-autorest/autorest/to v0.4.0 PS D:\opensource\prometheus-2.35.0\cmd\prometheus> cd D:\opensource\prometheus-2.35.0\cmd\promtool PS D:\opensource\prometheus-2.35.0\cmd\promtool> go build go: downloading github.com/google/pprof v0.0.0-20220318212150-b2ab0324ddda
prometheus启动需要配置文件 prometheus.yml
global: scrape_interval: 15s evaluation_interval: 15s rule_files: # - "first.rules" # - "second.rules" scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['192.168.31.29:9090']
最后启动 ./prometheus --config.file=prometheus.yml
PS D:\opensource\prometheus-2.35.0\cmd\prometheus> ./prometheus --config.file=prometheus.yml
启动输出以下信息
浏览器中输入 http://192.168.31.29:9090/metrics 可返回信息则可成功
交叉编译
http://192.168.31.29:9090/metrics 可返回信息则可成功
prometheus 的webUI后台展示页面编译 需要nodejs npm 这个不会,暂没研究, 事实标准方案是使用grafana, prometheus后台管理太丑
#### 交叉编译
如果想编译出其他平台的改go env 即可. 下面是编译Linux 系统 amd64架构的命令, (国产化使用怕是够呛,
系统分类支持 darwin,freebsd,linux,windows
cpu架构支持以下 386,amd64,arm, 如果不行就得编译go编译器了.
PS D:\opensource\mysqld_exporter-main> go env -w GOOS=linux
PS D:\opensource\mysqld_exporter-main> go build
go: downloading github.com/prometheus/procfs v0.7.3
PS D:\opensource\mysqld_exporter-main> cd ..\node_exporter-1.3.0\
PS D:\opensource\node_exporter-1.3.0> go build
go: downloading github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
go: downloading github.com/ema/qdisc v0.0.0-20200603082823-62d0308e3e00
go: downloading github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968
go: downloading github.com/hodgesds/perf-utils v0.4.0
go: downloading github.com/jsimonetti/rtnetlink v0.0.0-20211022192332-93da33804786
go: downloading github.com/mdlayher/wifi v0.0.0-20200527114002-84f0b9457fdd
go: downloading github.com/safchain/ethtool v0.1.0
go: downloading golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
go: downloading github.com/mdlayher/netlink v1.4.1
go: downloading github.com/mdlayher/genetlink v1.0.0
go: downloading go.uber.org/multierr v1.6.0
go: downloading go.uber.org/atomic v1.7.0
go: downloading github.com/josharian/native v0.0.0-20200817173448-b6b71def0850
go: downloading github.com/mdlayher/socket v0.0.0-20210307095302-262dc9984e00
PS D:\opensource\node_exporter-1.3.0> cd D:\opensource\prometheus-2.35.0
PS D:\opensource\prometheus-2.35.0> go build