question

JooSilva-5381 avatar image
0 Votes"
JooSilva-5381 asked AlexZhu-MSFT answered

How do i monitor CPU Usage on a Linux Agent Managed Server through Powershell?

Hello, i'm trying to build a dashboard with some performance counters without using the graphs but instead using the powershell grid script widget. But i can't seem to find any information regarding out to get the % cpu utilization on the linux machines through powershell? I understand Get-SCXAgents exists but it only shows me information relative to the agent itself? And Get-Counter only works on windows machines from what i read..

Any idea on how i could accomplish this?

Thanks in advance,
Joao

msc-operations-manager
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexZhu-MSFT avatar image
1 Vote"
AlexZhu-MSFT answered AlexZhu-MSFT edited

Hi,

As for as I know, it's not so easy to get CPU usage of Linux computers to show the data in the dashboard. Strong PowerShell skill and Linux knowledge are required. Here's some thoughts shared, just for your reference.

If we have SSH client installed in the Management Server (Note: Server 2019 is required to install SSH client) and have configured passwordless ssh connection as mentioned below, we may create a PowerShell Grid Widget, enter the script (just an example, need to be completed) to see if it works.

How to Setup Passwordless SSH Connect from Windows to Linux
Note: This is not from Microsoft, just for your reference

For writing a complete script, we may refer the article below.
Operations Manager Dashboard Script Widgets

 $i=1
 foreach ($computer in $computers)
 {
     $cpu_usage_linux = ssh root@10.1.1.250 "top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | gawk '{print `$2+`$4+`$6}'"
     $dataObject=$ScriptContext.CreateFromObject/CreateInstance.......
     $dataObject["Index"]=$i
     $dataObject["CPU"]=$cpu_usage_linux
     $ScriptContext.ReturnCollection.Add($dataObject)
     $i++
 }

add a widget

117327-scom-dashboard-powershell-linux-01.png

enter the script (only the main structure, need to be complete in real environment)

117422-scom-dashboard-powershell-linux-02.png

test the command in PS directly

117366-scom-dashboard-powershell-linux-03.png

Alex
If the response is helpful, please click "Accept Answer" and upvote it.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JooSilva-5381 avatar image
0 Votes"
JooSilva-5381 answered

I was able to do this thankfully.

On another note, do you know of a way to get the values for the Bytes Sent and Received per second over the network, or on the interface? I was only able to find a reliable way to get the total bytes sent and received in the entire time of that interface and not the last value.

How could i approach this? Thank you very much,

Joao

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlexZhu-MSFT avatar image
0 Votes"
AlexZhu-MSFT answered

Hi,

Thank you very much for getting back. I'm not an export of Linux shell scripting. For this request, we may consider performing the task via the shell script. Thoughts:
1, write a shell script that get the data we desired
2, using ssh to run the script and return the output
3, store the returned output to $dataObject as above

For a quick test, I've put the above command in the test.bash to see if it works

 vi ./test.sh
    
 #!/bin/bash
 top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | gawk '{print $2+$4+$6}'

118139-scom-dashboard-powershell-linux-04.png


Alex
If the response is helpful, please click "Accept Answer" and upvote it.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.