Skip to content

Commit 0b0eafc

Browse files
committed
Adds feature to set process priority for Icinga for Windows to BelowNormal for improved Host performance
1 parent d9ba095 commit 0b0eafc

6 files changed

+76
-0
lines changed

Diff for: doc/100-General/10-Changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1818

1919
### Enhancements
2020

21+
* [#756](https://github.com/Icinga/icinga-powershell-framework/pull/756) Adds feature to set process priority for Icinga for Windows to BelowNormal for improved Host performance
22+
2123
## 1.13.0 Beta-1 (2024-08-30)
2224

2325
[Issues and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/32)

Diff for: jobs/SetProcessPriority.ps1

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Load the basic framework data
2+
Use-Icinga -Minimal;
3+
4+
# Wait 10 seconds before procedding
5+
Start-Sleep -Seconds 10;
6+
7+
# Fetch the process information for JEA and the Icinga for Windows PID
8+
$JeaProcess = Get-Process -Id (Get-IcingaJEAServicePid) -ErrorAction SilentlyContinue;
9+
$IfWProcess = Get-Process -Id (Get-IcingaForWindowsServicePid) -ErrorAction SilentlyContinue;
10+
11+
# Set the JEA pid to below normal
12+
if ($null -ne $JeaProcess -And $JeaProcess.ProcessName -eq 'wsmprovhost') {
13+
$JeaProcess.PriorityClass = 'BelowNormal';
14+
}
15+
16+
# Set the Icinga for Windows pid to below normal
17+
if ($null -ne $IfWProcess -And $IfWProcess.ProcessName -eq 'powershell') {
18+
$IfWProcess.PriorityClass = 'BelowNormal';
19+
}
20+
21+
# Exit with okay
22+
exit 0;

Diff for: lib/core/framework/Invoke-IcingaForWindowsMigration.psm1

+11
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,18 @@ function Invoke-IcingaForWindowsMigration()
151151
Start-IcingaWindowsScheduledTaskRenewCertificate;
152152
# Ensure the Icinga Agent is not spamming the Application log by default
153153
Write-IcingaAgentEventLogConfig -Severity 'warning';
154+
# Set our newly added process update task
155+
Register-IcingaWindowsScheduledTaskProcessPriority -Force;
154156

155157
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.0');
156158
}
159+
160+
if (Test-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.0.1')) {
161+
Write-IcingaConsoleNotice 'Applying pending migrations required for Icinga for Windows v1.13.0.1';
162+
163+
# Set our newly added process update task
164+
Register-IcingaWindowsScheduledTaskProcessPriority -Force;
165+
166+
Set-IcingaForWindowsMigration -MigrationVersion (New-IcingaVersionObject -Version '1.13.0.1');
167+
}
157168
}

Diff for: lib/core/windows/Restart-IcingaWindowsService.psm1

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function Restart-IcingaForWindows()
99
}
1010

1111
Restart-IcingaService -Service 'icingapowershell';
12+
# Update the process priority after each restart
13+
Start-IcingaWindowsScheduledTaskProcessPriority;
1214
}
1315

1416
Set-Alias -Name 'Restart-IcingaWindowsService' -Value 'Restart-IcingaForWindows';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function Register-IcingaWindowsScheduledTaskProcessPriority()
2+
{
3+
param (
4+
[switch]$Force = $FALSE
5+
);
6+
7+
[string]$TaskName = 'Set Process Priority';
8+
[string]$TaskPath = '\Icinga\Icinga for Windows\';
9+
10+
$SetProcessPriorityTask = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue;
11+
12+
if ($null -ne $SetProcessPriorityTask -And $Force -eq $FALSE) {
13+
Write-IcingaConsoleWarning -Message 'The {0} task is already present. User -Force to enforce the re-creation' -Objects $TaskName;
14+
return;
15+
}
16+
17+
$ScriptPath = Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath '\jobs\SetProcessPriority.ps1';
18+
$TaskAction = New-ScheduledTaskAction -Execute 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -Argument ([string]::Format("-WindowStyle Hidden -Command &{{ & '{0}' }}", $ScriptPath));
19+
$TaskPrincipal = New-ScheduledTaskPrincipal -UserId 'S-1-5-18' -RunLevel 'Highest' -LogonType ServiceAccount;
20+
$TaskSettings = New-ScheduledTaskSettingsSet -DontStopIfGoingOnBatteries -AllowStartIfOnBatteries -StartWhenAvailable;
21+
22+
Register-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Force -Principal $TaskPrincipal -Action $TaskAction -Settings $TaskSettings | Out-Null;
23+
24+
Write-IcingaConsoleNotice -Message 'The task "{0}" has been successfully registered at location "{1}".' -Objects $TaskName, $TaskPath;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function Start-IcingaWindowsScheduledTaskProcessPriority()
2+
{
3+
[string]$TaskName = 'Set Process Priority';
4+
[string]$TaskPath = '\Icinga\Icinga for Windows\';
5+
6+
$SetProcessPriorityTask = Get-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -ErrorAction SilentlyContinue;
7+
8+
if ($null -eq $SetProcessPriorityTask) {
9+
Write-IcingaConsoleNotice -Message 'The "{0}" task is not present on this system.' -Objects $TaskName;
10+
return;
11+
}
12+
13+
Start-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath;
14+
}

0 commit comments

Comments
 (0)