swarmauri_tool_psutil 0.6.0.dev154__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_tool_psutil-0.6.0.dev154/PKG-INFO +20 -0
- swarmauri_tool_psutil-0.6.0.dev154/README.md +1 -0
- swarmauri_tool_psutil-0.6.0.dev154/pyproject.toml +56 -0
- swarmauri_tool_psutil-0.6.0.dev154/swarmauri_tool_psutil/PsutilTool.py +130 -0
- swarmauri_tool_psutil-0.6.0.dev154/swarmauri_tool_psutil/__init__.py +15 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: swarmauri_tool_psutil
|
|
3
|
+
Version: 0.6.0.dev154
|
|
4
|
+
Summary: Swarmauri Psutil Tool.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Jacob Stewart
|
|
7
|
+
Author-email: jacob@swarmauri.com
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: psutil (>=6.1.0,<7.0.0)
|
|
15
|
+
Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
|
|
16
|
+
Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
|
|
17
|
+
Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "swarmauri_tool_psutil"
|
|
3
|
+
version = "0.6.0.dev154"
|
|
4
|
+
description = "Swarmauri Psutil Tool."
|
|
5
|
+
authors = ["Jacob Stewart <jacob@swarmauri.com>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"License :: OSI Approved :: Apache Software License",
|
|
11
|
+
"Programming Language :: Python :: 3.10",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool.poetry.dependencies]
|
|
17
|
+
python = ">=3.10,<3.13"
|
|
18
|
+
|
|
19
|
+
# Swarmauri
|
|
20
|
+
swarmauri_core = {version = "^0.6.0.dev154"}
|
|
21
|
+
swarmauri_base = {version = "^0.6.0.dev154"}
|
|
22
|
+
|
|
23
|
+
# Dependencies
|
|
24
|
+
psutil = "^6.1.0"
|
|
25
|
+
|
|
26
|
+
[tool.poetry.group.dev.dependencies]
|
|
27
|
+
flake8 = "^7.0"
|
|
28
|
+
pytest = "^8.0"
|
|
29
|
+
pytest-asyncio = ">=0.24.0"
|
|
30
|
+
pytest-xdist = "^3.6.1"
|
|
31
|
+
pytest-json-report = "^1.5.0"
|
|
32
|
+
python-dotenv = "*"
|
|
33
|
+
requests = "^2.32.3"
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["poetry-core>=1.0.0"]
|
|
37
|
+
build-backend = "poetry.core.masonry.api"
|
|
38
|
+
|
|
39
|
+
[tool.pytest.ini_options]
|
|
40
|
+
norecursedirs = ["combined", "scripts"]
|
|
41
|
+
|
|
42
|
+
markers = [
|
|
43
|
+
"test: standard test",
|
|
44
|
+
"unit: Unit tests",
|
|
45
|
+
"integration: Integration tests",
|
|
46
|
+
"acceptance: Acceptance tests",
|
|
47
|
+
"experimental: Experimental tests"
|
|
48
|
+
]
|
|
49
|
+
log_cli = true
|
|
50
|
+
log_cli_level = "INFO"
|
|
51
|
+
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
52
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
53
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
54
|
+
|
|
55
|
+
[tool.poetry.plugins."swarmauri.tools"]
|
|
56
|
+
PsutilTool = "swarmauri_tool_psutil.PsutilTool:PsutilTool"
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# standard/tools/concrete/PsutilTool.py
|
|
2
|
+
import psutil
|
|
3
|
+
from typing import Dict, Any, Literal, List, Callable
|
|
4
|
+
from swarmauri_core.ComponentBase import ComponentBase
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from swarmauri.tools.base.ToolBase import ToolBase
|
|
7
|
+
from swarmauri.tools.concrete.Parameter import Parameter
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@ComponentBase.register_type(ToolBase, "PsutilTool")
|
|
11
|
+
class PsutilTool(ToolBase):
|
|
12
|
+
type: Literal["PsutilTool"] = "PsutilTool"
|
|
13
|
+
name: str = Field(
|
|
14
|
+
"PsutilTool", description="Tool to gather system information using psutil."
|
|
15
|
+
)
|
|
16
|
+
description: str = Field(
|
|
17
|
+
"This tool gathers system information like CPU, memory, disk, network, and sensors using the psutil library.",
|
|
18
|
+
description="Description of the PsutilTool",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
parameters: List[Parameter] = Field(
|
|
22
|
+
default_factory=lambda: [
|
|
23
|
+
Parameter(
|
|
24
|
+
name="info_type",
|
|
25
|
+
type="string",
|
|
26
|
+
description="Type of system information to retrieve (cpu, memory, disk, network, sensors).",
|
|
27
|
+
required=True,
|
|
28
|
+
)
|
|
29
|
+
]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def get_all_cpu_values(self) -> Dict[str, Any]:
|
|
33
|
+
return {
|
|
34
|
+
"cpu_times": psutil.cpu_times()._asdict(),
|
|
35
|
+
"cpu_percent": psutil.cpu_percent(interval=1),
|
|
36
|
+
"cpu_times_per_cpu": [
|
|
37
|
+
cpu._asdict() for cpu in psutil.cpu_times(percpu=True)
|
|
38
|
+
],
|
|
39
|
+
"cpu_count": psutil.cpu_count(logical=True),
|
|
40
|
+
"cpu_frequency": psutil.cpu_freq()._asdict(),
|
|
41
|
+
"cpu_stats": psutil.cpu_stats()._asdict(),
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
def get_all_memory_values(self) -> Dict[str, Any]:
|
|
45
|
+
return {
|
|
46
|
+
"virtual_memory": psutil.virtual_memory()._asdict(),
|
|
47
|
+
"swap_memory": psutil.swap_memory()._asdict(),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
def get_all_disk_values(self) -> Dict[str, Any]:
|
|
51
|
+
partitions = psutil.disk_partitions()
|
|
52
|
+
disk_usage = {
|
|
53
|
+
partition.device: psutil.disk_usage(partition.mountpoint)._asdict()
|
|
54
|
+
for partition in partitions
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
"disk_partitions": [partition._asdict() for partition in partitions],
|
|
58
|
+
"disk_usage": disk_usage,
|
|
59
|
+
"disk_io_counters": psutil.disk_io_counters()._asdict(),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
def get_all_network_values(self) -> Dict[str, Any]:
|
|
63
|
+
return {
|
|
64
|
+
"network_io_counters": psutil.net_io_counters()._asdict(),
|
|
65
|
+
"network_connections": [
|
|
66
|
+
conn._asdict() for conn in psutil.net_connections()
|
|
67
|
+
],
|
|
68
|
+
"network_interfaces": {
|
|
69
|
+
iface: [addr._asdict() for addr in addrs]
|
|
70
|
+
for iface, addrs in psutil.net_if_addrs().items()
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
def get_all_sensors_values(self) -> Dict[str, Any]:
|
|
75
|
+
battery = psutil.sensors_battery()
|
|
76
|
+
temperatures = psutil.sensors_temperatures()
|
|
77
|
+
fans = psutil.sensors_fans()
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
"battery": battery._asdict() if battery else None,
|
|
81
|
+
"temperatures": {
|
|
82
|
+
name: [temp._asdict() for temp in temps]
|
|
83
|
+
for name, temps in (temperatures or {}).items()
|
|
84
|
+
},
|
|
85
|
+
"fan_speeds": {
|
|
86
|
+
name: [fan._asdict() for fan in fans]
|
|
87
|
+
for name, fans in (fans or {}).items()
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
def __call__(self, info_type: str) -> Dict[str, Any]:
|
|
92
|
+
"""
|
|
93
|
+
Call the appropriate method based on the provided info_type and return the corresponding system information.
|
|
94
|
+
|
|
95
|
+
Parameters:
|
|
96
|
+
info_type (str): The type of system information requested. Valid options are 'cpu', 'memory', 'disk',
|
|
97
|
+
'network', or 'sensors'.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Dict[str, Any]: A dictionary where the key is the `info_type` and the value is the result of the corresponding
|
|
101
|
+
system information retrieval method.
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
ValueError: If an invalid `info_type` is provided.
|
|
105
|
+
|
|
106
|
+
Example:
|
|
107
|
+
>>> tool = YourToolClass()
|
|
108
|
+
>>> result = tool("cpu")
|
|
109
|
+
>>> print(result)
|
|
110
|
+
{'cpu': {...}}
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
# Mapping info_type values to the corresponding methods
|
|
114
|
+
info_methods: Dict[str, Callable[[], Any]] = {
|
|
115
|
+
"cpu": self.get_all_cpu_values,
|
|
116
|
+
"memory": self.get_all_memory_values,
|
|
117
|
+
"disk": self.get_all_disk_values,
|
|
118
|
+
"network": self.get_all_network_values,
|
|
119
|
+
"sensors": self.get_all_sensors_values,
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
# Retrieve the appropriate method or raise an error if invalid info_type is provided
|
|
123
|
+
if info_type not in info_methods:
|
|
124
|
+
raise ValueError(
|
|
125
|
+
f"Invalid info_type '{info_type}' specified. Valid options are: {list(info_methods.keys())}."
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Execute the corresponding method and return the result
|
|
129
|
+
result = info_methods[info_type]()
|
|
130
|
+
return result
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .PsutilTool import PsutilTool
|
|
2
|
+
__version__ = "0.6.0.dev26"
|
|
3
|
+
__long_desc__ = """
|
|
4
|
+
|
|
5
|
+
# Swarmauri Psutil Plugin
|
|
6
|
+
|
|
7
|
+
This repository includes a Psutil of a Swarmauri Plugin.
|
|
8
|
+
|
|
9
|
+
Visit us at: https://swarmauri.com
|
|
10
|
+
Follow us at: https://github.com/swarmauri
|
|
11
|
+
Star us at: https://github.com/swarmauri/swarmauri-sdk
|
|
12
|
+
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|