使用 dotnet 跟踪和计数器部署在 kubernetes 性能诊断上的 C# dotnet 应用程序

Amo*_*ari 5 trace profiling docker kubernetes .net-core

我正在尝试使用 dotnet-trace 和 dotnet 计数器为部署在 kubernetes(GKE) 集群上的应用程序启用性能诊断。为此,我在应用程序容器中添加了性能诊断 sidecar。诊断.Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS tools
RUN dotnet tool install --tool-path /tools dotnet-trace
RUN dotnet tool install --tool-path /tools dotnet-counters
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime
COPY --from=tools /tools /tools
ENV PATH="/tools:${PATH}"
ENV COMPlus_EnableDiagnostics="0"
WORKDIR /tools 
Run Code Online (Sandbox Code Playgroud)

我在这里使用的应用程序是一个简单的 hello world 应用程序。这就是我在 GKE 上部署这些容器的方式:deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-dotnet-diagnostics
spec:
  replicas: 1
  selector:
    matchLabels:
      app: demo-diagnostics
  template:
    metadata:
      labels:
        app: demo-diagnostics
    spec:
      shareProcessNamespace: true
      containers:
      - name: demo-app
        image: gcr.io/qp-fda-mystudies-2020-07/dotnetapp:latest
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: dotnet-diagnostics
          mountPath: /tmp
      - name: demo-diagnostics
        image: gcr.io/qp-fda-mystudies-2020-07/diagnostics:latest
        stdin: true
        tty: true
        command: ["/bin/sh","-c"]
        args: ["dotnet-trace collect -p 1; dotnet-counters monitor -p 1"]
        volumeMounts:
        - name: dotnet-diagnostics
          mountPath: /tmp
      volumes:
      - name: dotnet-diagnostics
        emptyDir: {}
Run Code Online (Sandbox Code Playgroud)

我在这里面临的问题是诊断容器不断陷入 crashloopbackoff。我在这里遇到的错误是:无法启动计数器会话:Microsoft.Diagnostics.NETCore.Client.ServerNotAvailableException:进程 1 未运行兼容的 .NET 运行时。我一直在关注这些文章和线程: https://github.com/dotnet/diagnostics/issues/810https://im5tu.io/article/2020/01/diagnostics-in-.net-core-3- using-dotnet-counters-with-docker/ 目标是在后台运行这些诊断进程,并将使用这些工具捕获的信息推送到 stackdriver。我不知道我在这里缺少什么,因为我对 dotnet 还比较陌生。请帮忙。

jBe*_*ger 0

注意已测试,但我会尝试删除此行(或将其设置为 1):

ENV COMPlus_EnableDiagnostics="0"
Run Code Online (Sandbox Code Playgroud)

来源:MS