calculate percentage inode usage using python

Viewed 2222

I am trying to calculate percentage of inode usage in python. Here is my sample python code

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% /

but how to calculate %inode as shown in df -i command? i tried "total_inodes-free_inodes/total_inodes" but it is giving wrong percentage usage.

1 Answers
Related