猿问

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

我有一个 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


然后我设置ELASTIC_APM_SERVER_URLand ELASTIC_APM_SERVICE_NAME:


export ELASTIC_APM_SERVER_URL=http://my-apm-server-url

export ELASTIC_APM_SERVICE_NAME=agent-name

但是,我没有看到代理在 APM 仪表板中注册。


它不会向 APM 服务器发送任何数据。


如何确保代理正在运行?如何检查代理日志以了解为什么它无法连接到 APM 服务器?


拉丁的传说
浏览 165回答 1
1回答

慕田峪9158850

既然您没有在上面提到它:您是否检测了 Go 应用程序?Elastic APM Go“代理”是一个用于检测应用程序源代码的包。它不是一个独立的进程,而是在您的应用程序中运行。因此,首先(如果您还没有)检测您的应用程序。请参阅https://www.elastic.co/guide/en/apm/agent/go/current/getting-started.html#instrumenting-source这是一个使用Echo和apmechov4检测模块的示例 Web 服务器:package mainimport (        "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 应用程序中看到请求。如果您在 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"}
随时随地看视频慕课网APP

相关分类

Go
我要回答