I am a huge fan of Microsoft and I love to work with Microsoft products but sometimes I like to make a step to the “Dark Side” and put my fingers on Linux . As I frequently answer some questions on TechNet I found an interesting question. How could you monitor processes on Linux and use a performance visualize it? Well let’s find out…
In this case we are going to show the %CPU used by the Linux SCOM agent. First we need some background information.
The Linux SCOM agent runs 2 processes:
- scxcimserver
- scxcimprovagt
Actually it runs scxcimprovagt two times under different accounts root and the Linux agent action account. To visualize it we run the “top” command in Linux…
The big deal now is to get a command which strips out the appropriate information and returns just the total amount of %CPU of all these 3 processes.
After some fumbling and binging I got it together. The secret formula is:
top -b n 1 | grep scxcim* | awk ‘{cpu = cpu + $9} END {print cpu}’
The “top” command shows the actual processes runnig. Using –b n 1 makes the output usable for filtering by “grep” and then we use “awk” to add up the CPU columns. In our case $9 means the 9th column from the left.
Now we just need to add things up and let build the performance rule first.
Step 1 – Performance Rule
Create a new rule “Unix/Linux Shell Command (Performance)” and save it into a separate management pack…
Next select a name and target…
Choose the interval to run the command…
Now you can insert the command we just discussed…
We just leave it the way it is and click “Next”…
Now you could map the parameters as they will appear on the performance view (don’t change the “Value” parameter) and click “Create”…
Next, because I have disabled the rule in the wizard I need to make an override for the appropriate target…
Step 2 – Performance View
In the Monitoring pane create a new Performance View…
Select the rule we just created…
The select the view and after a a few minutes your performance rule will appear…
Cool!
Hot tip:
If you analyze the “top” command in Linux you see there are multiple columns 1 to 10.
If you now adjust the command…
top -b n 1 | grep scxcim* | awk ‘{cpu = cpu + $9} END {print cpu}’
to something like…
top -b n 1 | grep gnome* | awk ‘{mem = mem + $10} END {print mem}’
you could use it to get the sum of the used %Memory for the gnome processes and then also build a performance view!
Got it? Is that cool or what?
Cheers,
Stefan
hi I try to create this rule but in performance view it don’t show this rule what can I do for resolve problem?
code of get cpu and mem works good on server
Hi Giorgi
It may take a couple minutes until the rule appears in the Performance View. Is the rule still not visible?
Regards,
Stefan
I have the same problem as Giorgi…
for info, i finally found what is wrong in your procedure….
Hi Sigera
Sorry about the delay, I have been quite busy.
What did you find out? Let me know and I will write it on the post.
Thank you,
Stefan
In fact, the quotes in your linux command (for the awk part) aren’t correct (‘ instead of ´). The command works well like that but doesn’t work if you test it via a task in opsmgr. 3 hours to find this 🙂
Hi Sigera
Thanks for your hint. Well, it is always a problem if you copy / paste directly from a blog post, depending on the site and local character set. A lot of trouble generates also dashes “-“, or the ” ” ” characters, and pipe “|” symbols.
Sorry, about that…
Stefan
Your mode of explaining the whole thing in this article is actually good, every one be able to
without difficulty be aware of it, Thanks a lot.
Hi, I used the command
free -m|grep Mem| awk ‘{ram = ram + $3} END {print ram}’
and aplied it to Red Hat computers, but the graphic dont show results