gpt4 book ai didi

go - APM Go 代理未向 APM 服务器发送数据

转载 作者:行者123 更新时间:2023-12-01 22:21:13 28 4
gpt4 key购买 nike

我有一个 Elastic APM-Server 启动并运行,它已成功建立与 Elasticsearch 的连接。
然后我安装了一个 Elastic APM Go 代理:

go get -u go.elastic.co/apm
它返回以下内容:
finding go.elastic.co/apm v1.8.0
finding github.com/stretchr/testify v1.4.0
finding github.com/prometheus/procfs v0.0.3
finding github.com/google/go-cmp v0.3.1
finding github.com/armon/go-radix v1.0.0
finding github.com/santhosh-tekuri/jsonschema v1.2.4
finding github.com/cucumber/godog v0.8.1
finding golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e
finding go.elastic.co/fastjson v1.0.0
finding github.com/google/go-cmp v0.5.1
finding github.com/prometheus/procfs v0.1.3
finding golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
finding golang.org/x/sys latest
finding github.com/elastic/go-sysinfo v1.1.1
finding golang.org/x/sync latest
finding golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e
finding github.com/stretchr/testify v1.6.1
finding go.elastic.co/fastjson v1.1.0
finding github.com/cucumber/godog v0.10.0
finding github.com/stretchr/objx v0.3.0
finding github.com/elastic/go-sysinfo v1.4.0
finding gopkg.in/yaml.v2 v2.2.2
finding github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
finding golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
finding github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0
finding github.com/elastic/go-windows v1.0.0
finding golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae
finding golang.org/x/xerrors latest
finding gopkg.in/yaml.v2 v2.3.0
finding golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5
finding github.com/yuin/goldmark v1.1.27
finding github.com/cucumber/messages-go/v10 v10.0.3
finding gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
finding howett.net/plist v0.0.0-20181124034731-591f970eefbb
finding golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
finding gopkg.in/check.v1 latest
finding golang.org/x/mod v0.2.0
finding golang.org/x/tools latest
finding github.com/hashicorp/go-memdb v1.2.1
finding golang.org/x/net latest
finding github.com/cucumber/gherkin-go/v11 v11.0.0
finding github.com/joeshaw/multierror latest
finding golang.org/x/crypto latest
finding github.com/yuin/goldmark v1.1.32
finding github.com/elastic/go-windows v1.0.1
finding golang.org/x/mod v0.3.0
finding golang.org/x/text v0.3.3
finding howett.net/plist latest
finding golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
finding golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
finding golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
finding golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898
finding golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
finding golang.org/x/net v0.0.0-20200625001655-4c5254603344
finding github.com/kr/pretty v0.2.1
finding github.com/jessevdk/go-flags v1.4.0
finding github.com/kr/text v0.2.0
finding github.com/kr/pty v1.1.8
finding github.com/hashicorp/go-immutable-radix v1.2.0
finding github.com/hashicorp/golang-lru v0.5.4
finding github.com/yuin/goldmark v1.2.1
finding github.com/aslakhellesoy/gox v1.0.100
finding gopkg.in/yaml.v3 latest
finding gopkg.in/yaml.v2 v2.2.8
finding golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a
finding github.com/gogo/protobuf v1.3.1
finding github.com/gofrs/uuid v3.2.0+incompatible
finding github.com/stretchr/testify v1.5.1
finding github.com/creack/pty v1.1.7
finding github.com/creack/pty v1.1.9
finding github.com/cucumber/messages-go/v10 v10.0.1
finding github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e
finding github.com/hashicorp/go-uuid v1.0.0
finding github.com/hashicorp/go-version v1.0.0
finding github.com/mitchellh/iochan v1.0.0
finding gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
finding github.com/kr/pretty v0.2.0
finding github.com/niemeyer/pretty latest
finding github.com/hashicorp/go-uuid v1.0.2
finding github.com/hashicorp/go-version v1.2.1
finding github.com/creack/pty v1.1.11
finding github.com/kisielk/errcheck v1.2.0
finding github.com/gofrs/uuid v3.3.0+incompatible
finding github.com/kisielk/errcheck v1.4.0
finding golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563
finding golang.org/x/tools v0.0.0-20200619180055-7c47624df98f
downloading go.elastic.co/apm v1.8.0
extracting go.elastic.co/apm v1.8.0
downloading github.com/elastic/go-sysinfo v1.4.0
downloading golang.org/x/sys v0.0.0-20200819035508-9a32b3aa38f5
downloading go.elastic.co/fastjson v1.1.0
downloading github.com/armon/go-radix v1.0.0
extracting go.elastic.co/fastjson v1.1.0
extracting github.com/armon/go-radix v1.0.0
extracting github.com/elastic/go-sysinfo v1.4.0
downloading howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5
downloading github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
downloading github.com/prometheus/procfs v0.1.3
extracting github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901
extracting howett.net/plist v0.0.0-20200419221736-3b63eb3a43b5
extracting github.com/prometheus/procfs v0.1.3
extracting golang.org/x/sys v0.0.0-20200819035508-9a32b3aa38f5
然后我设置 ELASTIC_APM_SERVER_URLELASTIC_APM_SERVICE_NAME :
export ELASTIC_APM_SERVER_URL=http://my-apm-server-url
export ELASTIC_APM_SERVICE_NAME=agent-name
但是,我没有看到代理在 APM 仪表板中注册。
它不会向 APM 服务器发送任何数据。
如何确保代理正在运行?如何检查代理日志以了解为什么它无法连接到 APM 服务器?

