@@ -105,6 +105,9 @@ def health_status_to_number(status: str) -> int:
105105
106106NUM_OBJECTS = ['degraded' , 'misplaced' , 'unfound' ]
107107
108+ SMB_METADATA = ('smb_version' , 'volume' ,
109+ 'subvolume_group' , 'subvolume' , 'netbiosname' )
110+
108111alert_metric = namedtuple ('alert_metric' , 'name description' )
109112HEALTH_CHECKS = [
110113 alert_metric ('SLOW_OPS' , 'OSD or Monitor requests taking a long time to process' ),
@@ -768,6 +771,13 @@ def _setup_static_metrics(self) -> Dict[str, Metric]:
768771 ('type' , 'ceph_daemon' ,)
769772 )
770773
774+ metrics ['smb_metadata' ] = Metric (
775+ 'untyped' ,
776+ 'smb_metadata' ,
777+ 'SMB Metadata' ,
778+ SMB_METADATA
779+ )
780+
771781 for flag in OSD_FLAGS :
772782 path = 'osd_flag_{}' .format (flag )
773783 metrics [path ] = Metric (
@@ -1700,6 +1710,66 @@ def get_perf_counters(self) -> None:
17001710 self .metrics [path ].set (value , labels )
17011711 self .add_fixed_name_metrics ()
17021712
1713+ @profile_method ()
1714+ def get_smb_metadata (self ) -> None :
1715+ try :
1716+ mgr_map = self .get ('mgr_map' )
1717+ available_modules = [m ['name' ] for m in mgr_map ['available_modules' ]]
1718+ if 'smb' not in available_modules :
1719+ self .log .debug ("SMB module is not available, skipping SMB metadata collection" )
1720+ return
1721+
1722+ if not self .available ()[0 ]:
1723+ self .log .debug ("Orchestrator not available" )
1724+ return
1725+
1726+ smb_version = ""
1727+
1728+ try :
1729+ daemons = raise_if_exception (self .list_daemons (daemon_type = 'smb' ))
1730+ if daemons :
1731+ smb_version = str (daemons [0 ].version )
1732+ except Exception as e :
1733+ self .log .error (f"Failed to get SMB daemons: { str (e )} " )
1734+ return
1735+
1736+ ret , out , err = self .mon_command ({
1737+ 'prefix' : 'smb show' ,
1738+ 'format' : 'json'
1739+ })
1740+ if ret != 0 :
1741+ self .log .error (f"Failed to get SMB info: { err } " )
1742+ return
1743+
1744+ try :
1745+ smb_data = json .loads (out )
1746+
1747+ for resource in smb_data .get ('resources' , []):
1748+ if resource .get ('resource_type' ) == 'ceph.smb.share' :
1749+ self .log .info ("Processing SMB share resource" )
1750+ cluster_id = resource .get ('cluster_id' )
1751+ if not cluster_id :
1752+ self .log .debug ("Skipping share with missing cluster_id" )
1753+ continue
1754+
1755+ cephfs = resource .get ('cephfs' , {})
1756+ cephfs_volume = cephfs .get ('volume' , '' )
1757+ cephfs_subvolumegroup = cephfs .get ('subvolumegroup' , '_nogroup' )
1758+ cephfs_subvolume = cephfs .get ('subvolume' , '' )
1759+ self .metrics ['smb_metadata' ].set (1 , (
1760+ smb_version ,
1761+ cephfs_volume ,
1762+ cephfs_subvolumegroup ,
1763+ cephfs_subvolume ,
1764+ cluster_id
1765+ ))
1766+ except json .JSONDecodeError :
1767+ self .log .error ("Failed to decode SMB module output" )
1768+ except Exception as e :
1769+ self .log .error (f"Error processing SMB metadata: { str (e )} " )
1770+ except Exception as e :
1771+ self .log .error (f"Failed to get SMB metadata: { str (e )} " )
1772+
17031773 @profile_method (True )
17041774 def collect (self ) -> str :
17051775 # Clear the metrics before scraping
@@ -1719,6 +1789,7 @@ def collect(self) -> str:
17191789 self .get_pool_repaired_objects ()
17201790 self .get_num_objects ()
17211791 self .get_all_daemon_health_metrics ()
1792+ self .get_smb_metadata ()
17221793
17231794 if not self .get_module_option ('exclude_perf_counters' ):
17241795 self .get_perf_counters ()
0 commit comments