Skip to content

Commit e108423

Browse files
authored
Add YANG Model and Configuration Support for Memory Statistics (#20354)
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.
1 parent 9e64ebe commit e108423

File tree

6 files changed

+141
-0
lines changed

6 files changed

+141
-0
lines changed

src/sonic-yang-models/doc/Configuration.md

+20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Table of Contents
5050
* [L2 Neighbors](#l2-neighbors)
5151
* [Loopback Interface](#loopback-interface)
5252
* [LOSSLESS_TRAFFIC_PATTERN](#LOSSLESS_TRAFFIC_PATTERN)
53+
* [Memory Statistics](#memory-statistics)
5354
* [Management Interface](#management-interface)
5455
* [Management port](#management-port)
5556
* [Management VRF](#management-vrf)
@@ -1482,6 +1483,25 @@ lossless traffic for dynamic buffer calculation
14821483
}
14831484
```
14841485

1486+
### Memory Statistics
1487+
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.
1488+
1489+
```
1490+
{
1491+
"MEMORY_STATISTICS": {
1492+
"memory_statistics": {
1493+
"enabled": "false",
1494+
"sampling_interval": "5",
1495+
"retention_period": "15"
1496+
}
1497+
}
1498+
}
1499+
1500+
```
1501+
- **enabled**: Defines whether the memory statistics collection is active (true or false).
1502+
- **sampling_interval**: Interval between data collection.
1503+
- **retention_period**: Time to retain collected data.
1504+
14851505
### Management Interface
14861506

14871507
Management interfaces are defined in **MGMT_INTERFACE** table. Object

src/sonic-yang-models/setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def run(self):
137137
'./yang-models/sonic-kubernetes_master.yang',
138138
'./yang-models/sonic-loopback-interface.yang',
139139
'./yang-models/sonic-lossless-traffic-pattern.yang',
140+
'./yang-models/sonic-memory-statistics.yang',
140141
'./yang-models/sonic-mgmt_interface.yang',
141142
'./yang-models/sonic-mgmt_port.yang',
142143
'./yang-models/sonic-mgmt_vrf.yang',
@@ -242,6 +243,7 @@ def run(self):
242243
'./cvlyang-models/sonic-kubernetes_master.yang',
243244
'./cvlyang-models/sonic-loopback-interface.yang',
244245
'./cvlyang-models/sonic-mgmt_interface.yang',
246+
'./cvlyang-models/sonic-memory-statistics.yang',
245247
'./cvlyang-models/sonic-mgmt_port.yang',
246248
'./cvlyang-models/sonic-mgmt_vrf.yang',
247249
'./cvlyang-models/sonic-ntp.yang',

src/sonic-yang-models/tests/files/sample_config_db.json

+7
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,13 @@
27822782
"motd": "Some message of the day",
27832783
"logout": "Some logout message"
27842784
}
2785+
},
2786+
"MEMORY_STATISTICS": {
2787+
"memory_statistics": {
2788+
"enabled": "false",
2789+
"sampling_interval": "5",
2790+
"retention_period": "15"
2791+
}
27852792
}
27862793
},
27872794
"SAMPLE_CONFIG_DB_UNKNOWN": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"MEMORY_STATISTICS_VALID_CONFIG": {
3+
"desc": "Configuring memory statistics with valid values."
4+
},
5+
"MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": {
6+
"desc": "Configuring memory statistics with an invalid sampling_interval ( out of acceptable range).",
7+
"eStrKey": "Range",
8+
"eStr": "3..15"
9+
},
10+
"MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": {
11+
"desc": "Configuring memory statistics with an invalid retention_period (out of acceptable range).",
12+
"eStrKey": "Range",
13+
"eStr": "1..30"
14+
},
15+
"MEMORY_STATISTICS_WITH_ENABLE_FEATURE": {
16+
"desc": "Enabling memory statistics feature with valid values."
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"MEMORY_STATISTICS_VALID_CONFIG": {
3+
"sonic-memory-statistics:sonic-memory-statistics": {
4+
"sonic-memory-statistics:MEMORY_STATISTICS": {
5+
"memory_statistics":{
6+
"enabled": "false",
7+
"sampling_interval": "5",
8+
"retention_period": "15"
9+
}
10+
}
11+
}
12+
},
13+
"MEMORY_STATISTICS_WITH_INVALID_SAMPLING_INTERVAL": {
14+
"sonic-memory-statistics:sonic-memory-statistics": {
15+
"sonic-memory-statistics:MEMORY_STATISTICS": {
16+
"memory_statistics":{
17+
"enabled": "true",
18+
"sampling_interval": "45",
19+
"retention_period": "20"
20+
}
21+
}
22+
}
23+
},
24+
"MEMORY_STATISTICS_WITH_INVALID_RETENTION_PERIOD": {
25+
"sonic-memory-statistics:sonic-memory-statistics": {
26+
"sonic-memory-statistics:MEMORY_STATISTICS": {
27+
"memory_statistics":{
28+
"enabled": "true",
29+
"sampling_interval": "5",
30+
"retention_period": "45"
31+
}
32+
}
33+
}
34+
},
35+
"MEMORY_STATISTICS_WITH_ENABLE_FEATURE": {
36+
"sonic-memory-statistics:sonic-memory-statistics": {
37+
"sonic-memory-statistics:MEMORY_STATISTICS": {
38+
"memory_statistics":{
39+
"enabled": "true",
40+
"sampling_interval": "5",
41+
"retention_period": "30"
42+
}
43+
}
44+
}
45+
}
46+
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module sonic-memory-statistics {
2+
yang-version 1.1;
3+
4+
namespace "http://github.com/sonic-net/sonic-memory-statistics";
5+
prefix memstats;
6+
7+
import sonic-types {
8+
prefix stypes;
9+
}
10+
11+
description "YANG module for configuring memory statistics in SONiC-based OS.";
12+
13+
revision 2024-07-22 {
14+
description "First Revision";
15+
}
16+
17+
container sonic-memory-statistics {
18+
container MEMORY_STATISTICS {
19+
description "Memory statistics configuration parameters.";
20+
container memory_statistics{
21+
leaf enabled {
22+
type boolean;
23+
default false;
24+
description "Flag to enable or disable memory statistics collection. If set to false, the memory statistics collection will stop.";
25+
}
26+
27+
leaf sampling_interval {
28+
type uint8 {
29+
range "3..15";
30+
}
31+
units "minutes";
32+
default 5;
33+
description "Time interval in minutes for sampling memory statistics. Valid range, is between 3 minutes to 30 minutes.";
34+
}
35+
36+
leaf retention_period {
37+
type uint8 {
38+
range "1..30";
39+
}
40+
units "days";
41+
default 15;
42+
description "Retention period for memory statistics data, defined in days. Valid range is from 1 day to 30 days.";
43+
}
44+
}
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)