最佳答案

既然您没有在上面提到它:您是否检测了 Go 应用程序? Elastic APM Go“代理”是一个用于检测应用程序源代码的包。它不是一个独立的进程,而是在您的应用程序中运行。
因此,首先(如果您还没有)检测您的应用程序。见 https://www.elastic.co/guide/en/apm/agent/go/current/getting-started.html#instrumenting-source
这是一个使用 Echo 的示例 Web 服务器,以及 apmechov4仪表模块:

package main

import (
"fmt"
"net/http"

echo "github.com/labstack/echo/v4"

"go.elastic.co/apm/module/apmechov4"
)

func main() {
e := echo.New()
e.Use(apmechov4.Middleware())
e.GET("/hello/:name", func(c echo.Context) error {
fmt.Println(c.Param("name"))
return nil
})
http.ListenAndServe(":8080", e)
}
如果你运行它并向 http://localhost:8080/hello/world 发送一些请求,您应该很快就会在 Kibana 的 APM 应用中看到请求。
enter image description here
如果在 Kibana 中仍然没有看到任何内容,可以关注 https://www.elastic.co/guide/en/apm/agent/go/current/troubleshooting.html#agent-logging启用日志记录。如果代理能够成功地将数据发送到服务器,您可以看到以下内容:
$ ELASTIC_APM_LOG_FILE=stderr ELASTIC_APM_LOG_LEVEL=debug go run main.go
{"level":"debug","time":"2020-08-19T13:33:28+08:00","message":"sent request with 3 transactions, 0 spans, 0 errors, 0 metricsets"}
{"level":"debug","time":"2020-08-19T13:33:46+08:00","message":"gathering metrics"}
{"level":"debug","time":"2020-08-19T13:33:56+08:00","message":"sent request with 0 transactions, 0 spans, 0 errors, 3 metricsets"}
另一方面,如果服务器无法访问,您会看到如下内容:
{"level":"error","time":"2020-08-19T13:38:01+08:00","message":"config request failed: sending config request failed: Get \"http://localhost:8200/config/v1/agents?service.name=main\": dial tcp 127.0.0.1:8200: connect: connection refused"}

关于go - APM Go 代理未向 APM 服务器发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63480314/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com