@@ -1694,85 +1694,37 @@ class FipsCfg(object):
1694
1694
syslog .syslog (syslog .LOG_INFO , f'FipsCfg: update the FIPS enforce option { self .enforce } .' )
1695
1695
loader .set_fips (image , self .enforce )
1696
1696
1697
- class Memory_StatisticsCfg (object ):
1698
- """
1699
- Memory Stats Config Daemon
1700
- Handles changes in MEMORY_STATS table.
1701
- 1) Handle enabling or disabling the feature
1702
- 2) Handle change of retention period
1703
- 3) Handle change of sampling interval
1704
- """
1705
-
1706
- def __init__ (self , config_db ):
1707
- self .config_db = config_db
1708
- self .cache = {}
1709
- self .memory_statistics_defaults = {
1710
- "enabled" : "false" ,
1711
- "retention_time" : "15 days" ,
1712
- "sampling_interval" : "5 minutes"
1713
- }
1714
-
1715
- def load (self , memory_stats_config : dict ):
1716
- """
1717
- Load memory statistics configuration when the daemon starts.
1718
- Args:
1719
- memory_stats_config: Configured memory statistics settings.
1720
- """
1721
- syslog .syslog (syslog .LOG_INFO , "Memory_StatisticsCfg init ..." )
1722
- memory_statistics_conf = memory_stats_config .get ("config" , {})
1723
-
1724
- # Apply default configurations if not present
1725
- for row , value in self .memory_statistics_defaults .items ():
1726
- if not memory_statistics_conf .get (row ):
1727
- self .config_db .mod_entry ("MEMORY_STATISTICS" , "config" , {row : value })
1728
-
1729
- # Apply configurations to ensure they are set correctly on startup
1730
- self .apply_configuration (memory_statistics_conf )
1697
+ class Memory_StatisticsCfg :
1698
+ def __init__ (self ):
1699
+ pass
1731
1700
1732
- def apply_configuration (self , config ):
1733
- """
1734
- Apply the memory statistics configuration settings.
1735
- Args:
1736
- config: Configuration data for memory statistics.
1737
- """
1738
- # Determine if the feature is enabled or disabled
1739
- enabled = config .get ("enabled" , self .memory_statistics_defaults ["enabled" ]).lower () == "true"
1740
- retention_time = config .get ("retention_time" , self .memory_statistics_defaults ["retention_time" ])
1741
- sampling_interval = config .get ("sampling_interval" , self .memory_statistics_defaults ["sampling_interval" ])
1742
-
1743
- # Enable or disable memory statistics
1744
- if enabled :
1745
- self .run_cmd (["sonic-memory_statistics-config" , "--enable" ])
1701
+ def apply_configuration (self , config_data ):
1702
+ enabled = config_data .get ('enabled' , 'false' )
1703
+ retention_time = config_data .get ('retention_time' , '30 days' )
1704
+ sampling_interval = config_data .get ('sampling_interval' , '10 minutes' )
1705
+
1706
+ cmd = ["sonic-memory_statistics-config" ]
1707
+ if enabled .lower () == 'true' :
1708
+ cmd .append ("--enable" )
1746
1709
else :
1747
- self .run_cmd (["sonic-memory_statistics-config" , "--disable" ])
1748
-
1749
- # Set retention time and sampling interval
1750
- self .run_cmd (["sonic-memory_statistics-config" , "--retention_time" , retention_time ])
1751
- self .run_cmd (["sonic-memory_statistics-config" , "--sampling_interval" , sampling_interval ])
1752
-
1753
- def memory_statistics_update (self , key , data ):
1754
- """
1755
- Handle updates to the memory statistics configuration.
1756
- Args:
1757
- key: Key identifying the config type.
1758
- data: Updated configuration data.
1759
- """
1760
- syslog .syslog (syslog .LOG_INFO , "Memory_Statistics global configuration update" )
1761
- if key == "config" :
1762
- self .apply_configuration (data )
1710
+ cmd .append ("--disable" )
1711
+
1712
+ if retention_time :
1713
+ cmd .extend (["--retention-time" , retention_time ])
1714
+ if sampling_interval :
1715
+ cmd .extend (["--sampling-interval" , sampling_interval ])
1716
+
1717
+ self .run_cmd (cmd )
1763
1718
1764
1719
def run_cmd (self , cmd ):
1765
- """
1766
- Execute a shell command and return the output.
1767
- Args:
1768
- cmd: List of command arguments.
1769
- """
1770
1720
try :
1771
1721
output = subprocess .check_output (cmd , stderr = subprocess .STDOUT )
1772
1722
syslog .syslog (syslog .LOG_INFO , output .decode ('utf-8' ))
1773
1723
except subprocess .CalledProcessError as e :
1774
- syslog .syslog (syslog .LOG_ERR , e .output .decode ('utf-8' ))
1775
-
1724
+ syslog .syslog (syslog .LOG_ERR , f"Command failed with error: { e .output .decode ('utf-8' )} " )
1725
+ except Exception as e :
1726
+ syslog .syslog (syslog .LOG_ERR , f"An unexpected error occurred: { str (e )} " )
1727
+
1776
1728
class HostConfigDaemon :
1777
1729
def __init__ (self ):
1778
1730
self .state_db_conn = DBConnector (STATE_DB , 0 )
0 commit comments