Re: [Tutor] CPU Utilization]
Alan Gauld wrote: >> shell out to perform the top command, parse the results, and report >> those values to the job controller. > > > I'd use vmstat rather than top since top is intended to run > contuinuously whereas vmstat by default just returns a single line > snapshot. > > I don't know of any native python mechanism for obtaining cpu usage. > > Alan G vmstat is a beautiful thing. Although as I mentioned in reply to others who responded to my question that top can run just once, top actually provides much more information than I am intending to use, making it seem a little wasteful. vmstat is much more focused on exactly the information I want. Although I am using linux pretty much exclusively these days, there's still a lot that I don't know and I wasn't aware that it existed. Thanks ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
Nico wrote: > I think that libgtop and its python binding (used in gdesklets for > example) would do the trick. > Thank you for your thoughts on that. I think in other applications this might have a shot. In this situation I am using diskless workstations with minimal configurations, so gnome libraries will not be an option. At this point I'm going to go with vmstat. Thanks ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
> shell out to perform the top command, parse the results, and report > those values to the job controller. I'd use vmstat rather than top since top is intended to run contuinuously whereas vmstat by default just returns a single line snapshot. I don't know of any native python mechanism for obtaining cpu usage. Alan G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
Thanks for your responses. Michael Janssen wrote: >It's perhaps easier to read the information from the /proc filesystem >(this is where top gets it itself). "man proc" tells where the info is >stored (guess: /proc/stat). > > > stat does look in some ways easier. I will say that I found the statistics somewhat baffling, but I'm sure it's all there. Hugo González Monteverde wrote: >Hi, > >top is very interactive so it would not be easy at all to parse. > > > Actually top has a batch mode. This works pretty well. *def* xmlrpc_idlecpu(self): u = commands.getoutput('top -b -n 1') *return* u.split('\n')[2].split(',')[3] >I can suggest reading /proc/loadavg if you're in Linux. > >proc(5) ('man 5 proc') says that /proc/loadavg is > The load average numbers give the number of jobs in > the run queue averaged over 1, 5 and 15 minutes. > They are the same as the load average numbers given > by uptime(1) and other programs. > >It can be easily parsed with split() > > That's an interesting idea to use that. Although if you have big jobs and little jobs you might not know whether you can add another job to that computer or not, because you would necessarily be attempting to derive the utilization from those statistics. Thank you both for your answers. ds ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] CPU Utilization
Hi, top is very interactive so it would not be easy at all to parse. I can suggest reading /proc/loadavg if you're in Linux. proc(5) ('man 5 proc') says that /proc/loadavg is The load average numbers give the number of jobs in the run queue averaged over 1, 5 and 15 minutes. They are the same as the load average numbers given by uptime(1) and other programs. It can be easily parsed with split() Hope that helps, Hugo DS wrote: > I am implementing a computational cluster and am using a job controller > (for want of a better term) that contacts the worker computers, > determines how busy they currently are, and then assigns more work if > the worker computer is below a certain cpu utilization threshhold. > > For the cpu threshhold, I've been thinking I'd have the worker computer > shell out to perform the top command, parse the results, and report > those values to the job controller. > > Is there a better way, or more pythonic, way to do this? > > Thanks > > ds > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor