诊断监视和收集实用工具 (dotnet-monitor)

本文适用于:✔️ dotnet-monitor 版本 6.0.0 及更高版本

安装

有两种方法可以下载 dotnet-monitor

  • dotnet 全局工具:

    若要安装最新版 dotnet-monitordotnet-monitor,请使用 dotnet tool install 命令:

    dotnet tool install --global dotnet-monitor
    
  • Docker 映像:

    下载 Docker 映像,以便在多容器环境中使用:

    docker pull mcr.microsoft.com/dotnet/monitor
    

摘要

dotnet-monitor [-h|--help] [--version] <command>

说明

dotnet-monitor 全局工具是用于监视生产环境中的 .NET 应用程序以及按需收集诊断项目(例如转储、跟踪、日志和指标)或使用自动规则在指定条件下收集的方法。

选项

  • --version

    显示 dotnet-monitor 实用工具的版本。

  • -h|--help

    显示命令行帮助。

命令

Command
dotnet monitor collect
dotnet monitor config show
dotnet monitor generatekey

dotnet-monitor collect

监视 .NET 应用程序,允许收集诊断项目,并将结果发送到所选目标。

摘要

dotnet-monitor collect [-h|--help] [-u|--urls] [-m|--metrics] [--metricUrls] [--diagnostic-port] [--no-auth] [--temp-apikey] [--no-http-egress]

选项

  • -h|--help

    显示命令行帮助。

  • -u|--urls <urls>

    HTTP API 的绑定。 默认值为 https://localhost:52323

  • -m|--metrics [true|false]

    启用向 /metrics 路由发布指标。 默认为 true

  • --metricUrls <urls>

    指标 HTTP API 的绑定。 默认值为 http://localhost:52325

  • --diagnostic-port <path>

    运行时实例可以连接到的诊断端口的完全限定路径和文件名。 指定此选项会将 dotnet-monitor 置于“侦听”模式。 如果未指定,则 dotnet-monitor 处于“连接”模式。

    在 Windows 上,这必须是有效的命名管道名称。 在 Linux 和 macOS 上,这必须是有效的 Unix 域套接字路径。

  • --no-auth

    禁用 API 密钥身份验证。 默认值为 false

    强烈建议不要在生产环境中使用此选项。

  • --temp-apikey

    dotnet-monitor 实例生成临时 API 密钥。

  • --no-http-egress

    通过 HTTP 响应禁用诊断项目的出口。 指定后,必须使用出口提供程序输出项目。

dotnet-monitor config show

显示配置,就好像 dotnet-monitor collect 是使用这些参数执行的。

摘要

dotnet-monitor config show [-h|--help] [-u|--urls] [-m|--metrics] [--metricUrls] [--diagnostic-port] [--no-auth] [--temp-apikey] [--no-http-egress] [--level] [--show-sources]

选项

  • -h|--help

    显示命令行帮助。

  • -u|--urls <urls>

    HTTP API 的绑定。 默认值为 https://localhost:52323

    此值作为 urls 键映射到配置中。

  • -m|--metrics [true|false]

    启用向 /metrics 路由发布指标。 默认值为 true

    此值作为 Metrics:Enabled 键映射到配置中。

  • --metricUrls <urls>

    指标 HTTP API 的绑定。 默认值为 http://localhost:52325

    此值作为 Metrics:Endpoints 键映射到配置中。

  • --diagnostic-port <path>

    运行时实例可以连接到的诊断端口的完全限定路径和文件名。 指定此选项会将 dotnet-monitor 置于“侦听”模式。 如果未指定,则 dotnet-monitor 处于“连接”模式。

    在 Windows 上,这必须是有效的命名管道名称。 在 Linux 和 macOS 上,这必须是有效的 Unix 域套接字路径。

    此值作为 DiagnosticPort:EndpointName 键映射到配置中。

  • --no-auth

    禁用 API 密钥身份验证。 默认值为 false

    强烈建议不要在生产环境中使用此选项。

    此值未映射到配置中。

  • --temp-apikey

    dotnet-monitor 实例生成临时 API 密钥。

    此值作为 Authentication:MonitorApiKey 键映射到配置中。

  • --no-http-egress

    通过 HTTP 响应禁用诊断项目的出口。 指定后,必须使用出口提供程序输出项目。

    此值未映射到配置中。

  • --level

    配置级别。 Full 配置可以显示敏感信息。 有两个级别:

    • Full - 完整配置,无需编修任何值。
    • Redacted - 完整配置,但敏感信息(如已知机密)已编修。
  • --show-sources

    标识提供每个有效配置值的配置源。

dotnet-monitor generatekey

生成用于 HTTP 身份验证的 API 密钥和哈希。

摘要

dotnet-monitor generatekey [-h|--help] [-o|--output]

选项

  • -h|--help

    显示命令行帮助。

  • -o|--output <Cmd|Json|MachineJson|PowerShell|Shell|Text>

    将 API 密钥信息写入标准输出的输出格式。

    允许的值为:

    • Cmd - 采用在 Windows 命令提示符或批处理文件中可用的格式的输出。
    • Json - 采用 JSON 对象格式的输出。
    • MachineJson - 采用 JSON 对象的格式输出,不带注释和说明。 适用于自动化方案。
    • PowerShell - 采用在 PowerShell 提示和脚本中可用的格式的输出。
    • Shell - 采用在 Linux shell(如 Bash)中可用的格式的输出。
    • Text - 采用纯文本格式的输出。

另请参阅