收集 IntelliTrace 快照写操作
Microsoft.SystemCenter.IntelliTraceProfiling.CollectIntelliTraceSnapshot.WriteAction (WriteActionModuleType)
收集 IIS 应用程序池的 IntelliTrace 分析快照
Element properties: Member Modules:
Overrideable Parameters:
Source Code: <WriteActionModuleType ID="Microsoft.SystemCenter.IntelliTraceProfiling.CollectIntelliTraceSnapshot.WriteAction" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IISApplicationPath" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="AlertID" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:unsignedInt"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IISApplicationPath" Selector="$Config/IISApplicationPath$" ParameterType="string"/>
<OverrideableParameter ID="AlertID" Selector="$Config/AlertID$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PA" TypeID="Microsoft.SystemCenter.IntelliTraceProfiling.GetApplicationPool.ProbeActionType">
<IISApplicationPath>$Config/IISApplicationPath$</IISApplicationPath>
</ProbeAction>
<WriteAction ID="WA2" TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagWriteAction">
<ScriptName>CollectIntelliTraceSnapshot.ps1</ScriptName>
<ScriptBody><Script>
param($intelliTraceInstallPath, $applicationPoolName, $alertID)
$ErrorActionPreference = "Stop"
Import-Module "$($intelliTraceInstallPath)\Microsoft.VisualStudio.IntelliTrace.PowerShell.dll"
$traceStatus = Get-IntelliTraceCollectionStatus | Where-Object {$_.OutputPath -ne $null -and $_.CollectionPlanPath -ne $null -and $_.ApplicationPool -eq $applicationPoolName} | Select-Object -First 1
if($traceStatus -eq $null)
{
throw "The IntelliTrace snapshot cannot be found. Make sure that the application pool is started and the task is running under an account that has sufficient privileges to access collected traces."
exit 1
}
$traceDirectory = [System.IO.Path]::GetDirectoryName($traceStatus.OutputPath)
try
{
$lock = [System.IO.File]::Open( [System.IO.Path]::Combine($traceDirectory, ".lock") , [System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None)
}
catch [System.IO.IOException]
{
throw "The IntelliTrace snapshot cannot be collected. Another collect snapshot operation is already running for this application pool."
exit 1
}
try
{
Checkpoint-IntelliTraceCollection $applicationPoolName -Confirm:$false
$snapshotDirectory = [System.IO.Path]::Combine($traceDirectory ,[System.Guid]::NewGuid().ToString())
[void] (New-Item $snapshotDirectory -type directory)
$traceFiles = @(Get-Item "$($traceDirectory)\*.iTrace")
$collectedTraces = @()
foreach ($file in $traceFiles)
{
try
{
$destination = [System.IO.Path]::Combine($snapshotDirectory, $file.Name)
[System.IO.File]::Move($file.FullName, $destination)
$collectedTraces = $collectedTraces + $destination
}
catch [System.IO.IOException]
{
# ignore files locked by IntelliTrace
}
}
if($collectedTraces.Count -eq 0)
{
throw "The IntelliTrace snapshot cannot be collected. Make sure that the application pool is running and that the task is running under an account that has sufficient rights to access collected traces."
exit 1
}
$machineName = [System.Environment]::MachineName
$oAPI = new-object -comObject "MOM.ScriptAPI"
$bag = $oAPI.CreatePropertyBag()
$bag.AddValue("AlertID", $alertID)
$bag.AddValue("AttachmentName", [System.String]::Format("{0}_{1}_{2}", $applicationPoolName, $machineName, [System.DateTime]::Now.ToString("yyyy-MM-dd HH.mm.ss")))
$bag.AddValue("AlertDescription", "A new IntelliTrace snapshot for application pool $($applicationPoolName) was received from computer $($machineName).")
$bag.AddValue("AttachmentType", "IntelliTrace")
for($i = 0; $i -lt $collectedTraces.Count; $i++)
{
if($i -eq 0)
{
$bag.AddValue("AttachmentPath", $collectedTraces[$i])
}
else
{
$bag.AddValue("AttachmentPath$($i)", $collectedTraces[$i])
}
}
$bag
}
finally
{
$lock.Close()
}
</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>IntelliTraceInstallPath</Name>
<Value>$Data/Property[@Name='IntelliTraceInstallPath']$</Value>
</Parameter>
<Parameter>
<Name>ApplicationPoolName</Name>
<Value>$Data/Property[@Name='ApplicationPoolName']$</Value>
</Parameter>
<Parameter>
<Name>AlertID</Name>
<Value>$Config/AlertID$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</WriteAction>
<WriteAction ID="WA3" TypeID="AA!Microsoft.SystemCenter.AlertAttachment.SendAttachment.WriteAction">
<DeleteLocalFile>true</DeleteLocalFile>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="WA3">
<Node ID="WA2">
<Node ID="PA"/>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>