-
Notifications
You must be signed in to change notification settings - Fork 11
Feature harddrives #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Updated subprocess to use popen included Hard drive functions, as well as status scoring for sata and nvme
Added new exception for paths not used.
Removed enum harddrive status Fixed attributes issue if 0
Moved scoring function to two parts to add score as an attribute.
miaucl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a clean PR, please add instructions to the Readme.md.
- What is the frequency you are planning to run this?
- Fix the "conflicts"
- Cleanup unused code as good as possibe (comments are not a problem, but unused code lines are confusing)
Otherwise, I really like this extension and will test it as soon as it is in a clean state and I can run the workflows.
Thanks already @bimal12
linux2mqtt/linux2mqtt.py
Outdated
| main_logger = logging.getLogger("main") | ||
| mqtt_logger = logging.getLogger("mqtt") | ||
|
|
||
| logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the same logging system as already present or create a new logger if you need one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this line, I use specific purpose loggers and do not want to pollute the default logging config as library.
See following code:
def configure_logger(
logger: logging.Logger, verbosity: int, logdir: str | None
) -> None:
"""Configure main logger.
Parameters
----------
logger
The logger to configure
verbosity
The verbosity level
logdir
The log directory
"""
if verbosity >= 5:
logger.setLevel(logging.DEBUG)
elif verbosity == 4:
logger.setLevel(logging.INFO)
elif verbosity == 3:
logger.setLevel(logging.WARNING)
elif verbosity == 2:
logger.setLevel(logging.ERROR)
elif verbosity == 1:
logger.setLevel(logging.CRITICAL)
# Configure logger
logger.propagate = False
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
formatter = logging.Formatter(log_format)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
if logdir:
try:
logdirpath = Path(logdir)
absolute_logdir = (
logdirpath.resolve() if not logdirpath.is_absolute() else logdirpath
)
absolute_logdir.mkdir(parents=True, exist_ok=True)
log_file = path.join(absolute_logdir, f"linux2mqtt-{logger.name}.log")
file_handler = RotatingFileHandler(
log_file, maxBytes=1_000_000, backupCount=5
)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
except Exception as ex:
logger.warning(
"Failed to initialize logging to directory %s : %s",
logdir,
str(ex),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I removed the line, and pulled in the updated loggers.
linux2mqtt/metrics.py
Outdated
| self.metric.polled_result = { | ||
| **self.harddrive.attributes, # type: ignore[unused-ignore] | ||
| } | ||
| # self.metric._name = self.harddrive.attributes['model_name'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded?
| def get_score(self): | ||
| score = 0 | ||
|
|
||
| # Critical warnings (bitmask) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your scoring based on? Is it an official baseline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just an arbitrary scoring metric that I put together to assist with monitoring drive health.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, in that case it would be helpful to document it somewhere for users to understand :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this into the readme now.
linux2mqtt/harddrive.py
Outdated
|
|
||
| ata_regex = "^ata.*(?<!part\d)$" | ||
| nvme_regex = "^nvme-eui.*(?<!part\d)$" | ||
| # potential_disks = os.listdir("/dev/disk/by-id/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unneeded?
miaucl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks better already, still some points open but workflows are already happy :)
|
|
||
| self.attributes["Model Name"] = self._attributes["model_name"] # type: ignore | ||
| self.attributes["Device"] = self._attributes["device"]["name"] # type: ignore | ||
| self.attributes["Model Name"] = self._attributes["model_name"] # type: ignore[index] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why all this ignore index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was what mypy was saying was needed.
error: "type: ignore" comment without error code (consider "type: ignore[index]" instead) [ignore-without-code]
linux2mqtt/linux2mqtt.py
Outdated
| main_logger = logging.getLogger("main") | ||
| mqtt_logger = logging.getLogger("mqtt") | ||
|
|
||
| logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for this line, I use specific purpose loggers and do not want to pollute the default logging config as library.
See following code:
def configure_logger(
logger: logging.Logger, verbosity: int, logdir: str | None
) -> None:
"""Configure main logger.
Parameters
----------
logger
The logger to configure
verbosity
The verbosity level
logdir
The log directory
"""
if verbosity >= 5:
logger.setLevel(logging.DEBUG)
elif verbosity == 4:
logger.setLevel(logging.INFO)
elif verbosity == 3:
logger.setLevel(logging.WARNING)
elif verbosity == 2:
logger.setLevel(logging.ERROR)
elif verbosity == 1:
logger.setLevel(logging.CRITICAL)
# Configure logger
logger.propagate = False
log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
formatter = logging.Formatter(log_format)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
if logdir:
try:
logdirpath = Path(logdir)
absolute_logdir = (
logdirpath.resolve() if not logdirpath.is_absolute() else logdirpath
)
absolute_logdir.mkdir(parents=True, exist_ok=True)
log_file = path.join(absolute_logdir, f"linux2mqtt-{logger.name}.log")
file_handler = RotatingFileHandler(
log_file, maxBytes=1_000_000, backupCount=5
)
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
except Exception as ex:
logger.warning(
"Failed to initialize logging to directory %s : %s",
logdir,
str(ex),
)
Pull harddrive stats from smartctl for HDDs and NVME drives