@@ -118,12 +118,13 @@ def __gather_loadavg_info():
118118
119119
120120class Disk :
121- def __init__ (self , mount , file_system , total , used , avail ):
121+ def __init__ (self , mount , file_system , total , used , avail , inode_util ):
122122 self .mount = mount
123123 self .file_system = file_system
124124 self .used = used
125125 self .avail = avail
126126 self .util = 100.0 * used / total if total > 0 else 0
127+ self .inode_util = inode_util
127128
128129
129130class Metrics :
@@ -295,13 +296,18 @@ def config_parser():
295296 disk_group .add_argument ('--disk-space-avail' ,
296297 action = 'store_true' ,
297298 help = 'Reports available disk space in gigabytes.' )
299+ disk_group .add_argument ('--disk-inode-util' ,
300+ action = 'store_true' ,
301+ help = 'Reports disk inode utilization in percentages.' )
298302 disk_group .add_argument ('--disk-space-units' ,
299303 metavar = 'UNITS' ,
300304 default = 'gigabytes' ,
301305 type = to_lower ,
302306 choices = size_units ,
303307 help = 'Specifies units for disk space metrics.' )
304308
309+
310+
305311 exclusive_group = parser .add_mutually_exclusive_group ()
306312 exclusive_group .add_argument ('--from-cron' ,
307313 action = 'store_true' ,
@@ -374,7 +380,20 @@ def get_disk_info(paths):
374380 total = int (line [1 ]) * 1024
375381 used = int (line [2 ]) * 1024
376382 avail = int (line [3 ]) * 1024
377- disks .append (Disk (mount , file_system , total , used , avail ))
383+ disks .append (Disk (mount , file_system , total , used , avail , 0 ))
384+
385+ df_inode_out = [s .split () for s in
386+ os .popen ('/bin/df -i -k -P ' +
387+ ' ' .join (paths )).read ().splitlines ()]
388+ disks_inode_util = []
389+ for line in df_inode_out [1 :]:
390+ used = float (line [2 ])
391+ total = float (line [1 ])
392+ inode_util_val = 100.0 * used / total if total > 0 else 0
393+ disks_inode_util .append (inode_util_val )
394+
395+ for index , disk in enumerate (disks ):
396+ disk .inode_util = disks_inode_util [index ]
378397 return disks
379398
380399
@@ -394,6 +413,10 @@ def add_disk_metrics(args, metrics):
394413 metrics .add_metric ('DiskSpaceAvailable' , disk_unit_name ,
395414 disk .avail / disk_unit_div ,
396415 disk .mount , disk .file_system )
416+ if args .disk_inode_util :
417+ metrics .add_metric ('InodeUtilization' , 'Percent' ,
418+ disk .inode_util , disk .mount , disk .file_system )
419+
397420
398421
399422def add_static_file_metrics (args , metrics ):
@@ -433,7 +456,7 @@ def validate_args(args):
433456
434457 if report_disk_data :
435458 if not args .disk_space_util and not args .disk_space_used and \
436- not args .disk_space_avail :
459+ not args .disk_space_avail and not args . disk_inode_util :
437460 raise ValueError ('Disk path is provided but metrics to report '
438461 'disk space are not specified.' )
439462
@@ -442,7 +465,7 @@ def validate_args(args):
442465 raise ValueError ('Disk file path ' + path +
443466 ' does not exist or cannot be accessed.' )
444467 elif args .disk_space_util or args .disk_space_used or \
445- args .disk_space_avail :
468+ args .disk_space_avail or args . disk_inode_util :
446469 raise ValueError ('Metrics to report disk space are provided but '
447470 'disk path is not specified.' )
448471
0 commit comments