Skip to content

Instantly share code, notes, and snippets.

@meunierd
Created March 23, 2012 01:28
Show Gist options
  • Save meunierd/2166040 to your computer and use it in GitHub Desktop.
Save meunierd/2166040 to your computer and use it in GitHub Desktop.
vmstat 1 | python watcher.py 12 5000 5
#!/usr/bin/env python
import sys
col = int(sys.argv[1])
val = int(sys.argv[2])
limit = int(sys.argv[3])
count = 0
def get_l():
l = sys.stdin.readline().strip()
while l.startswith('procs') or l.startswith('r'):
l = sys.stdin.readline().strip()
return l
l = get_l()
while l is not None:
tokens = l.split()
if val < int(tokens[col - 1]):
count += 1
if limit <= count:
print "Hit Limit."
count = 0
else:
count = 0
l = get_l()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment