FqSc@s%ddlmZyddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z Wne k rnXdZidd6aejddfkrejdnyeefWnek rdZd ZnXejddfko9ejdd fkrHd Zn!ejddfkrid Znejdd fkrd Znejjdejjejjejd dddgZdfdYZdfdYZdefdYZdefdYZ defdYZ!defdYZ"defdYZ#d efd!YZ$d"efd#YZ%d$efd%YZ&d&efd'YZ'd(efd)YZ(d*efd+YZ)d,efd-YZ*d.efd/YZ+d0efd1YZ,d2efd3YZ-d4efd5YZ.d6efd7YZ/d8efd9YZ0d:efd;YZ1d<efd=YZ2d>efd?YZ3d@efdAYZ4dBefdCYZ5dDefdEYZ6dFefdGYZ7dHefdIYZ8dJefdKYZ9dLefdMYZ:dNefdOYZ;i'dPdQ6dRdS6dTdU6dVdW6dXdY6dZd[6d\d]6d^d_6d`da6dbdc6ddde6dfdg6dhdi6djdk6dldm6dndo6dpdq6drds6dtdu6dvdw6dxdy6dzd{6d|d}6d~d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6a<idd6dd6dd6dd6dd6dd6dd6Z=dZ>dZ?dZ@dZAdZBdZCddZDddZEddZFdZGdZHeIdZJdZKeIdZLdZMeIdZNdZOdZPdZQdZRdZSddddZTdZUdZVdZWdZXdZYdZZedZ[dZ\dZ]dZ^dZ_dZ`dZadZbdZcdZdZddZeefdkryeYeejdage>atgjhrddlhZhejjitgjhrejjtgjhnehjkdtgjhnedWn/e k rZltgjmrejnjodnnXed nedagdapdS(i(t generatorsNs0.7.2ttdefaultis#error: Python 2.2 or later requirediiiccs0d}x#|D]}||fV|d}q WdS(Nii((tsequencetindextitem((s/usr/share/dstat/dstat.pyt enumerate*s  cCs>d}g}x+|D]#}|j||f|d}qW|S(Nii(tappend(RRtseqlistR((s/usr/share/dstat/dstat.pyR0s  cCs%d}x|D]}||}q W|S(Ni((Rtretti((s/usr/share/dstat/dstat.pytsum;s s ~/.dstat/s /plugins/s/usr/share/dstat/s/usr/local/share/dstat/tOptionscBs5eZdZdZdZdZdZRS(cCs||_t|_t|_d|_d|_d|_d|_d|_ t|_ t|_ t|_ d|_ d|_d|_t|_t|_t|_t|_t|_d|_t}g|_tjjst|_t|_t|_nidod6dpd 6dqd6|_yetj|dddddddddddddddddd d!d"d#d$d%g|\}}Wn2tjk r}d&t|GHtj dnXx:|D]2\}}|drkr|jj!d(q|dskr|j"d*|_q|dtkr|jj!d,q|dukr>|j#||_ q|dvkr]|jj!d/q|dwkr||jj!d1q|dxkr|jj!d3q|dykr|j"d*|_ q|dzkr|jj!d6q|d{kr|jj!d8q|d|krJtj$d<|d=j%|j"d*fIJ|j|j"d*7_q|d}kri|jj!d?q|d~kr|j"d*|_q|dkr|jj!dBq|dkr|jj!dDq|dkr|jj!dFq|dkr|j"d*|_q|dkr'|jj!dIq|dkrF|jj!dKq|dkre|jj!dMq|dkr|jd(d,d?d1dMg7_q|dkr|jdBd8d1d,dMd(g7_q|dkrt|_ q|dkrij&|j'}|j(|j|7_q|dkr/t|_q|dkrGt|_q|dkrf|jd|_q|dkr~t|_ q|dkrt|_ q|dkrt)tj dq|dkrt|_t|_q|dkrt|_q|dkr t|_q|dkr"||_q|dkr:||_q|dkrRdc|_q|dkr|j*|j+tj dq|dkr|j,tj dq|j-dhr|jj!|diqdj|GHtj dqW|j r|j rdkGHtj dn|js8dlGHd(d,d?d1dMg|_nyTt.|dkrct/|d|_nt.|dkrt/|d|_nWndmGHtj dnX|jdkrdnGHtj dndS(NiiiRtsdashd[a-d]tlocalssd[b-k]ssd[v-z]ssda[a-e]tloresssd[l-u]ssda[f-o]thiress acdfghilmno:prstTvyC:D:I:M:N:S:Vtalls all-pluginstbitstbwt blackonwhitetdebugt filesystemtfloattfullthelptintegertlisttmodstmodulestnocolort noheaderstnoupdatesoutput=spidfile=tprofiletversiontvmstats5dstat: %s, try dstat -h for a list of all the optionss-ctcpus-Ct,s-dtdisks-Ds --filesystemtfss-gtpages-itints-Is-ltloads-mtmems-Ms--modss --moduless9WARNING: Option %s is deprecated, please use --%s insteads --s-ntnets-Ns-ptprocs-rtios-stswaps-Ss-tttimes-Ttepochs-ytsyss-as--alls-vs--vmstats-fs--fulls --all-pluginss--bitss--bws--black-on-whites--debugs--floats --integers--lists --nocolors --noheaderss --noupdates-os--outputs --pidfiles --profilesdstat_profile.logs-hs--helps-Vs --versions--isNdstat: option %s unknown to getopt, try dstat -h for a list of all the optionssOdstat: option --float and --integer are mutual exlusive, you can only force ones6You did not select any stats, using -cdngy by default.s>dstat: incorrect argument, try dstat -h for the correct syntaxs2dstat: delay must be an integer, greater than zero(R shd[a-d](ssd[b-k]ssd[v-z]ssda[a-e](ssd[l-u]ssda[f-o](s-c(s-C(s-d(s-D(s --filesystem(s-g(s-i(s-I(s-l(s-m(s-Ms--modss --modules(s-n(s-N(s-p(s-r(s-s(s-S(s-t(s-T(s-y(s-as--all(s-vs--vmstat(s-fs--full(s --all-plugins(s--bits(s--bws--black-on-white(s--debug(s--float(s --integer(s--list(s --nocolor(s --noheaders(s --noupdate(s-os--output(s --pidfile(s --profile(s-hs--help(s-Vs --version(0targstFalseRRtcounttNonetcpulistRtdelaytdisklistRRRtintlisttnetlisttswaplisttTruetcolortupdatetheadertoutputtpidfileR!t listpluginstpluginsR2tstdouttisattytdisksettgetoptterrortstrtexitRtsplitt get_disklisttstderrtjointfromkeystkeystsortt showpluginstusageRR"t startswithtlenR)(tselfR3t allpluginstoptstexctopttargRD((s/usr/share/dstat/dstat.pyt__init__Is"                           &           )          ! $                                  cCs|jd}g}x|D]}|d dkrtjj|rtjj|rtj|}|ddkrtjjtjj||}tjj|}nd||fGH|}n|d}|j |qd|GHq|j |qW|S(NR%is/dev/it/sdstat: symlink %s -> %ssdstat: %s does not exist( RLtostpathtexiststislinktreadlinkROtdirnametnormpathR(RWtdisksR9R R&ttarget((s/usr/share/dstat/dstat.pyRMs" !   cCsdtGHdGHdGHHdtjtjfGHdtjdGHdtjGHHd}t|jsgd }nd tj d |fGHt \}}d ||fGHHd t GHdt j GHdtjdGHH|atdS(NsDstat %ss&Written by Dag Wieers s2Homepage at http://dag.wieers.com/home-made/dstat/sPlatform %s/%ss Kernel %sis Python %sRsno s#Terminal type: %s (%scolor support)tTERMs#Terminal size: %d lines, %d columnssProcessors: %ds Pagesize: %dsClock ticks per secs: %dt SC_CLK_TCK(tVERSIONR_tnameR2tplatformtunameR"t gettermcolorR>tgetenvt gettermsizetgetcpunrtresourcet getpagesizetsysconftopRS(RWR>trowstcols((s/usr/share/dstat/dstat.pyR"s*    cCs dGHdS(Ns/Usage: dstat [-afv] [options..] [delay [count]]((RW((s/usr/share/dstat/dstat.pyRT!scCs dGHdS(NsC Versatile tool for generating system resource statistics Dstat options: -c, --cpu enable cpu stats -C 0,3,total include cpu0, cpu3 and total -d, --disk enable disk stats -D total,hda include hda and total -g, --page enable page stats -i, --int enable interrupt stats -I 5,eth2 include int5 and interrupt used by eth2 -l, --load enable load stats -m, --mem enable memory stats -n, --net enable network stats -N eth1,total include eth1 and total -p, --proc enable process stats -r, --io enable io stats (I/O requests completed) -s, --swap enable swap stats -S swap1,total include swap1 and total -t, --time enable time/date output -T, --epoch enable time counter (seconds since epoch) -y, --sys enable system stats --aio enable aio stats --fs, --filesystem enable fs stats --ipc enable ipc stats --lock enable lock stats --raw enable raw stats --socket enable socket stats --tcp enable tcp stats --udp enable udp stats --unix enable unix stats --vm enable vm stats --plugin-name enable plugins by plugin name (see manual) --list list all available plugins -a, --all equals -cdngy (default) -f, --full automatically expand -C, -D, -I, -N and -S lists -v, --vmstat equals -pmgdsc -D total --bits force bits for values expressed in bytes --float force float values on screen --integer force integer values on screen --bw, --blackonwhite change colors for white background terminal --nocolor disable colors (implies --noupdate) --noheaders disable repetitive headers --noupdate disable intermediate updates --output file write CSV output to file --profile show profiling statistics when exiting dstat delay is the delay in seconds between each update (default: 1) count is the number of updates to display before exiting (default: unlimited) ((RW((s/usr/share/dstat/dstat.pyR$s6(t__name__t __module__R]RMR"RTR(((s/usr/share/dstat/dstat.pyR Hs    tdstatcBseZdZdZdZdZdZdZdZ dZ dZ dZ ddZ dddZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZRS(tfiiicCst|jr!|j|_nt|jrB|j|_n|jsWtdnt|jrx|j|_nt|jr|j|_n|js|j|_ni|_i|_i|_|j dkrx|jD])}d|j|<|j|<|j|(RWR RR Rk((s/usr/share/dstat/dstat.pyRs  6 - !cCs{d}t|jtjrx~t|jD]m\}}|td|d|j!j|jt dtd}|dt |jkr+|t d}q+q+W|Sxt|jD]\}}x~t|jD]m\}}|td|d|j!j|jt dtd}|dt |jkr|t d}qqW|dt |jkr|tdt d}qqW|SdS( NRtsubtitleiRRiRtcolon( RRkRRRRRRRRRV(RWR R RRktj((s/usr/share/dstat/dstat.pyRs77cCst|jtjr9d|jddt|jdSd}xjt|jD]Y\}}|d|ddt|jd}|dt|jkrO|d}qOqOW|SdS(Nt"R%iR(RRkRRRVRR(RWR R Rk((s/usr/share/dstat/dstat.pytcsvtitles$'cCsd}t|jtjrwxUt|jD]D\}}|d|d}|dt|jkr+|d}q+q+W|Sxt|jD]\}}xUt|jD]D\}}|d|d}|dt|jkr|d}qqW|dt|jkr|d}qqW|SdS(NRRiR%(RRkRRRRRV(RWR R RRkR((s/usr/share/dstat/dstat.pyt csvsubtitlescCsG|jstdn|js*tdn|jr:tStddS(sCheck if stat is applicables$No objects found, no stats availables)No objects discovered, no stats availablesUnknown problem, please reportN(RRR~RR=(RW((s/usr/share/dstat/dstat.pytchecks     cGstS(N(R=(RWtobjlist((s/usr/share/dstat/dstat.pyR~ scCs!d}t|dr4t|j|j|j|jSxt|jD]\}}t|j |t j st|j |t j r|t |j ||j|j|j}tdtd}n3|t|j ||j|j|j}td}|dt|jkrD||}qDqDW|S(sDisplay stat resultsRRARRRi(thasattrtcprintRAttypeRtscaleRRRRRt TupleTypetListTypet cprintlistRRRV(RWRR RkR((s/usr/share/dstat/dstat.pytshows2)) cCs@||dk r tdtdS||kr<tdtdSdS(NiRtpipetgtR(RR(RWttotlisttvislist((s/usr/share/dstat/dstat.pytshowend s  cCs0d}d}xt|jD] \}}t|j|tjs]t|j|tjrxt|j|D]F\}}|||}|dt|j|krq|d}qqqqWnDt|j|tjr||j|}n|||j|}|dt|jkr|d}qqW|S(NcSs(|t|krd|Sdt|S(Ns%.3fs%s(tround(tvar((s/usr/share/dstat/dstat.pytprintcsv(sRiR%( RRRRRRRRVR(RWRRR RkRR((s/usr/share/dstat/dstat.pytshowcsv's 2 cCs,||dk rdS||dk r(dSdS(NiR%R((RWRR((s/usr/share/dstat/dstat.pyt showcsvend<s N(RxRyR6RRkRRRRRwRRRRRRRRRRRRR~RRRR(((s/usr/share/dstat/dstat.pyRz]s0             t dstat_aiocBseZdZdZRS(cCs>d|_d|_d|_d|_d|_|jddS( Ntasyncs#aiotaiotdis/proc/sys/fs/aio-nr(s#aio(R(RkRRRRR(RW((s/usr/share/dstat/dstat.pyR]Ds      cCsJxC|jD]5}t|dkr+q nt|d|jdd |_d|_d|_d |_|jd d |_dS( NtusrR2tidltwaithiqtsiqtpii"s /proc/stati(RssysRRRR(RRRRRRw(RW((s/usr/share/dstat/dstat.pyR]Rs      cGsg}xX|jD]J}t|dks|ddd!dkrHqn|j|ddqW|jx|D]}|j|qrW|S(NiiiR$(RRVRRR(RWRR RR((s/usr/share/dstat/dstat.pyR~Zs)  cCsg}tjrtj}nNtjs-d}n<g}d}x-|tkrh|jt||d}q<Wx4|D],}||jdgkrp|j|qpqpW|S(NR|ii(stotal(RuR7RtcpunrRRJR~(RWR tvarlistR$Rk((s/usr/share/dstat/dstat.pyRcs     cCsOg}xB|jD]7}|dkr2|jdq|jd|dqW|S(NR|stotal cpu usageR$s usage(RR(RWR Rk((s/usr/share/dstat/dstat.pyRkus  c Csx|jD]}t|dkr+q nx|jD]}|dd|ksk|ddkr5|dkr5t|dt|dt|dt|dt|d t|d t|d f|j|d|_d|_d|_d|_|jdd|_dS( NRR2RRii"s /proc/stat(susrssyssidl(RRRRRRw(RW((s/usr/share/dstat/dstat.pyR]s      cGsg}xX|jD]J}t|dks|ddd!dkrHqn|j|ddqW|jx|D]}|j|qrW|S(NiiiR$(RRVRRR(RWRR RR((s/usr/share/dstat/dstat.pyR~s)  cCsg}tjrtj}nNtjs-d}n<g}d}x-|tkrh|jt||d}q<Wx4|D],}||jdgkrp|j|qpqpW|S(NR|ii(stotal(RuR7RRRRJR~(RWR RR$Rk((s/usr/share/dstat/dstat.pyRs     cCsKg}x>|jD]3}|dkr2|jdq|jd|qW|S(NR|s cpu usageR$(RR(RWR Rk((s/usr/share/dstat/dstat.pyRks  c CsEx|jD]}x|jD]{}|dd|ksS|ddkr|dkrt|dt|dt|dt|df|j|d|_d|_tjd|_|jdd|_dS(NRtwrittbs ^(dm-\d+|md\d+|[hsv]d[a-z]+\d+)$s/proc/diskstatsi(sreadR(RRtretcompilet diskfilterRRw(RW((s/usr/share/dstat/dstat.pyR]s    cGsg}x`|jD]R}t|dkr1qn|ddgdkrNqn|d}|j|qWx|D]}|j|qpW|stdn|S(Ni it0i is*No suitable block devices found to monitor(RRVRR(RWRR RRkR((s/usr/share/dstat/dstat.pyR~s   cCsg}tjrtj}nptjs-d}n^g}xK|jD]@}|jj|r[q=n|tkrpq=n|j|q=W|jxA|D]9}||jdgtj j kr|j|qqW|S(NR|(stotal( RuR9RR~Rtmatcht blockdevicesRRRRGRQ(RWR RRk((s/usr/share/dstat/dstat.pyRs"      #cCs$g|jD]}dt|^q S(Nsdsk/(Rt sysfs_dev(RWRk((s/usr/share/dstat/dstat.pyRksc Csx|jD]}d|j|   #HHW%6(RxRyR]R~RRkR(((s/usr/share/dstat/dstat.pyRIs     t dstat_epochcBseZdZdZRS(cCs=d|_d|_d|_tjr0d|_nd|_dS(NR1i i i(sepoch(RkRRRuRR(RW((s/usr/share/dstat/dstat.pyR]s      cCst|jd|jjD]-}|j||j|dt |j |d|_d|_tjd|_|jdd|_dS(NtrecvtsendRs^(lo|bond\d+|face|.+\.\d+)$s /proc/net/devi(R!ssend(RRRRt totalfilterRRw(RW((s/usr/share/dstat/dstat.pyR]s    cGsg}x~|jddD]j}t|dkr7qn|ddkr]|ddkr]qn|d}|d kr|j|qqW|jx|D]}|j|qW|S( NRRiiRi itlotface(sloR%(RRVRRR(RWRR RRkR((s/usr/share/dstat/dstat.pyR~s     cCsg}tjrtj}n%tjs-d}n|j}|jx7|D]/}||jddgkrG|j|qGqGW|stdn|S(NR|R$s/No suitable network interfaces found to monitor(stotal(RuR;RR~RRRR(RWR RRk((s/usr/share/dstat/dstat.pyRs        cCsg|jD]}d|^q S(Nsnet/(R(RWRk((s/usr/share/dstat/dstat.pyRkscCsddg|jdsrawR?(ssockets:sTCP:sUDP:sRAW:sFRAG:(RkRRRRRR(RW((s/usr/share/dstat/dstat.pyR]Xs      cCsxG|jD]9}t|dkr+q nt|d|j|d(RxRyR]R(((s/usr/share/dstat/dstat.pyRas t dstat_udpcBseZdZdZRS(cCsJd|_d |_d |_d|_d|_d|_|jd d dS( NR>RMRNRRRSRiids /proc/net/udps/proc/net/udp6(slissact(slistens established(RkRRRRRR(RW((s/usr/share/dstat/dstat.pyR]s      cCsx|jD]}d|j|RRRRRt+tplust_t underscorec Cs@tjr$itdd6tdtdd6tdd6tdd6tdtd d 6tdd 6td d 6tdd6tdd6tdd6tdd6tdd6td tdtdtdtdtdtdtdfd6tdtdtdtdtdtdtd tdfd6}nitdd6tdtdd6tdd6tdd6tdtd d 6tdd 6td d 6tdd6tdd6tdd6tdd6tdd6tdtdtdtdtdtdtd tdfd6td td tdtdtdtdtdtdfd6}|S(!sProvide a set of colors to useR{RR}RRRRRRRIt roundtripRxRRtinputRwttext_lottext_hitunit_lotunit_hiR|RyR~RRt colors_loRRRt colors_hiRRz(RuRtansi(R((s/usr/share/dstat/dstat.pyt set_themedsH           #)          #&cCsyVxOtdddjD]5}|j}t|dkrFqnt|dSWWnpxjtdjD]R}|j}t|dkrqon|ddkrotjt|dSqoWnXdS( s)Return the number of 'ticks' since bootups /proc/uptimetriis /proc/stattbtimeiN(RRRLRVRRR0R(RR((s/usr/share/dstat/dstat.pyttickss  cCsN|jdr%|jdd}n%|jdrJ|jdd}n|S(sImprove a device names /dev/mapper/R^is/dev/i(RURL(tdevname((s/usr/share/dstat/dstat.pyRCs cCstjj|s"td|ndtjkr@ianttjkrkt|ddt|trFtj||}|s+Pn|j|V|d7}q WdS(s/Return the splitted lines of a file, one by oneiN(R=RRRL(RRR R((s/usr/share/dstat/dstat.pytproc_splitlines s cCstj|dS(sReturn the first line of a filei(RR(R((s/usr/share/dstat/dstat.pyt proc_readlinescCstj|dj|S(s(Return the first line of a file splittedi(RRRL(RR((s/usr/share/dstat/dstat.pytproc_splitlinesccslttj}xStjdD]B}y%t|||krGw"n|VWq"tk rcq"q"Xq"WdS(sReturn a list of process IDss/proc/N(RJR_tgetpidtlistdirR)t ValueError(t dstat_pidtpid((s/usr/share/dstat/dstat.pyt proc_pidlist#s    cCsed}xRtrTttt|}t||kr=Pn||}|d}q Wd}||fS(s/Convert decimal to string given base and lengthiii(R=RJRRRV(RRtbasetcR ((s/usr/share/dstat/dstat.pytdchg3s  cCsd}xtr|dkr+td}Pnttt||}t||kr|t|d}xw|dkrd||}t||kr|ttt||krPn|d}qoWttt|}Pn||}|d}q Wd}||fS(s.Convert float to string given scale and lengthiRis%%.%dfi(R=RJRRRV(RRRRR R ((s/usr/share/dstat/dstat.pytfchg@s&   3 cCsd|d|df}t||krd|d}t||krd|dd}t||krd|ddd}qqn|S(s#Convert time string to given lengths%2dh%02di<s%2dhs%2ddis%2dwi(RV(RRR ((s/usr/share/dstat/dstat.pyttchgZscCsFd}}x5|D]-}||t||||}td}qW|S(s Return all columns color printedRR(RR(RRRRR RR((s/usr/share/dstat/dstat.pyRes   R{iic Csd}|dkrd}nt}|d"krX|tt|krXt}|d}n|dkr|rtddj|tdtdtdStddj|tdtdSn|dkrtdd d d d d dddf }n8tjr#|d#kr#d$}d}}|d}nd%}t tj krYtd}td}td} ntd}td}td} tj r|d&krt |||\} } ntj r|d'krt|||\} } n|d(krt |||\} } n{|dkr%t|||\} } nT|dkrGt||} } n2|dkrlt|||} } n td|| d kr| } n|dkr|} n|d)kr|t||t|} n\|dkr|tt||t|} n)|d*kr&|| t|} n|} |d+krU| | j|td} n| | j|td} |r| d!krt|dkr| | || 7} q| td7} n| S(,sColor print one columniiiiRIRRRtktMtGtTtPtEtZtYRg @tBRRRRRRRRR{RcRsType %s not known to dstat.Ri(ii(R( RRRRRRRRR( RRRRRRRRR(RRRR{(RRRR{(RRR(ii(RRR{(Rc(R4RVRJR=RtrjustRRuRRR8RRRRRRR)Rtljust( RRRRRtunittunitstcolorstctexttcunitR RR>((s/usr/share/dstat/dstat.pyRmsr  $  ,' (                  ! '  cCsd}xl|D]d}||j7}||dk rL|tdtd7}q ||kr |tdtd7}q q W|d7}xl|D]d}||j7}||dk r|tdtd7}q||kr|tdtd7}qqW|dS( s.Return the header for a set of module countersRiRRRRs R(RRRR(RRRto((s/usr/share/dstat/dstat.pyR@s     cCsd}x;|D]3}||j}||dk r |d}q q W|d7}x;|D]3}||j}||dk rU|d}qUqUW|dS(s2Return the CVS header for a set of module countersRiR%s (RR(RRR((s/usr/share/dstat/dstat.pyt csvheaders   cCstj|IJdS(sOutput info messageN(R2RN(tlevelRJ((s/usr/share/dstat/dstat.pytinfoscCstj|IJt|dS(s#Print error and exit with errorcodeN(R2RNRK(R RJ((s/usr/share/dstat/dstat.pytdies cCs}y/ddladdladdlatjWnAy*tjtjdtjdfWnqyXdanXdadS( sInitialise terminaliNR:Rwii(Ni(Ni( tfcntltstructttermiost TIOCGWINSZtcursest setuptermttigetnumR6ttermsize(((s/usr/share/dstat/dstat.pytinitterms$    cCstdsytddkrmtjddddd}tjtjjtj |}tj d|d Stddkrt j t j dt j dfSttjdttjdfaWqd aqXntS( s$Return the dynamic terminal geometryiitHHHHiR:RwtLINEStCOLUMNSiiP(iiP(RRtpackRtioctlR2RERRRtunpackRRRR)R_tenviron(Rctx((s/usr/share/dstat/dstat.pyRps ! * cCsg|rctjjrcy3ddl}|j|jddkrGtSWqctjdIJtSXn|S(s/Return whether the system can use colors or notiNRis:Color support is disabled, python-curses is not installed.(R2RERFRRRR4RN(R>R((s/usr/share/dstat/dstat.pyRns   cCs$|ddkr tjj|S|S(sPerform basename on paths onlyiR^t.(R^R(R_R`tbasename(Rk((s/usr/share/dstat/dstat.pyR&scCsd}ytjd|djd}t|d}|dkrWt|d}n|jd rt|d }|jd rqn|snWnt|}nX|S(sAReturn the name of a process by taking best guesses and exclusions/proc/%s/cmdlineititbashtcshtkshtperltpythontrubytshRiN(RRRRspythonRR(R6RRRLRRU(RRkR tcmdline((s/usr/share/dstat/dstat.pyt getnamebypid,s   cCs_d}x:tdjD]&}|dd!dkr|d}qqW|dkr[tdn|S(s'Return the number of CPUs in the systemis /proc/statiiR$is)Problem finding number of CPUs in system.(RRR(RR((s/usr/share/dstat/dstat.pyRq=s  cCs8gtjdD]$}tjj|jdd^qS(Ns /sys/block/*t!R^(tglobR_R`RR(R((s/usr/share/dstat/dstat.pyRGscCstjd|}|r^|j}t|ddt|d}dttd|Stjd|}|r|j}|dStjd |}|rd S|S( s,Convert sysfs device names into device namess,ide/host(\d)/bus(\d)/target(\d)/lun(\d)/disciiithdtascciss/(c\dd\d)it placeholdertsdX(RRRR)tchrtord(tdeviceRRtnr((s/usr/share/dstat/dstat.pyRLs " cCsdg}dddddddd d d g }d g}d dddddddddddddddg}dg}ddd d!d"d#d$d%g}d&g}d'g} d(g} ||kr ttd)|j|d*|d*} |d*} | sd+| Sd,| | fS||krhttd)|j|d-|d.} |d.} | sZd/| Sd0| | fS|| kr|d1|S||krd2|S||krd3|S||krd4|S|| kr| j|d*|d*} |d*} | sd5| Sd6| | fS||krY|j|} |d*} |d*} | sHd7| | fSd8| | | fS||kr|j|d*|d*} |d*} | sd9| Sd:| | fSd;||fSd<S(=s+Convert major/minor pairs into device namesiiii!i"i8i9iXiYiZi[iiiAiBiCiDiEiFiGiiiiiiiii iHiIiJiKiLiMiNiOibihiR issd%sssd%s%dii@shd%sshd%s%dsdm-%dsmd%dsloop%dsram%dsc0d%dsc0d%dp%dsida%d-%ds ida%d-%d-%dsubd%dsubd%d-%dsdev%d-%dN(RRR(tmajtmintramtidetlooptscsitmdtidatubdtccisstdmtdisctparttcont((s/usr/share/dstat/dstat.pyR^sb $ 6     +  +            cCsg}tjd}xCtD]8}|jdr|j|j|jdqqWtjd}xXtD]P}xGtj|dD]2}|j|j|jdj ddqWqqW|j |S(Ns dstat_(.+)$tdstat_is.+/dstat_(.+).py$s /dstat_*.pyRR( RRRRURRRt pluginpathR RRR(RDtremodRR`((s/usr/share/dstat/dstat.pyRCs' 4 cCst\}}dGtjd}g}xOtD]D}|jdr2|j|j|jdjddq2q2W|j |d}xd|D]\}|t |d}|dkrd G|t |d }n||d kr|d GqqW|GHtjd }xt D]}g}xGt j |dD]2}|j|j|jdjddq0W|srqn|j |d}dt jj|Gxd|D]\}|t |d}|dkrd G|t |d }n||d kr|d GqqW|GHqWdS(Ns internal: s dstat_(.+)$R iRRiis i iR%s.+/dstat_(.+).py$s /dstat_*.pys%s: (RpRRRRURRRRRRRVR!R R_R`tabspath(RvRwR"RDRtcols2tmodR`((s/usr/share/dstat/dstat.pyRSsF3     0    cCstjjtdtjjtjrRtjj tjrRtj tjntj rtjj tj rt \}}ddl }|jtj }|jdj|dntj rtjdIJntj|dS(NRit cumulativei s=No profiling data was found, maybe profiler was interrupted ?(R2RERRtflushRuRBR_R`RaRR!RptpstatstStatst sort_statst print_statsRNRK(R RvRwR(R((s/usr/share/dstat/dstat.pyRKs   c Bseaejdaejddaeeja e j a d}e j}ejd}ejjdejjrejd}ejd}|dkr|rejdj|rejjd ||ejjejd d jejfqneeje_ejrejj ejrje!ejd d a"t"jd n3e!ejdd a"t"jde#t"jdt"jd||ft"jdd jeje$j%de$j&fnej'rmy<e!ej'dd }|jeej|j(Wqme)k ri}ej*dej'I|IJe+e_'qmXnejse+e_,xt-j.D]}dt-|} n | f} x | D]} d$| j3d%d&} y| e4j.krd'd(l5} | j6| e7\}}}|j(|d d?kr7e8|d*d(U| e9_:e9j;e9j<q|d d+krvd,| d(Ud-| d(Ue9j;e9j<qej*d.| IJn d/| d(Ue9j;e9j<Wne)k r%}| | d'krej*d0| |fIJn#ej=r ej*d1| |fIJnej=d2krqqnej*d3| IJnX|e9j>d}t1j?e9ej=rd4G| Ge@e9d5rd6Ge9jAGnHnPqWqWt1seBd7d8nejrt"jeCt1neDjEe$j$e$jF}e$j$aGd a,d aHxqt,ej0ejIks&ejId'krq|jJtGt,deKt,f|jLejjMt,|a,eNjOqWej,rejjd9nd(S(@s<Initialization of the program, terminal, internal structuresRiiist XTERM_SHELLRhs /bin/bashs(screen*|xterm*)s]0;(%s@%s) %s %siRR s tws"Dstat %s CSV output" s["Author:","Dag Wieers ",,,,"URL:","http://dag.wieers.com/home-made/dstat/" s"Host:","%s",,,,"User:","%s" s'"Cmdline:","dstat %s",,,,"Date:","%s" s%d %b %Y %H:%M:%S %ZsFailed to create pidfile %sRRRRR$tcpu24R&tdisk24t disk24oldR)tint24R(tpage24R/tswapoldR RRiNs.pys%o = dstat_plugin(); del(dstat_plugin)s.sos import %ss o = %s.new()sModule %s is of unknown type.so = %s()sModule %s failed to load. (%s)s.Module %s failed to load, trying another. (%s)is"Module %s caused unknown exceptiontModuleRtrequiresis-None of the stats you selected are available.s (scpuR.(sdiskR/R0(sintR1(spageR2(sswapR3(s.py(PRqRR_RtthzR2R&RJRtownpidRrRsR-tgetpasstgetuserRmRERRFRoRRRR`RtargvRORuR3RnR>RARaRt outputfileRjR0ReRfRBRURRNR4R?RRQRR8RRDRRtimpt find_moduleR!texecfileRRRRRRRRRRRtschedt schedulertsleeptinittimetmissedR5tenterabstperformR1R'Rt clearcache(tintervaltuserthostnametshellttermRBtetkeyt linewidthtpluginRR%t pluginfileR<tfptpathnamet descriptionR@((s/usr/share/dstat/dstat.pytmains   *E  8                              (    cCstja|dtjtja|dtjdatjsKd}n'tdksctdkrldand}tdkrtt|dkrt da dStdkrt a d\a a gagatanta tjjrt }t\a a |t krxgaxctD]X}||jd}|t ks[ttd kr|t krtj||}qqWntjrt dkrttkrtaqtdkrtt ddkrtaqntantattjkrtdtdsBH@    *   & =8BAOBFD =3   *              S            J $  w