Azure的运行手册应用负载的洞察力.NET程序集 [英] Azure Runbook load .Net assembly for application insight
问题描述
我的要求,我想写一些指标申请有识之士每隔一段时间监控服务。
不过,我觉得我会写这个PowerShell脚本,并相应地安排它。
写输出脚本启动
$ PSScriptRoot = GET-位置
$ AI =$ PSScriptRoot \\ Microsoft.ApplicationInsights.dll
[Reflection.Assembly] ::的LoadFile($ AI)
$ InstrumentationKey =
$ TelClient =新对象Microsoft.ApplicationInsights.TelemetryClient
$ TelClient.InstrumentationKey = $ InstrumentationKey$ TrackMetric =新对象Microsoft.ApplicationInsights.DataContracts.MetricTelemetry
$ TrackMetric.Name =PowershellTest
$ TrackMetric.Value =获取随机最小值:1最大值:100$ TelClient.TrackMetric($ TrackMetric)
$ TelClient.Flush()写输出脚本结束$ TrackMetric.Value
这PowerShell脚本工作,但我感动的剧本后,运行手册就不再工作。
所以,这里是问题。
我不能够加载运行手册里面的ApplicationInsight DLL。
不知道如何做到这一点?
异常详细信息
异常调用的LoadFile和1的说法(S):系统找不到指定的文件(从HRESULT异常:
0x80070002)
谢谢
西拉杰
的问题是在加载的DLL文件。该运行手册是不是能找到该行的文件:
$ AI =$ PSScriptRoot \\ Microsoft.ApplicationInsights.dll
[Reflection.Assembly] ::的LoadFile($ AI)
当您通过Azure的自动化运行运行手册,你没有访问本地路径,你在本地机器上或者在premise通常做。在Azure的自动化,模块被放置在 C:\\模块
相反,低于code段使用,您上传的DLL文件后:
<$p$p><$c$c>[System.Reflection.Assembly]::LoadFrom(\"C:\\Modules\\Azure\\Microsoft.ApplicationInsights.dll\")最近的相关参考:<一href=\"https://social.msdn.microsoft.com/Forums/vstudio/en-US/45251bdb-bb20-488c-a428-3ee1094fd568/referencing-microsoftwindowsazurestoragedll-and-creating-cloud-blob-client-using?forum=azureautomation\"相对=nofollow>引用的DLL
I have requirement where I want to write some metrics to the application insight for monitoring a service at a regular interval.
I though that I would write this PowerShell script and schedule it accordingly.
Write-Output "Script Start"
$PSScriptRoot = Get-Location
$AI = "$PSScriptRoot\Microsoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile("$AI")
$InstrumentationKey = ""
$TelClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"
$TelClient.InstrumentationKey = $InstrumentationKey
$TrackMetric = New-Object "Microsoft.ApplicationInsights.DataContracts.MetricTelemetry"
$TrackMetric.Name = "PowershellTest"
$TrackMetric.Value = Get-Random -Minimum:1 -Maximum:100
$TelClient.TrackMetric($TrackMetric)
$TelClient.Flush()
Write-Output "Script End $TrackMetric.Value"
This PowerShell Script works, but after I moving that script to Runbook it is no longer working.
So, here is the issue. I am not able to load the ApplicationInsight DLL inside the Runbook.
Any idea how to do that?
Exception Details
Exception calling "LoadFile" with "1" argument(s): "The system cannot find the file specified. (Exception from HRESULT:
0x80070002)"
Thanks Siraj
The issue is in loading the DLL file. The Runbook is not able to find the file in this line:
$AI = "$PSScriptRoot\Microsoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile("$AI")
When you run a Runbook via Azure Automation, you don't have access to the local path as you normally do on a local machine or on premise. In Azure Automation, modules are placed in "C:\Modules".
Instead, use below code snippet, after you have uploaded the dll file:
[System.Reflection.Assembly]::LoadFrom("C:\Modules\Azure\Microsoft.ApplicationInsights.dll")
Closest Related Reference: Referencing DLL
这篇关于Azure的运行手册应用负载的洞察力.NET程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!