Contact SalesSitemapCustomer Login

Go Back   VPSlink Forums > Technical Discussion > Linux

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-07-2006, 01:59 PM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default OpenVZ cpu / mem monitor

One of the interesting quriks of using a virtualizer like OpenVZ is that often tools to show you cpu and memory usage by utilities like top display information for the entire system instead of your individual VPS. However, that information is interesting and often important when you're trying to debug / optimize your own VPS.

However, the problem is that there was no such calculation utility for OpenVZ. Based on that need, I put together a utility that will allow you to view your individual VPS cpu (user / nice / system / idle) and memory usage.

If you're interested in it, feel free to download a copy here:

www.cubedthree.com/projects/openvz/openvzmon.c

If you have any questions, comments or suggestions about how to modify or improve the utility, they would be very much appreciated!

Last edited by jasonaward; 09-21-2006 at 01:59 PM.
Reply With Quote
  #2 (permalink)  
Old 09-07-2006, 04:40 PM
Senior Member
 
Join Date: Aug 2006
Posts: 159
Default

CPU meter works. Pulling a 1MB file from Apache registers a brief 0.5% CPU hit so it seems to be in the ballpark.

The memory meter may have the free and used stats reversed however. I get:
Code:
VPS Memory
   total: 120.31MB used: 59.30MB (49.29%) free: 61.01MB (50.71%)
But with the second script found at http://wiki.vpslink.com/index.php?ti...ization_Script I get:
Code:
privvmpages usage: 61 MB (50%)
One of the two is wrong. Do I have 61 MB free, or do I have 61 MB used?
Reply With Quote
  #3 (permalink)  
Old 09-07-2006, 04:53 PM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default

That's incredibly odd. I've compared the memory usage in my C program with the two memory calculations from the page you linked to, and they all synced up.

Code:
VPS Memory
   total: 479.69MB used: 190.57MB (39.73%) free: 289.11MB (60.27%)
Code:
#/bin/Free
VPS Memory:
  total: 479 mb   used: 188 mb   free: 291 mb
Code:
#/bin/Free2
privvmpages usage: 185 MB (38%)
The minor variations were there because the server was being utilized... but they all produce the same overall result. I'm not sure what's causing a difference on your end .... *unless* your VPS is configured differently!

My guess is that if you run both memory scripts from the linked page, you'll get different results from it as well (note that my C is based upon the first script).

Could you either post or private message me a copy of your /proc/user_beancounters file? I'd like to see what's going on.
Reply With Quote
  #4 (permalink)  
Old 09-07-2006, 05:14 PM
Senior Member
 
Join Date: Aug 2006
Posts: 159
Default

Code:
# openvzmon
VPS CPU
   user: 0.00 nice: 0.00 system: 0.00 idle: 100.00
VPS Memory
   total: 120.31MB used: 59.31MB (49.30%) free: 61.00MB (50.70%)

# free
VPS Memory:
  total: 120 mb   used: 59 mb   free: 61 mb

# free2
privvmpages usage: 61 MB (51%)
As you can see your app is in full agreement with the first "free" script. And unlike on your server, my stats aren't fluctuating to any significant degree between the above invocations.

Code:
# cat /proc/user_beancounters
Version: 2.5
       uid  resource           held    maxheld    barrier      limit    failcnt
     50344: kmemsize        1616446    2405415    5400000    6000000          0
            lockedpages           0          0        128        128          0
            privvmpages       15193      30798      30800      30800         16
            shmpages            643       1299       6000       6000          0
            dummy                 0          0          0          0          0
            numproc              29         42        128        128          0
            physpages          5951      23844          0 2147483647          0
            vmguarpages           0          0      30800      30800          0
            oomguarpages       8681      24806      14400      14400          0
            numtcpsock            3         28        120        120          0
            numflock              1          5         80         80          0
            numpty                7         10         16         16          0
            numsiginfo            0          4        128        128          0
            tcpsndbuf          4456     256220     720000     800000          0
            tcprcvbuf             0     342080     720000     800000          0
            othersockbuf      13368      98568     720000     800000          0
            dgramrcvbuf           0       4276      54000      60000          0
            numothersock         10         20        128        128          0
            dcachesize       119966     173348     540000     600000          0
            numfile             461        684       1600       1600          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            dummy                 0          0          0          0          0
            numiptent            14         14        600        600          0
Reply With Quote
  #5 (permalink)  
Old 09-07-2006, 05:26 PM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default

Ahhh... I know exactly what it is.

Notice how you're really at nearly 50% saturation? So you have nearly as much free memory as you have used.

The problem with the bash scripts is that bash has no concept of floating point numbers. Sometimes you can fake it by using the external bc program, but internally bash just chops off the decimal point. The cause of the entire problem is when you do the division by page size, you're losing data.

So what you're really seeing is a result of truncation of the decimal point in the bash script calculations. It just so happens that the first script calculates in a way that provides a slightly more accurate answer.

The good news is that my C program is substantially more accurate in the calculations than either bash script.

Thanks for trying my program and posting the above information.
Reply With Quote
  #6 (permalink)  
Old 09-07-2006, 05:29 PM
Senior Member
 
Join Date: Jun 2006
Location: Guadalajara, Mexico
Posts: 541
Default

the new version with the memory info works great, thanks for sharing it with us
__________________
pablasso.com (spanish)
Reply With Quote
  #7 (permalink)  
Old 09-07-2006, 06:06 PM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default

Quote:
Originally Posted by pablasso
the new version with the memory info works great, thanks for sharing it with us
No problem! Let me know if you'd like to see it enhanced / extended in any way.
Reply With Quote
  #8 (permalink)  
Old 09-20-2006, 11:38 AM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default

For those of you who care, I made a couple of changes to the monitor. They include:

1) added optional parameter -n which is the number of iterations of information the monitor will display before terminating (similar to the normal 'top' n parameter)

2) added optional parameter -d which is the delay between refreshes in seconds as an integer value (similar to the normal 'top' d parameter) -- which is good when you're debugging something, set d = 1.

The link above should still work.

Let me know if you guys have any questions or comments. Thanks!
Reply With Quote
  #9 (permalink)  
Old 09-20-2006, 12:26 PM
Senior Member
 
Join Date: Aug 2006
Posts: 159
Default

I get a "connection refused" for the server linked to in your first post. This happens both from my VPSLink account and from my home connection.
Reply With Quote
  #10 (permalink)  
Old 09-20-2006, 01:14 PM
Senior Member
 
Join Date: Aug 2006
Posts: 1,019
Default

Quote:
Originally Posted by jcsix
I get a "connection refused" for the server linked to in your first post. This happens both from my VPSLink account and from my home connection.
Sorry about that... I was emerging gcc-4.1.1 and had to take down apache to free up enough memory to get it to compile. It should be working now. Thanks for checking it out.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT. The time now is 03:30 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0