diff --git a/.azure-pipelines/azure-pipelines.yaml b/.azure-pipelines/azure-pipelines.yaml index 5987f12..b60de32 100644 --- a/.azure-pipelines/azure-pipelines.yaml +++ b/.azure-pipelines/azure-pipelines.yaml @@ -5,7 +5,7 @@ variables: version: '0.3.0' buildConfiguration: 'Release' disable.coverage.autogenerate: 'true' - imageName: 'ubuntu-18.04' + imageName: 'ubuntu-20.04' # Use build number format, i.e. 0.3.0-B1811001 name: $(version)-B$(date:yyMM)$(rev:rrr) @@ -136,8 +136,8 @@ stages: - template: jobs/test.yaml parameters: - name: ubuntu_18_04_coverage - imageName: 'ubuntu-18.04' + name: ubuntu_20_04_coverage + imageName: 'ubuntu-20.04' displayName: 'PowerShell coverage' coverage: 'false' publishResults: 'false' @@ -159,7 +159,7 @@ stages: name: ps_7_ubuntu_18_04 displayName: 'PowerShell 7.0 - ubuntu-18.04' imageName: mcr.microsoft.com/powershell - imageTag: 7.0.3-ubuntu-18.04 + imageTag: 7.1.3-ubuntu-18.04 - template: jobs/testContainer.yaml parameters: @@ -168,13 +168,6 @@ stages: imageName: mcr.microsoft.com/powershell imageTag: 7.1.3-ubuntu-20.04 - - template: jobs/testContainer.yaml - parameters: - name: ps_6_ubuntu_18_04 - displayName: 'PowerShell 6.2 - ubuntu-18.04' - imageName: mcr.microsoft.com/powershell - imageTag: 6.2.4-ubuntu-18.04 - # Release pipeline - stage: Release displayName: Release diff --git a/.vscode/settings.json b/.vscode/settings.json index b9c80ad..e0ffb12 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,6 +20,7 @@ "editor.tabSize": 2 }, "cSpell.words": [ + "Kusto", "cmdlet", "cmdlets", "hashtable" diff --git a/CHANGELOG.md b/CHANGELOG.md index c9e55a1..71aa9b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +What's changed since pre-release v0.3.0-B2108008: + +- General improvements: + - Added `Duration_d` that duration in milliseconds that the rule took to execute. [#49](https://github.com/microsoft/PSRule.Monitor/issues/49) + ## v0.3.0-B2108008 (pre-release) What's changed since v0.2.0: diff --git a/README.md b/README.md index 28e8133..23751a8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# PSRule to Azure Monitor +# PSRule for Azure Monitor Log PSRule analysis results to Azure Monitor. -![ci-badge] +[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/microsoft/PSRule.Monitor) ## Support @@ -16,9 +16,10 @@ If you have any problems with the [PSRule][engine] engine, please check the proj Support for this project/ product is limited to the resources listed above. -## Getting the modules +## Getting the module -This project requires the `PSRule` PowerShell module. For details on each see [install]. +This project requires the `PSRule` PowerShell module. +For detail on installation and dependencies see [install]. You can download and install these modules from the PowerShell Gallery. @@ -111,9 +112,11 @@ $results | Send-PSRuleMonitorRecord -WorkspaceId -SharedKey ago(1h) ``` diff --git a/docs/samples/sample-queries.md b/docs/samples/sample-queries.md new file mode 100644 index 0000000..9a5d965 --- /dev/null +++ b/docs/samples/sample-queries.md @@ -0,0 +1,12 @@ +# Sample queries + +## Slowest rules + +Get the top 10 slowest rules to execute by average execution time in milliseconds. + +```kusto +PSRule_CL +| where TimeGenerated >= ago(30d) and isnotnull(Duration_d) +| summarize Avg_ms = avg(Duration_d), Max_ms = max(Duration_d), Min_ms = min(Duration_d), Count = count() by RuleId_s +| top 10 by Avg_ms desc nulls last +``` diff --git a/src/PSRule.Monitor/Data/LogRecord.cs b/src/PSRule.Monitor/Data/LogRecord.cs index 9e4327f..293be8e 100644 --- a/src/PSRule.Monitor/Data/LogRecord.cs +++ b/src/PSRule.Monitor/Data/LogRecord.cs @@ -41,5 +41,7 @@ namespace PSRule.Monitor.Data public string RunId { get; set; } public Guid CorrelationId { get; set; } + + public long Duration { get; set; } } } diff --git a/src/PSRule.Monitor/Pipeline/WorkspaceClient.cs b/src/PSRule.Monitor/Pipeline/WorkspaceClient.cs index 3777f02..04d4e86 100644 --- a/src/PSRule.Monitor/Pipeline/WorkspaceClient.cs +++ b/src/PSRule.Monitor/Pipeline/WorkspaceClient.cs @@ -94,6 +94,7 @@ namespace PSRule.Monitor.Pipeline var moduleName = GetField(info, "moduleName"); var annotations = GetProperty(info, "annotations"); var runId = GetPropertyValue(sourceObject, "runId"); + var duration = GetProperty(sourceObject, "time"); var record = new LogRecord { RuleId = ruleId, @@ -109,6 +110,7 @@ namespace PSRule.Monitor.Pipeline Annotations = GetPropertyMap(annotations), RunId = runId, CorrelationId = _CorrelationId, + Duration = duration, }; return record; }