当前位置: 首页>>代码示例>>Python>>正文


Python os.statvfs方法代码示例

本文整理汇总了Python中os.statvfs方法的典型用法代码示例。如果您正苦于以下问题:Python os.statvfs方法的具体用法?Python os.statvfs怎么用?Python os.statvfs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在os的用法示例。


在下文中一共展示了os.statvfs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _free_space

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def _free_space(self, directory, power=0):
		"""
			Get available free space at a target directory.

			@param directory: directory path of a folder
			@type directory: basestring

			@return: Available free space
			@rtype: float
		"""
		assert power >= 0
		assert isinstance(directory, basestring)
		assert self.validate_dir(directory)
		if not directory or not os.path.isdir(directory):
			return 0
		statvfs = os.statvfs(directory)
		free_space = statvfs.f_frsize * statvfs.f_bfree
		return free_space / math.pow(1024, power) 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:20,代码来源:validator.py

示例2: disk

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def disk():
    c = statsd.StatsClient(STATSD_HOST, 8125, prefix=PREFIX + 'system.disk')
    while True:
        for path, label in PATHS:
            disk_usage = psutil.disk_usage(path)

            st = os.statvfs(path)
            total_inode = st.f_files
            free_inode = st.f_ffree
            inode_percentage = int(100*(float(total_inode - free_inode) / total_inode))

            c.gauge('%s.inodes.percent' % label, inode_percentage)
            c.gauge('%s.total' % label, disk_usage.total)
            c.gauge('%s.used' % label, disk_usage.used)
            c.gauge('%s.free' % label, disk_usage.free)
            c.gauge('%s.percent' % label, disk_usage.percent)
        time.sleep(GRANULARITY) 
开发者ID:thenetcircle,项目名称:dino,代码行数:19,代码来源:statsd-agent.py

示例3: test_structseq

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def test_structseq(self):
        import time
        import os

        t = time.localtime()
        for proto in protocols:
            s = self.dumps(t, proto)
            u = self.loads(s)
            self.assertEqual(t, u)
            if hasattr(os, "stat"):
                t = os.stat(os.curdir)
                s = self.dumps(t, proto)
                u = self.loads(s)
                self.assertEqual(t, u)
            if hasattr(os, "statvfs"):
                t = os.statvfs(os.curdir)
                s = self.dumps(t, proto)
                u = self.loads(s)
                self.assertEqual(t, u)

    # Tests for protocol 2 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:pickletester.py

示例4: disk_usage

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def disk_usage(path, diskUsage='all'):
    st = os.statvfs(path)
    free = st.f_bavail * st.f_frsize
    total = st.f_blocks * st.f_frsize
    used = (st.f_blocks - st.f_bfree) * st.f_frsize

    if diskUsage == 'free':
        diskUsage = free
    elif diskUsage == 'total':
        diskUsage = total
    elif diskUsage == 'used':
        diskUsage = used
    elif diskUsage == 'all':
        diskUsage = free, total, used
    else:
        diskUsage = None

    return diskUsage

## funtion get_hostname : return raspberry pi hostname info 
开发者ID:jeonghoonkang,项目名称:BerePi,代码行数:22,代码来源:rpiMonitor.py

示例5: _update

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def _update(data):
        try:
            st = os.statvfs("/")
        except Exception as e:
            return e  # just for tests; we don't really need return value

        mb = 1000 ** 2  # sadly storage is generally expressed in decimal units
        new_data = dict(
            mb_free=st.f_bfree * st.f_frsize // mb,
            mb_total=st.f_blocks * st.f_frsize // mb,
            mb_used=(st.f_blocks - st.f_bfree) * st.f_frsize // mb,
            inodes_free=st.f_ffree,
            inodes_total=st.f_files,
            inodes_used=st.f_files - st.f_ffree,
        )
        for key in ["mb_total", "mb_used", "inodes_total", "inodes_used"]:
            data[key] = max(new_data[key], data.get(key, 0))
        for key in ["mb_free", "inodes_free"]:
            data[key] = min(new_data[key], data.get(key, float("inf")))

        return new_data 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:23,代码来源:inner.py

