gpt4 book ai didi

azure - 如何从 Automation 帐户登录到 Azure 中的 Application Insights?

转载 作者:行者123 更新时间:2023-12-02 23:17:51 24 4
gpt4 key购买 nike

我正在使用 Azure 自动化帐户将我的生产数据库复制到暂存。我还使用这个复制的数据库执行了很多自定义操作,并且使用 Azure 存储帐户执行了一些迁移操作。 总而言之,我的“主”Runbook 调用另一个 Runbook,并且所有工作流程都非常大,因此我想记录每个步骤。

有什么方法可以使用 Application Insights 来实现此目的吗?如果您知道任何其他可能的解决方案,请告诉我!我正在寻找最简单、最智能的解决方案。

我找到了这个模块https://learn.microsoft.com/en-us/powershell/module/azurerm.applicationinsights/?view=azurermps-6.13.0但似乎没有 cmdlet 可以实际“记录”某些内容。

我希望能够做这样的事情:

New-AzureRmApplicationInsightsLog -Name "myAppInsights" -LogText "Step 1. Start copying db"

最佳答案

假设您可以获得Microsoft.ApplicationInsights.dll。如果您不知道如何获取,请告诉我。

然后按照以下步骤操作:

  1. Microsoft.ApplicationInsights.dll放入zip文件中(您可以右键单击.dll文件→发送到→压缩(zipped)文件夹) ,然后您将获得一个名为 Microsoft.ApplicationInsights.zip

    的 zip 文件
  2. 导航到 Azure 门户 → 您的自动化帐户 → 模块 → 添加模块:上传第 1 步中的 zip 文件。

    注意:这可能需要几分钟,当您看到 Microsoft.ApplicationInsights 的状态可用时,就ok了。

  3. 导入模块后,Microsoft.ApplicationInsights.dll 位于 azure 中的以下位置:"C:\Modules\User\Microsoft.ApplicationInsights\Microsoft。 ApplicationInsights.dll”

  4. 在 Runbook 中编写代码以将遥测数据发送到应用程序洞察:

     Add-Type -Path "C:\Modules\User\Microsoft.ApplicationInsights\Microsoft.ApplicationInsights.dll"

    $InstrumentationKey = "xxxx"
    $TelClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
    $TelClient.InstrumentationKey = $InstrumentationKey

    $TelClient.TrackEvent("PowerShell rocks!")
    $TelClient.Flush()

    write-output "ok it is finished."
  5. 检查您是否可以在应用程序洞察中看到数据:

关于azure - 如何从 Automation 帐户登录到 Azure 中的 Application Insights?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57588792/

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