Skip to content

Commit

Permalink
Add YANG Model and Configuration Support for Memory Statistics (#20354)
Browse files Browse the repository at this point in the history
This PR introduces a new YANG model for configuring memory statistics in SONiC, along with necessary updates to the configuration database and test cases. The following changes have been made:

YANG Model:

Created a new YANG module sonic-memory-statistics.yang for managing memory statistics configuration parameters, including:
enabled: Boolean flag to enable or disable memory statistics collection.
sampling_interval: Configurable time interval for sampling memory statistics.
retention_period: Configurable retention period for memory statistics data.
Configuration Database:

Updated sample_config_db.json to include default values for the memory statistics configuration, ensuring seamless integration with the existing configuration management.
Test Cases:

Added comprehensive test cases in memory_statistics.json to validate the configuration parameters, including valid configurations and error scenarios for invalid sampling intervals and retention periods.
These changes aim to enhance the monitoring capabilities of SONiC by providing a structured way to configure memory statistics, thereby improving overall system performance and resource management.
  • Loading branch information
Arham-Nasir authored Dec 3, 2024
1 parent 9e64ebe commit e108423
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/sonic-yang-models/doc/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Table of Contents
* [L2 Neighbors](#l2-neighbors)
* [Loopback Interface](#loopback-interface)
* [LOSSLESS_TRAFFIC_PATTERN](#LOSSLESS_TRAFFIC_PATTERN)
* [Memory Statistics](#memory-statistics)
* [Management Interface](#management-interface)
* [Management port](#management-port)
* [Management VRF](#management-vrf)
Expand Down Expand Up @@ -1482,6 +1483,25 @@ lossless traffic for dynamic buffer calculation
}
```

### Memory Statistics
The memory statistics configuration is stored in the **MEMORY_STATISTICS** table. This table is used by the memory statistics daemon to manage memory monitoring settings. The configuration allows enabling or disabling memory collection, specifying how frequently memory statistics are sampled, and defining how long the memory data is retained.

```
{
"MEMORY_STATISTICS": {
"memory_statistics": {
"enabled": "false",
"sampling_interval": "5",
"retention_period": "15"
}
}
}

```
- **enabled**: Defines whether the memory statistics collection is active (true or false).
- **sampling_interval**: Interval between data collection.
- **retention_period**: Time to retain collected data.

### Management Interface

Management interfaces are defined in **MGMT_INTERFACE** table. Object
Expand Down
2 changes: 2 additions & 0 deletions src/sonic-yang-models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def run(self):
'./yang-models/sonic-kubernetes_master.yang',
'./yang-models/sonic-loopback-interface.yang',
'./yang-models/sonic-lossless-traffic-pattern.yang',
'./yang-models/sonic-memory-statistics.yang',
'./yang-models/sonic-mgmt_interface.yang',
'./yang-models/sonic-mgmt_port.yang',
'./yang-models/sonic-mgmt_vrf.yang',
Expand Down Expand Up @@ -242,6 +243,7 @@ def run(self):
'./cvlyang-models/sonic-kubernetes_master.yang',
'./cvlyang-models/sonic-loopback-interface.yang',
'./cvlyang-models/sonic-mgmt_interface.yang',
'./cvlyang-models/sonic-memory-statistics.yang',
'./cvlyang-models/sonic-mgmt_port.yang',
'./cvlyang-models/sonic-mgmt_vrf.yang',
'./cvlyang-models/sonic-ntp.yang',
Expand Down
7 changes: 7 additions & 0 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,13 @@
"motd": "Some message of the day",
"logout": "Some logout message"
}
},
"MEMORY_STATISTICS": {
"memory_statistics": {
"enabled": "false",
"sampling_interval": "5",
"retention_period": "15"
}
}
},
"SAMPLE_CONFIG_DB_UNKNOWN": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"MEMORY_STATISTICS_VALID_CONFIG": {
"desc": "Configuring memory statistics with valid values."
},
"MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": {
"desc": "Configuring memory statistics with an invalid sampling_interval ( out of acceptable range).",
"eStrKey": "Range",
"eStr": "3..15"
},
"MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": {
"desc": "Configuring memory statistics with an invalid retention_period (out of acceptable range).",
"eStrKey": "Range",
"eStr": "1..30"
},
"MEMORY_STATISTICS_WITH_ENABLE_FEATURE": {
"desc": "Enabling memory statistics feature with valid values."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"MEMORY_STATISTICS_VALID_CONFIG": {
"sonic-memory-statistics:sonic-memory-statistics": {
"sonic-memory-statistics:MEMORY_STATISTICS": {
"memory_statistics":{
"enabled": "false",
"sampling_interval": "5",
"retention_period": "15"
}
}
}
},
"MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": {
"sonic-memory-statistics:sonic-memory-statistics": {
"sonic-memory-statistics:MEMORY_STATISTICS": {
"memory_statistics":{
"enabled": "true",
"sampling_interval": "45",
"retention_period": "20"
}
}
}
},
"MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": {
"sonic-memory-statistics:sonic-memory-statistics": {
"sonic-memory-statistics:MEMORY_STATISTICS": {
"memory_statistics":{
"enabled": "true",
"sampling_interval": "5",
"retention_period": "45"
}
}
}
},
"MEMORY_STATISTICS_WITH_ENABLE_FEATURE": {
"sonic-memory-statistics:sonic-memory-statistics": {
"sonic-memory-statistics:MEMORY_STATISTICS": {
"memory_statistics":{
"enabled": "true",
"sampling_interval": "5",
"retention_period": "30"
}
}
}
}

}
47 changes: 47 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-memory-statistics.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module sonic-memory-statistics {
yang-version 1.1;

namespace "http://github.com/sonic-net/sonic-memory-statistics";
prefix memstats;

import sonic-types {
prefix stypes;
}

description "YANG module for configuring memory statistics in SONiC-based OS.";

revision 2024-07-22 {
description "First Revision";
}

container sonic-memory-statistics {
container MEMORY_STATISTICS {
description "Memory statistics configuration parameters.";
container memory_statistics{
leaf enabled {
type boolean;
default false;
description "Flag to enable or disable memory statistics collection. If set to false, the memory statistics collection will stop.";
}

leaf sampling_interval {
type uint8 {
range "3..15";
}
units "minutes";
default 5;
description "Time interval in minutes for sampling memory statistics. Valid range, is between 3 minutes to 30 minutes.";
}

leaf retention_period {
type uint8 {
range "1..30";
}
units "days";
default 15;
description "Retention period for memory statistics data, defined in days. Valid range is from 1 day to 30 days.";
}
}
}
}
}

0 comments on commit e108423

Please sign in to comment.