示例6: main

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def main():
    args = parse_args()
    mountpoints = []
    with open('/proc/mounts', 'r') as fp:
        for line in fp:
            a, mountpoint, fstype, a = line.split(' ', 3)
            if fstype in ['ext2', 'ext3', 'ext4', 'xfs', 'zfs']:
                mountpoints.append(mountpoint)

    template = args.prefix + '.{}.{} {} ' + str(int(time()))
    for mp in mountpoints:
        stat = os.statvfs(mp)
        used = stat.f_frsize * stat.f_blocks - stat.f_bfree * stat.f_bsize
        size = stat.f_frsize * stat.f_blocks

        if mp == '/':
            mp = 'rootfs'
        mp = mp.replace('/', '_').lstrip('_')

        print(template.format(mp, 'used', used))
        print(template.format(mp, 'size', size)) 
开发者ID:innogames,项目名称:igcollect,代码行数:23,代码来源:linux_fs.py

示例7: getFreeSpace

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def getFreeSpace(logs_path):
    space = os.statvfs(os.path.expanduser("~"))
    free = space.f_bavail * space.f_frsize / 1024000
    total = space.f_blocks * space.f_frsize / 1024000

    used_by_logs = getLogsSize(logs_path)
    total_for_logs = free + used_by_logs
    percentage = (float(used_by_logs)/float(total_for_logs)) * 100
    total_for_logs_gb = float(total_for_logs) / 1024.0

    result = {
        "used": "{0:.0f}".format(used_by_logs),
        "total": "{0:.1f}".format(total_for_logs_gb),
        "percentage": "{0:.0f}".format(percentage)
    }

    print("Returning sizes!")
    print(result)

    return result 
开发者ID:Stefal,项目名称:rtkbase,代码行数:22,代码来源:reach_tools.py

示例8: get_path_usage

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def get_path_usage(path):

    space_st = os.statvfs(path)

    # f_bavail: without blocks reserved for super users
    # f_bfree:  with    blocks reserved for super users
    avail = space_st.f_frsize * space_st.f_bavail

    capa = space_st.f_frsize * space_st.f_blocks
    used = capa - avail

    return {
        'total': capa,
        'used': used,
        'available': avail,
        'percent': float(used) / capa,
    } 
开发者ID:bsc-s2,项目名称:pykit,代码行数:19,代码来源:fsutil.py

示例9: read_disk

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def read_disk():
    """
    Returns disk usage for /tmp

    :returns: Disk usage (total, used, percentage used)
    :rtype dict
    """
    s = os.statvfs("/tmp")
    return {
        # This should report as 500MB, if not may need to be hardcoded
        # https://aws.amazon.com/lambda/faqs/
        "totalMiB": (s.f_blocks * s.f_bsize) / MB_FACTOR,
        "usedMiB": ((s.f_blocks - s.f_bfree) * s.f_frsize) / MB_FACTOR,
        "usedPercentage": round(
            (((s.f_blocks - s.f_bfree) * s.f_frsize) / (s.f_blocks * s.f_bsize)) * 100,
            2,
        ),
    } 
开发者ID:iopipe,项目名称:iopipe-python,代码行数:20,代码来源:system.py

示例10: disk_metrics

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def disk_metrics():
    """Get the disk usage, in bytes."""

    def add_usage(ms, dus, dname):
        try:
            for i, val in enumerate(dus):
                if val.decode("utf-8") == dname:
                    ms[dname] = int(dus[i - 1])
        except Exception:
            pass

    # Overall disk usage
    statinfo = os.statvfs("/")
    metrics = {"used": statinfo.f_frsize * (statinfo.f_blocks - statinfo.f_bfree)}

    # Per-directory disk usage
    dirs = ["/home", "/nix", "/srv", "/tmp", "/var"]
    argv = ["du", "-s", "-b"]
    argv.extend(dirs)  # why doesn't python have an expression variant of this!?
    dus = subprocess.check_output(argv).split()
    for dname in dirs:
        add_usage(metrics, dus, dname)

    return metrics 
开发者ID:barrucadu,项目名称:lainonlife,代码行数:26,代码来源:metrics.py

