Skip to content

Instantly share code, notes, and snippets.

@CTimmerman
Created June 4, 2015 14:11
Show Gist options
  • Save CTimmerman/0016fc26f784e5ad640c to your computer and use it in GitHub Desktop.
Save CTimmerman/0016fc26f784e5ad640c to your computer and use it in GitHub Desktop.
Get and check local and remote (Tomcat) memory usage
"""Checks memory percentage of first process by user name.
2015-06-04 v1.0 by Cees.Timmerman@nospam
Run with `python -m doctest mem_perc.py`.
>>> ps_tomcat = ['ps', 'u', '-U', 'tomcat6']
>>> mem_perc(ps_tomcat) < 20
True
>>> mem_perc(['ssh', 'other.host'] + ps_tomcat) < 20
True
"""
import re, subprocess as sub
def mem_perc(cmd_list): return float(re.split('\s+', sub.check_output(cmd_list, stderr=sub.STDOUT).split('\n')[1])[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment