/[svn.andrew.net.au]/usbspindownd/diskstats.py
ViewVC logotype

Annotation of /usbspindownd/diskstats.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 29 - (hide annotations)
Tue Jan 29 19:48:35 2008 UTC (13 years, 10 months ago) by apollock
File MIME type: text/x-python
File size: 1255 byte(s)
Initial import

1 apollock 29 #!/usr/bin/python
2    
3     #
4     # Python module for parsing /proc/diskstats on Linux
5     #
6     # Author: Andrew Pollock <me@andrew.net.au>
7     # Copyright: (c) 2008 Andrew Pollock
8     #
9    
10     class DiskStat:
11    
12     def __init__(self, nrread, nrmergedread, nrsectorsread, msread, nrwrite, nrmergedwrite, nrsectorswrite, mswrite, nrio, msio, weightedmsio):
13     self.nrread = nrread
14     self.nrmergedread = nrmergedread
15     self.nrsectorsread = nrsectorsread
16     self.msread = msread
17     self.nrwrite = nrwrite
18     self.nrmergedwrite = nrmergedwrite
19     self.nrsectorswrite = nrsectorswrite
20     self.mswrite = mswrite
21     self.nrio = nrio
22     self.msio = msio
23     self.weightedmsio = weightedmsio
24    
25    
26     class DiskStats:
27    
28     def __init__(self, disk):
29     self.disk = disk.lstrip("/dev/")
30    
31     def diskstat(self):
32     proc_diskstats = open("/proc/diskstats")
33     stat = None
34     while True:
35     line = proc_diskstats.readline()
36     if line == "":
37     break
38     else:
39     line = line.split()
40    
41     if line[2] == self.disk:
42     stat = line[3:]
43     proc_diskstats.close()
44     if stat:
45     ds = DiskStat(stat[0], stat[1], stat[2], stat[3], stat[4], stat[5], stat[6], stat[7], stat[8], stat[9], stat[10])
46     return ds
47     else:
48     # Need to raise an exception here
49     pass
50    
51     if __name__ == "__main__":
52     ds = DiskStats("/dev/hda")
53     print ds.diskstat()

  ViewVC Help
Powered by ViewVC 1.1.22