示例11: get_disk_info

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def get_disk_info(self, path):
        try:
            folder = os.path.dirname(path)
            if sys.platform == 'win32':
                free_bytes, total_bytes, _ = win32file.GetDiskFreeSpaceEx(folder)
                used_bytes = total_bytes - free_bytes
            else:
                st = os.statvfs(folder)
                free_bytes = st.f_bavail * st.f_frsize
                total_bytes = st.f_blocks * st.f_frsize
                used_bytes = (st.f_blocks - st.f_bfree) * st.f_frsize
            return (total_bytes, free_bytes, used_bytes)
        except:
            if DEBUG:
                log('baseapp::get_disk_info: cannot get disk info: path', path)
            return (None, None, None) 
开发者ID:alesnav,项目名称:p2ptv-pi,代码行数:18,代码来源:BaseApp.py

示例12: test_structseq

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def test_structseq(self):
        import time
        import os

        t = time.localtime()
        for proto in protocols:
            s = self.dumps(t, proto)
            u = self.loads(s)
            self.assert_is_copy(t, u)
            if hasattr(os, "stat"):
                t = os.stat(os.curdir)
                s = self.dumps(t, proto)
                u = self.loads(s)
                self.assert_is_copy(t, u)
            if hasattr(os, "statvfs"):
                t = os.statvfs(os.curdir)
                s = self.dumps(t, proto)
                u = self.loads(s)
                self.assert_is_copy(t, u) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:pickletester.py

示例13: disk_usage

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def disk_usage(path):
    """Return disk usage associated with path."""
    try:
        st = os.statvfs(path)
    except UnicodeEncodeError:
        if not PY3 and isinstance(path, unicode):
            # this is a bug with os.statvfs() and unicode on
            # Python 2, see:
            # - https://github.com/giampaolo/psutil/issues/416
            # - http://bugs.python.org/issue18695
            try:
                path = path.encode(sys.getfilesystemencoding())
            except UnicodeEncodeError:
                pass
            st = os.statvfs(path)
        else:
            raise
    free = (st.f_bavail * st.f_frsize)
    total = (st.f_blocks * st.f_frsize)
    used = (st.f_blocks - st.f_bfree) * st.f_frsize
    percent = usage_percent(used, total, _round=1)
    # NB: the percentage is -5% than what shown by df due to
    # reserved blocks that we are currently not considering:
    # http://goo.gl/sWGbH
    return sdiskusage(total, used, free, percent) 
开发者ID:krintoxi,项目名称:NoobSec-Toolkit,代码行数:27,代码来源:_psposix.py

示例14: disk_usage

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def disk_usage(mount_path):
    """
    Return disk usage statistics about the given path as a (total, used, free)
    namedtuple.  Values are expressed in bytes.
    """
    # Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
    # License: MIT
    _ntuple_diskusage = collections.namedtuple('usage', 'total used free')

    if platform.system() == "Linux":
        st = os.statvfs(mount_path)
        free = st.f_bavail * st.f_frsize
        total = st.f_blocks * st.f_frsize
        used = (st.f_blocks - st.f_bfree) * st.f_frsize

        return _ntuple_diskusage(total, used, free)

    elif platform.system() == "Windows":

        _, total, free = ctypes.c_ulonglong(), ctypes.c_ulonglong(), \
                         ctypes.c_ulonglong()
        if sys.version_info >= (3,) or isinstance(mount_path, unicode):
            fun = ctypes.windll.kernel32.GetDiskFreeSpaceExW
        else:
            fun = ctypes.windll.kernel32.GetDiskFreeSpaceExA
        ret = fun(mount_path, ctypes.byref(_), ctypes.byref(total), ctypes.byref(free))
        if ret == 0:
            raise ctypes.WinError()
        used = total.value - free.value

        return _ntuple_diskusage(total.value, used, free.value)
    else:
        raise NotImplementedError("Platform not supported.") 
开发者ID:mbusb,项目名称:multibootusb,代码行数:35,代码来源:usb.py

示例15: CheckDiskSpace

# 需要导入模块: import os [as 别名]
# 或者: from os import statvfs [as 别名]
def CheckDiskSpace(self):
    stat = os.statvfs('/Users')
    free_space_mb = (stat.f_bavail * stat.f_frsize) / 1048576
    if free_space_mb < FREE_SPACE:
      print ('You have less than 30GB of free disk space.\n'
             ' Depending on what you\'re installing into the image, '
             'that may not be enough.')
      sys.exit() 
开发者ID:google,项目名称:macops,代码行数:10,代码来源:can_haz_image.py


注:本文中的os.statvfs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。