3 __author__ =
'Ali GOREN <goren.ali@yandex.com>'
4 __repo__ =
'https://github.com/aligoren/syspy'
5 __license__ =
'Apache v2.0 License'
24 symbols = (
'K',
'M',
'G',
'T',
'P',
'E',
'Z',
'Y')
26 for i, s
in enumerate(symbols):
27 prefix[s] = 1 << (i + 1) * 10
28 for s
in reversed(symbols):
30 value = float(n) / prefix[s]
31 return '%.1f%s' % (value, s)
36 Return all mounted disk partitions as a list of namedtuples
37 including device, mount point and filesystem type,
38 similarly to “df” command on UNIX. If all parameter
39 is False return physical devices only
40 (e.g. hard disks, cd-rom drives, USB keys)
41 and ignore all others (e.g. memory partitions such as /dev/shm).
42 Namedtuple’s fstype field is a string which varies depending on the platform.
43 On Linux it can be one of the values found in /proc/filesystems
44 (e.g. 'ext3' for an ext3 hard drive o 'iso9660' for the CD-ROM drive).
45 On Windows it is determined via GetDriveType and can be either
46 "removable", "fixed", "remote", "cdrom", "unmounted" or "ramdisk".
47 On OSX and FreeBSD it is retrieved via getfsstat(2).
49 for part
in psutil.disk_partitions(all=
False):
51 if 'cdrom' in part.opts
or part.fstype ==
'':
54 usage = psutil.disk_usage(part.mountpoint)
59 ret_uper = int(usage.percent)
61 ret_pmoup = part.mountpoint
63 return ret_pd, ret_ut, ret_usu, ret_ufree, ret_uper, ret_prt, ret_pmoup
67 Return disk usage statistics about the given path as a namedtuple including total,
68 used and free space expressed in bytes, plus the percentage usage.
69 OSError is raised if path does not exist
71 dusage = list(psutil.disk_usage(
'/'))
76 ret_percent = dusage[3]
78 return ret_total, ret_used, ret_free, ret_percent
82 Return system-wide disk I/O statistics as a namedtuple including the following fields:
84 read_count: number of reads
85 write_count: number of writes
86 read_bytes: number of bytes read
87 write_bytes: number of bytes written
88 read_time: time spent reading from disk (in milliseconds)
89 write_time: time spent writing to disk (in milliseconds)
91 dioc = list(psutil.disk_io_counters())
93 ret_read_count = dioc[0]
94 ret_write_count = dioc[1]
95 ret_read_bytes = dioc[2]
96 ret_write_bytes = dioc[3]
97 ret_read_time = dioc[4]
98 ret_write_time = dioc[5]
100 return ret_read_count, ret_write_count, ret_read_bytes, ret_write_bytes, ret_read_time, ret_write_time
def getDiskIoCounters(self)
def getDiskPartitions(self)