WebFaction
Community site: login faq
0
1

Has anyone done such a script before? It will be nice to be able to see this info just like in a cpanel setup where are. able to see and kill proccess.

asked 21 Mar '11, 15:12

ptejada
3128
accept rate: 0%


Yes, we have a python script available on our wiki:

http://wiki.webfaction.com/attachment/wiki/MiscellaneousFiles/memory_usage.py

You can use the following command to download it:

wget -O ~/bin/memory_usage.py 'http://wiki.webfaction.com/attachment/wiki/MiscellaneousFiles/memory_usage.py?format=raw'; chmod 755 ~/bin/memory_usage.py

Then, simply run it: memory_usage.py (or ~/bin/memory_usage.py)

It will show you the total memory usage for all of your processes, along with their Process IDs for easy management. :)

permanent link

answered 21 Mar '11, 21:33

ryans ♦♦
5.0k73159
accept rate: 43%

edited 21 Mar '11, 21:36

This is it! Thank You!

(21 Mar '11, 21:45) ptejada

You can view your currently running processes with:

ps -u $LOGNAME -o pid,command

You can view your total RAM usage (in MB) with:

ps -u $LOGNAME -o rss,command | grep -v peruser | awk '{sum+=$1} END {print sum/1024}'

We might make process listings and memory usage available in the control panel at some point, but I can't say for sure when (or even if) that would be available.

permanent link

answered 21 Mar '11, 16:10

seanf
12.2k31736
accept rate: 37%

After I had some problems with memory usage, I hacked this together. I hope it's useful to you:

#!/usr/local/bin/python2.6

import sys

from commands import getoutput
from time     import sleep
from re       import compile

user  = "YOURUSERNAME"

tobig_single = 30720  # 30MB
tobig_total  = 102400 # 100MB

memory = {
    "total": 0,
    "largest": 0,
}

check = "ps -u %s -o rss,etime,pid,command" % (user)

regex = compile("^\s*(?P<memory>\d+)\s+(?P<time>[\d:-]+)\s+(?P<pid>\d+)\s+(?P<process>.*)")
for line in getoutput(check).split("\n"):
    m = regex.search(line)
    if m:
        mem = int(m.group("memory"))
        memory["total"] += mem
        if mem > memory["largest"]:
            memory["largest"] = mem
        if "-d" in sys.argv:
            print " %5.2fM %s" % (float(mem)/1024, m.group("process")[:100])

if memory["largest"] > tobig_single:
    print "A single process exceeds %sM (%5.2fM)" % (tobig_single / 1024, float(memory["largest"]) / 1024)

if memory["total"] > tobig_total:
    print "Collectively, all processes exceed %sM (%5.2fM)" % (tobig_total / 1024, float(memory["total"]) / 1024)

To use it, set user (line 9) to your username and modify the toobig_* variables to suit your fancy. Run it with no arguments and it'll tell you if those limits are exceeded. Run it with "-d" and it'll show you everything in a nicely formatted list.

permanent link

answered 21 Mar '11, 17:10

danielquinn
121129
accept rate: 14%

I copied your source to a file named 'usage' and uploaded to ~/bin/ When i run the the command: usage -d

I get this error: /home/myuser/bin/usage: /usr/local/bin/python2.6^M: bad interpreter: No such file or directory

Do you have an idea why im getting this error? I have python 2.6 as my default interpreter. I really want to make this work.

(21 Mar '11, 21:22) ptejada

The ^M character suggests that you are using Windows/DOS-style line-endings in your source file.

You should be able to fix that using:

dos2unix /home/myuser/bin/usage

(21 Mar '11, 21:31) ryans ♦♦

Thanks that did the trick. Very nice script! However @ryans suggestion is more complete you should try it, color hinted and PID included

(21 Mar '11, 21:44) ptejada
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×337
×102
×31
×24
×20

question asked: 21 Mar '11, 15:12

question was seen: 11,022 times

last updated: 21 Mar '11, 21:45

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM