-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-132548 / 25.04 / Add NVME plugin (#248)
* smartctl -a is legacy, use -x * remove unnecessary comment * add NVME plugin * prettify the header
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import re | ||
from typing import Any | ||
|
||
from .base import Plugin | ||
from .metrics import CommandMetric, PythonMetric | ||
from ixdiagnose.utils.command import Command | ||
from ixdiagnose.utils.middleware import MiddlewareClient | ||
from ixdiagnose.utils.run import run | ||
|
||
NVME_RE = re.compile(r"^nvme\dn\d+$") | ||
|
||
|
||
def get_nvme_devs() -> list[str]: | ||
nvmes = list() | ||
with os.scandir("/dev/") as sdir: | ||
for i in filter(lambda x: NVME_RE.match(x.name), sdir): | ||
nvmes.append(i.path) | ||
return nvmes | ||
|
||
|
||
def run_nvme_cmd(action: str, nvme: str, add_header: bool = True) -> str: | ||
header = '' if not add_header else f'{nvme:#^30}\n' | ||
cp = run(["nvme", action, nvme], check=False) | ||
if cp.returncode: | ||
footer = f"FAILED: {cp.stderr}\n\n" | ||
else: | ||
footer = cp.stdout + "\n\n" | ||
|
||
return header + footer | ||
|
||
|
||
def get_nvme_id_ctrl(client: MiddlewareClient, context: Any) -> str: | ||
output = "" | ||
for nvme in get_nvme_devs(): | ||
output += run_nvme_cmd("id-ctrl", nvme) | ||
return output | ||
|
||
|
||
def get_nvme_id_ns(client: MiddlewareClient, context: Any) -> str: | ||
output = "" | ||
for nvme in get_nvme_devs(): | ||
output += run_nvme_cmd("id-ns", nvme) | ||
return output | ||
|
||
|
||
def get_nvme_smart_log(client: MiddlewareClient, context: Any) -> str: | ||
output = "" | ||
for nvme in get_nvme_devs(): | ||
output += run_nvme_cmd("smart-log", nvme, add_header=False) | ||
return output | ||
|
||
|
||
class NVME(Plugin): | ||
name = "nvme" | ||
metrics = [ | ||
CommandMetric( | ||
"nvme_list_v", | ||
[ | ||
Command(["nvme", "list", "-v"], "nvme list -v", serializable=False), | ||
], | ||
), | ||
CommandMetric( | ||
"nvme_discover", | ||
[ | ||
Command(["nvme", "discover"], "nvme discover", serializable=False), | ||
], | ||
), | ||
PythonMetric( | ||
"nvme_id_ctrl", | ||
callback=get_nvme_id_ctrl, | ||
description="Identify Controller", | ||
serializable=False, | ||
), | ||
PythonMetric( | ||
"nvme_id_ns", | ||
callback=get_nvme_id_ns, | ||
description="Identify Namespace", | ||
serializable=False, | ||
), | ||
PythonMetric( | ||
"nvme_smart_log", | ||
callback=get_nvme_smart_log, | ||
description="SMART Log", | ||
serializable=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters