LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need "percentage" from vmstat (https://www.linuxquestions.org/questions/linux-newbie-8/need-percentage-from-vmstat-4175418252/)

JKimbrell 07-23-2012 11:27 AM

Need "percentage" from vmstat
 
Hello All,
Hopefully, someone can help with this.
We have an in house monitoring solution, and I need to return a percentage of usage from the "swpd" in vmstat instead of just a number.

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 488 162276 841144 30837840 0 0 628 29 4 9 6 2 90 2 0


Any ideas?
J.

TB0ne 07-23-2012 12:01 PM

Quote:

Originally Posted by JKimbrell (Post 4735949)
Hello All,
Hopefully, someone can help with this.
We have an in house monitoring solution, and I need to return a percentage of usage from the "swpd" in vmstat instead of just a number.

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 488 162276 841144 30837840 0 0 628 29 4 9 6 2 90 2 0

If you're looking for the percentage of the swap memory, you should start with the output of the "free" command instead. It'll give you the total, used, and free amounts. From there, calculating a percentage in bash is fairly simple:
http://www.ukdragon.com/blog/index.p...ntages_in_bash

So grab the free output into variables like:
Code:

$total = `free | grep Swap | awk {'print $2'}`
$used = `free | grep Swap | awk {'print $3'}`
$free  = `free | grep Swap | awk {'print $4'}`

(note: TOTALLY untested and unchecked).

That'll give you variables, run your percentage from there.

JKimbrell 07-23-2012 12:15 PM

That's nice TBone, however, I need more that this..
Appreciate you looking however.

TB0ne 07-23-2012 12:39 PM

Quote:

Originally Posted by JKimbrell (Post 4735993)
That's nice TBone, however, I need more that this..
Appreciate you looking however.

More than what??? What's missing?

JKimbrell 07-23-2012 01:18 PM

Don't need to get worked up, I don't like the answer, I need more of a complete answer.
Not an untested line of syntax and a URL.

TB0ne 07-23-2012 01:22 PM

Quote:

Originally Posted by JKimbrell (Post 4736051)
Don't need to get worked up, I don't like the answer, I need more of a complete answer.
Not an untested line of syntax and a URL.

Wasn't worked up, was asking what was missing. The answer is "nothing". The only 'untested' part is how to CALL the command to build a variable in bash. I think it's correct, but (since YOU are going to write the script), I left it to you to research. I even gave you a link to a tutorial showing you how to figure percentages in bash, so you could use what you were given.

You don't like it, feel free to figure it out on your own...you asked for ideas. I pointed you to the right system utility to use, gave you three lines of variable-producing code from which (if you put any effort into it), you could have easily written your own script.

I'm guessing what you wanted was someone to write it for you, and hand you something tested and debugged. No, thanks....you were given ideas, direction, and instructions to take it further. If you don't want to, then tell someone else at your company to write it.


All times are GMT -5. The time now is 07:14 PM.