【问题标题】:calculate percentage inode usage using python使用python计算百分比inode使用率
【发布时间】:2013-12-22 07:19:12
【问题描述】:

我正在尝试计算 python 中的 inode 使用百分比。 这是我的示例 python 代码

st = os.statvfs(path)
free  = (st.f_bavail * st.f_frsize) / 1024
total = (st.f_blocks * st.f_frsize) / 1024
used  = ((st.f_blocks - st.f_bfree) * st.f_frsize) / 1024
total_inode = st.f_files        # inodes 
free_inode = st.f_ffree   #free inodes 


# df -i /
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
none                 8257011   69850 8187161    1% /

但是如何计算 df -i 命令中显示的 %inode 呢?我尝试了“total_inodes-free_inodes/total_inodes”,但它给出了错误的百分比使用率。

【问题讨论】:

  • 你做了“total_inodes-free_inodes/total_inodes”还是“(total_inodes-free_inodes)/total_inodes”?
  • 我做了"(total_inodes-free_inodes)/total_inodes

标签: python linux


【解决方案1】:

如果您使用 Python 2.x,int / int 会导致 int 下限。您应该先将其转换为浮点数。

>>> 1/2
0
>>> 1.0/2
0.5
>>> float(1)/2
0.5

print(float(total_inode - free_inode) / total_inode)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 2013-11-15
    • 2020-12-25
    • 2012-11-01
    • 2012-09-20
    相关资源
    最近更新 更多