Get the App
SLTechnology News&Howtos  ›  Servers  › 

Powershell implementation setup program correlation script

Shulou Source: shulou.com Published: 2022-06-02 05:31:47 10月02日 Update

The company has always had a server with high CPU usage. It is analyzed that the Java usage of Hang Seng monitoring program is very high, and only one of the three Java programs is very high. It needs to be solved by Hang Seng, which has not been solved, resulting in weekly restart. Our operation and maintenance have to manually set the program correlation, which brings trouble to operation and maintenance.

In order to solve the duplication of operation and maintenance work, we plan to see if it can be implemented by script. By querying online data, we can set the program correlation through powershell. The reference links are as follows:

https://www.pstips.net/setting-process-running-under-specific-cpu.html

Therefore, the following powershell script was written to achieve automatic program settings cpu high java program dependency settings.

Set the number of cpu runs.ps1 script as follows:

#Get java processes with CPU higher than 40%, because there are three java processes on the machine, and the paths are consistent.

$id=Get-Process | Where-Object {$.Name -eq "java"} | Where-Object {$.CPU -gt 40}

#Set the first 4 CPUs to run, freely configure which CPUs to run. ProcessorAffinity

$id.ProcessorAffinity=15

Create a callpowershell.bat to run powershell scripts.

powershell set cpu run number.ps1

Finally, configure callpowershell.bat on the delayed startup tool to delay startup for 2 minutes.

After the above steps, after restarting the server for 2 minutes every week, the Java process that occupies 100% CPU will automatically specify 4 CPUs. It solves the duplication of labor in the operation and maintenance process.

Tags: Programs runs scripts dependencies number processes three servers Hang Seng Labor Services configuration similarity consistency Freedom Monitoring programs companies tools Manual machines Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Linux Docker Redmi