Skip to content

Commit e19398c

Browse files
committed
added sysctl plugin, collection only
1 parent 3efa92c commit e19398c

File tree

6 files changed

+325
-0
lines changed

6 files changed

+325
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from .analyzer_args import SysctlAnalyzerArgs
27+
from .sysctl_plugin import SysctlPlugin
28+
29+
__all__ = ["SysctlPlugin", "SysctlAnalyzerArgs"]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from typing import Optional
27+
28+
from nodescraper.models import AnalyzerArgs
29+
from nodescraper.plugins.inband.sysctl.sysctldata import SysctlDataModel
30+
31+
32+
class SysctlAnalyzerArgs(AnalyzerArgs):
33+
exp_vm_swappiness: Optional[int] = None
34+
exp_vm_numa_balancing: Optional[int] = None
35+
exp_vm_oom_kill_allocating_task: Optional[int] = None
36+
exp_vm_compaction_proactiveness: Optional[int] = None
37+
exp_vm_compact_unevictable_allowed: Optional[int] = None
38+
exp_vm_extfrag_threshold: Optional[int] = None
39+
exp_vm_zone_reclaim_mode: Optional[int] = None
40+
exp_vm_dirty_background_ratio: Optional[int] = None
41+
exp_vm_dirty_ratio: Optional[int] = None
42+
exp_vm_dirty_writeback_centisecs: Optional[int] = None
43+
exp_kernel_numa_balancing: Optional[int] = None
44+
45+
@classmethod
46+
def build_from_model(cls, datamodel: SysctlDataModel) -> "SysctlAnalyzerArgs":
47+
"""build analyzer args from data model
48+
49+
Args:
50+
datamodel (SysctlDataModel): data model for plugin
51+
52+
Returns:
53+
SysctlAnalyzerArgs: instance of analyzer args class
54+
"""
55+
return cls(exp_vm_swappiness=datamodel.vm_swappiness)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
27+
from typing import Optional
28+
29+
from nodescraper.interfaces import DataAnalyzer
30+
from nodescraper.models import TaskResult
31+
32+
from .analyzer_args import SysctlAnalyzerArgs
33+
from .sysctldata import SysctlDataModel
34+
35+
36+
class SysctlAnalyzer(DataAnalyzer[SysctlDataModel, SysctlAnalyzerArgs]):
37+
"""Check sysctl matches expected sysctl details"""
38+
39+
DATA_MODEL = SysctlDataModel
40+
41+
def analyze_data(
42+
self, data: SysctlDataModel, args: Optional[SysctlAnalyzerArgs] = None
43+
) -> TaskResult:
44+
"""Analyze the Sysctl data against expected Sysctl versions.
45+
46+
Args:
47+
data (SysctlDataModel): The Sysctl data to analyze.
48+
args (Optional[SysctlAnalyzerArgs], optional): Expected Sysctl data. Defaults to None.
49+
50+
Returns:
51+
TaskResult: The result of the analysis, indicating whether the Sysctl data matches
52+
the expected versions or not.
53+
"""
54+
55+
if not args:
56+
args = SysctlAnalyzerArgs()
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
27+
from nodescraper.base import InBandDataCollector
28+
from nodescraper.enums import EventCategory, EventPriority, ExecutionStatus, OSFamily
29+
from nodescraper.models import TaskResult
30+
31+
from .sysctldata import SysctlDataModel
32+
33+
34+
class SysctlCollector(InBandDataCollector[SysctlDataModel, None]):
35+
"""Collect sysctl kernel VM settings."""
36+
37+
DATA_MODEL = SysctlDataModel
38+
39+
def collect_data(
40+
self,
41+
args=None,
42+
) -> tuple[TaskResult, SysctlDataModel | None]:
43+
"""Collect sysctl VM tuning values from the system."""
44+
values = {}
45+
46+
if self.system_info.os_family == OSFamily.WINDOWS:
47+
self._log_event(
48+
category=EventCategory.OS,
49+
description="Windows is not supported for sysctl collection.",
50+
priority=EventPriority.WARNING,
51+
console_log=True,
52+
)
53+
return self.result, None
54+
55+
for field_name in SysctlDataModel.model_fields:
56+
sysctl_key = field_name.replace("_", ".", 1)
57+
res = self._run_sut_cmd(f"sysctl -n {sysctl_key}")
58+
59+
if res.exit_code == 0:
60+
try:
61+
values[field_name] = int(res.stdout.strip())
62+
except ValueError:
63+
self._log_event(
64+
category=EventCategory.OS,
65+
description=f"Invalid integer value for {sysctl_key}",
66+
data={"stdout": res.stdout},
67+
priority=EventPriority.ERROR,
68+
console_log=True,
69+
)
70+
else:
71+
self._log_event(
72+
category=EventCategory.OS,
73+
description=f"Error checking Linux system setting : {sysctl_key}",
74+
data={"system_setting": sysctl_key, "exit_code": res.exit_code},
75+
priority=EventPriority.WARNING,
76+
console_log=True,
77+
)
78+
79+
if values:
80+
sysctl_data = SysctlDataModel(**values)
81+
self._log_event(
82+
category="SYSCTL_READ",
83+
description="Sysctl settings read",
84+
data=sysctl_data.model_dump(),
85+
priority=EventPriority.INFO,
86+
)
87+
self.result.message = "SYSCTL data collected"
88+
self.result.status = ExecutionStatus.OK
89+
else:
90+
sysctl_data = None
91+
self._log_event(
92+
category=EventCategory.OS,
93+
description="Sysctl settings not read",
94+
priority=EventPriority.CRITICAL,
95+
console_log=True,
96+
)
97+
self.result.message = "Sysctl settings not read"
98+
self.result.status = ExecutionStatus.ERROR
99+
100+
return self.result, sysctl_data
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from nodescraper.base import InBandDataPlugin
27+
28+
from .analyzer_args import SysctlAnalyzerArgs
29+
from .sysctl_analyzer import SysctlAnalyzer
30+
from .sysctl_collector import SysctlCollector
31+
from .sysctldata import SysctlDataModel
32+
33+
34+
class SysctlPlugin(InBandDataPlugin[SysctlDataModel, None, SysctlAnalyzerArgs]):
35+
"""Plugin for collection and analysis of BIOS data"""
36+
37+
DATA_MODEL = SysctlDataModel
38+
39+
COLLECTOR = SysctlCollector
40+
41+
ANALYZER = SysctlAnalyzer
42+
43+
ANALYZER_ARGS = SysctlAnalyzerArgs
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
###############################################################################
2+
#
3+
# MIT License
4+
#
5+
# Copyright (c) 2025 Advanced Micro Devices, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in all
15+
# copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
# SOFTWARE.
24+
#
25+
###############################################################################
26+
from typing import Optional
27+
28+
from nodescraper.models import DataModel
29+
30+
31+
class SysctlDataModel(DataModel):
32+
vm_swappiness: Optional[int] = None
33+
vm_numa_balancing: Optional[int] = None
34+
vm_oom_kill_allocating_task: Optional[int] = None
35+
vm_compaction_proactiveness: Optional[int] = None
36+
vm_compact_unevictable_allowed: Optional[int] = None
37+
vm_extfrag_threshold: Optional[int] = None
38+
vm_zone_reclaim_mode: Optional[int] = None
39+
vm_dirty_background_ratio: Optional[int] = None
40+
vm_dirty_ratio: Optional[int] = None
41+
vm_dirty_writeback_centisecs: Optional[int] = None
42+
kernel_numa_balancing: Optional[int] = None

0 commit comments

Comments
 (0)