linux_fs.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:igcollect 作者: innogames 项目源码 文件源码
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']:
                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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号