我的应用程序在 kubernetes pod 中运行。
我已经通过官方文档中显示的 helm 命令在 kubernetes daemonset 中安装了 newrelic dotnet 代理。
现在我希望这个 .net 代理能够识别 pod 内运行的 dotnet 应用程序并转发其日志以及 APM 数据,例如平均响应时间、错误百分比等。
当前,当应用程序启动时,即 pod 启动并运行时,它会在 newrelic 帐户的 kubernetes 部分中发送日志。我可以在其中查看日志并按 pod 名称或容器名称过滤它们。但我在 APM 选项卡中看不到 APM 数据或应用程序。如何/配置什么来查看应用程序的 APM 数据。
在 kubernetes 守护进程集中安装了新的 relic dotnet 代理。
我在应用程序中添加了两个nuget包:
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.NewRelic" Version="2.0.0" />
在launchSettings.json中我添加了以下环境变量:
"ASPNETCORE_ENVIRONMENT": "Development",
"CORECLR_ENABLE_PROFILING": "1"
我在appsettings.json中配置了serilog,如下所示:
"Serilog": {
"Properties": {
"app": "test_api",
"Application": "test_api"
},
"WriteTo": {
"NewRelicLogsSink": {
"Name": "NewRelic",
"Args": {
"applicationName": "test_api"
}
}
}
},
在program.cs中创建并使用登录: 创作:
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration, "Serilog")
.Enrich.FromLogContext()
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);
用途:
Log.Information("This is get endpoint from test api");
pod.yaml 文件
apiVersion: v1
kind: Pod
metadata:
name: test-api-serilog-pod
labels:
app: test-api-serilog
spec:
containers:
- name: test-api-serilog-container
image: test-api-serilog:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Development"
- name: CORECLR_ENABLE_PROFILING
value: "1"
- name: NEW_RELIC_APP_NAME
value: "A new test api serilog 2"
- name: NEW_RELIC_LOG
value: "stdout"
- name: NEW_RELIC_APPLICATION_LOGGING_ENABLED
value: "true"
- name: NEW_RELIC_APPLICATION_LOGGING_FORWARDING_ENABLED
value: "true"
- name: NEW_RELIC_LICENSE_KEY
valueFrom:
secretKeyRef:
name: newrelic-bundle-newrelic-logging-config
key: license
我能够在 newrelic 云上获取日志,我可以通过
pod_name
或 container_name
进行过滤。
期待: 现在我想要 newrelic 云中的 APM 数据,例如平均响应时间或错误百分比、错误类型等。 在 APM 标记中看不到 A new test api serilog 2(NEW_RELIC_APP_NAME 的值)。 另外,在 newrelic 云中 Kubernetes->pods->test-api-serilog-pod 我可以看到 pod 的日志,但看不到 APM 数据。
疑问: 是否需要在应用程序运行容器内安装dotnet代理,或者我们可以配置在daemonset中运行的dotnet代理来将APM数据也发送到newrelic吗?
APM 代理需要在容器中运行才能获取您正在查找的信息类型。可通过三种方法实现此目的:添加另一个 NuGet 包和相关配置,将其构建到容器映像中(按照安装向导此处操作),或尝试新的 Kubernetes Agent Operator 自动注入它。 (请注意,截至 2024 年 7 月,最后一个仍处于预览状态。)