~doanac/+junk/health-check-test

« back to all changes in this revision

Viewing changes to health-check-test-get-pids.py

  • Committer: Andy Doan
  • Date: 2013-11-14 04:10:05 UTC
  • Revision ID: andy.doan@canonical.com-20131114041005-vie9t1c9a614jv6d
initial commit

slightly modified from cking's original tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import os
 
4
 
 
5
import psutil
 
6
 
 
7
basedir = os.path.dirname(__file__)
 
8
default_threshold_path = os.path.join(basedir, 'thresholds')
 
9
 
 
10
ignore_procs = [
 
11
    'health-check', 'init', 'cat', 'vi', 'emacs', 'getty', 'csh', 'bash', 'sh']
 
12
 
 
13
with open(os.path.join(basedir, 'procmapping.txt'), 'w') as mapping:
 
14
    for p in psutil.process_iter():
 
15
        try:
 
16
            if os.getpgid(p.pid) != 0:
 
17
                procname = os.path.basename(p.name)
 
18
                fname = default_threshold_path + "/" + procname + ".threshold"
 
19
                if not p.name in ignore_procs:
 
20
                    if os.path.isfile(fname):
 
21
                        mapping.write('%s:%d\n' % (procname, p.pid))
 
22
                        print(procname)
 
23
        except:
 
24
            pass