PDA

View Full Version : Interested in monitoring cpu/ram usage?



rbredow
10-24-2007, 12:07 AM
If you're interested in monitoring cpu and memory usage for apache and mysql you might find these commands helpful. I worked them out based on some suggestions in this westhost article - http://members.westhost.com/reducing-resources.html.

You can add the following code to your /.bashrc file and then simply type "musage" at the commandline to get a summary of the apache and mysqld cpu and memory usage:



alias musage_apache="usage=0; for mem in \`ps aux | grep httpd | grep -v grep | awk '{print \$6}'\`; do usage=\`expr \$mem + \$usage\`; done; echo apache: \$usage kilobytes"
alias cusage_apache="wget -nv --http-user=YOURUSER --http-password=YOURPASSWORD http://www.YOURSERVER.com/server-status/ -O - | grep \"CPU Usage:\""

alias musage_mysql="echo -n \"mysqld: \"; ps auxw | grep mysqld | grep -v grep | tail -1 | awk '{printf \"%d\", \$6}';echo \" kilobytes\""
alias cusage_mysql="echo -n \"mysqld: \"; ps auxw | grep mysqld | grep -v grep | tail -1 | awk '{printf \"%d\", \$3}';echo \" cpu percent\""

alias musage="musage_apache;cusage_apache;musage_mysql;cusage_my sql";


It should just work after updating your YOURUSER, YOURPASSWORD and YOURSERVER in the lynx line above.

Hope it's helpful for you. Lot easier than trying to add up the columns of ps aux yourself.

Enjoy-

-Rob

Corrado Fiore
12-06-2007, 09:16 AM
Nice one, thanks for sharing this! And, BTW, I didn't even know of the existence of the manual page you linked :-). Very useful.

Thanks,
Corrado Fiore

heinzel
03-01-2008, 01:57 AM
Hi,

I just migrated to WH 3.0 in the regular update process on a shared VPS. After the migration, the http://yourdomain.com/server-status/ page is not accessible anymore. Anybody else see the same behaviour?

Best,
Matthias

wildjokerdesign
03-01-2008, 07:14 AM
You can activate it by manually editing your httpd.conf file located at /etc/httpd/conf. Around line 934 you should see a Location tag for it that has been commented out. Simply change it to the second code example below and restart your account. The code you are looking for is this:

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>
# SetHandler server-status
# Order deny,allow
# Deny from all
# Allow from .example.com
#</Location>
Change To:

<Location /server-status>
SetHandler server-status
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /usr/local/apache/.htpasswd
Require valid-user
satisfy any
ORDER allow,deny
allow from 69.36.160.253 69.36.160.254
</Location>

This well require that you log in useing your main username password to view the page. Always nice to protect server information. :)

Remember when dealing with the httpd.conf file that you should use a plain text editor and download and upload in mode mode not binary mode. You must always restart your account to have your changes take effect.

Pablo
04-16-2008, 02:53 AM
Thanks for that tip its jus what I needed. Can someone tell me how I can log these figures using a cron job that runs every 5 minutes?

epicheirimatias
08-06-2008, 10:59 PM
I've properly configured server-status, but I'm having one problem.

Everything works fine, except that I'm running WordPress for my domain.

So even if I access to mydomain.com/server-status, my wordpress 404 page shows up and says nothing found for server-status.

What should I do in this kind of case?

wildjokerdesign
08-07-2008, 07:56 AM
Are you using "Pretty Permalinks"? If so then I imagine it is your .htaccess file that is causing the problem. I would need to see a copy of your .htaccess file to give you further guidance.

wildjokerdesign
08-07-2008, 10:08 AM
Try adding this to your .htaccess file if you are using pretty permalinks:

RewriteCond %{REQUEST_FILENAME} !server-status
You can add it right before:

RewriteRule . /wordpress/index.php [L]

epicheirimatias
08-07-2008, 09:58 PM
Mine is this. But I'll try your suggestion.


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

UPDATE:
Your suggested code just worked fine. THANK YOU!!

wildjokerdesign
08-08-2008, 07:32 AM
Your welcome. I thought that may do the job. :) The first two "conditions" in the rewrite tells the server that if there really is a file (-f) or directory (-d) that the "rule" should not be used. That is why you see the !, it means negative or not. Since server-status is not a "real" directory or file those two conditions where not met. I simply added a condition that was similar to the first two but more specific. :)