for root, dirs, files in os.walk('/var/run/ceph/'): for name in files: if "osd" in name and "pid" in name : osdlist = [] osdthlist=[] for osdcpu in range(psutil.cpu_count()): osdlist.append(" ") osdthlist.append("0") pidfile=root+ name osdid=commands.getoutput('ls %s|cut -d "." -f 2 2>/dev/null' %pidfile ) osdpid = commands.getoutput('cat %s 2>/dev/null' %pidfile) osd_runcpu = commands.getoutput('ps -o psr -p %s |grep -v PSR 2>/dev/null' %osdpid) th_list = commands.getoutput('ps -o psr -L -p %s |grep -v PSR|awk \'gsub(/^ *| *$/,"")\' 2>/dev/null' % osdpid)
osdname="osd."+osdid osdlist[int(osd_runcpu)]="+" for osdth in th_list.split('\n'): osdthlist[int(osdth)] = int(osdthlist[int(osdth)])+1 osdlist.insert(0,osdname) osdthlist.insert(0,osdname) if choose == "process": row.add_row(osdlist) elif choose == "thread": row.add_row(osdthlist) print row