@@ -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 :
@@ -301,6 +302,10 @@ def config_parser():
301302 type = to_lower ,
302303 choices = size_units ,
303304 help = 'Specifies units for disk space metrics.' )
305+ disk_group .add_argument ('--disk-inode-util' ,
306+ action = 'store_true' ,
307+ help = 'Reports disk inode utilization in percentages.' )
308+
304309
305310 exclusive_group = parser .add_mutually_exclusive_group ()
306311 exclusive_group .add_argument ('--from-cron' ,
@@ -363,7 +368,8 @@ def add_loadavg_metrics(args, metrics):
363368 metrics .add_metric ('LoadAvgPerCPU15Min' , None , loadavg .loadavg_percpu_15min )
364369
365370
366- def get_disk_info (paths ):
371+ def get_disk_info (args ):
372+ paths = args .disk_path
367373 df_out = [s .split () for s in
368374 os .popen ('/bin/df -k -P ' +
369375 ' ' .join (paths )).read ().splitlines ()]
@@ -374,14 +380,31 @@ 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+ #Gather inode utilization if it is requested
386+ if not args .disk_inode_util :
387+ return disks
388+
389+ df_inode_out = [s .split () for s in
390+ os .popen ('/bin/df -i -k -P ' +
391+ ' ' .join (paths )).read ().splitlines ()]
392+ disks_inode_util = []
393+ for line in df_inode_out [1 :]:
394+ used = float (line [2 ])
395+ total = float (line [1 ])
396+ inode_util_val = 100.0 * used / total if total > 0 else 0
397+ disks_inode_util .append (inode_util_val )
398+
399+ for index , disk in enumerate (disks ):
400+ disk .inode_util = disks_inode_util [index ]
378401 return disks
379402
380403
381404def add_disk_metrics (args , metrics ):
382405 disk_unit_name = SIZE_UNITS_CFG [args .disk_space_units ]['name' ]
383406 disk_unit_div = float (SIZE_UNITS_CFG [args .disk_space_units ]['div' ])
384- disks = get_disk_info (args . disk_path )
407+ disks = get_disk_info (args )
385408 for disk in disks :
386409 if args .disk_space_util :
387410 metrics .add_metric ('DiskSpaceUtilization' , 'Percent' ,
@@ -394,6 +417,10 @@ def add_disk_metrics(args, metrics):
394417 metrics .add_metric ('DiskSpaceAvailable' , disk_unit_name ,
395418 disk .avail / disk_unit_div ,
396419 disk .mount , disk .file_system )
420+ if args .disk_inode_util :
421+ metrics .add_metric ('InodeUtilization' , 'Percent' ,
422+ disk .inode_util , disk .mount , disk .file_system )
423+
397424
398425
399426def add_static_file_metrics (args , metrics ):
@@ -433,7 +460,7 @@ def validate_args(args):
433460
434461 if report_disk_data :
435462 if not args .disk_space_util and not args .disk_space_used and \
436- not args .disk_space_avail :
463+ not args .disk_space_avail and not args . disk_inode_util :
437464 raise ValueError ('Disk path is provided but metrics to report '
438465 'disk space are not specified.' )
439466
@@ -442,7 +469,7 @@ def validate_args(args):
442469 raise ValueError ('Disk file path ' + path +
443470 ' does not exist or cannot be accessed.' )
444471 elif args .disk_space_util or args .disk_space_used or \
445- args .disk_space_avail :
472+ args .disk_space_avail or args . disk_inode_util :
446473 raise ValueError ('Metrics to report disk space are provided but '
447474 'disk path is not specified.' )
448475
0 commit comments