From d1811e4eddefb86f5dfb8d6e17ce3922274edf01 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 14:25:57 +0800 Subject: [PATCH 01/13] Remove `envdir` from `tox.ini`. The config option `envdir` is never intended to be used to share env directory [1]. [1] https://github.com/tox-dev/tox/issues/2788#issuecomment-1367437092. --- tox.ini | 3 --- 1 file changed, 3 deletions(-) diff --git a/tox.ini b/tox.ini index b54137a..b9c94fa 100644 --- a/tox.ini +++ b/tox.ini @@ -12,7 +12,6 @@ basepython = python3 setenv = PYTHONPATH={toxinidir} [testenv:dev-environment] -envdir = {toxinidir}/.venv deps = pre-commit {[testenv:lint]deps} @@ -22,7 +21,6 @@ commands = pre-commit install [testenv:pre-commit] -envdir = {[testenv:dev-environment]envdir} deps = {[testenv:dev-environment]deps} # ensure that dev-environment is installed commands = pre-commit run --all-files @@ -48,7 +46,6 @@ deps = {[testenv:func]deps} [testenv:reformat] -envdir = {toxworkdir}/lint deps = {[testenv:lint]deps} commands = black . From 1cd85aadd245368ffc228f3607460621787ab78e Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 14:57:31 +0800 Subject: [PATCH 02/13] Fix spelling errors. --- prometheus_hardware_exporter/collector.py | 2 +- prometheus_hardware_exporter/collectors/redfish.py | 2 +- prometheus_hardware_exporter/collectors/sasircu.py | 2 +- prometheus_hardware_exporter/core.py | 2 +- prometheus_hardware_exporter/exporter.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/prometheus_hardware_exporter/collector.py b/prometheus_hardware_exporter/collector.py index 500afb9..a764eba 100644 --- a/prometheus_hardware_exporter/collector.py +++ b/prometheus_hardware_exporter/collector.py @@ -331,7 +331,7 @@ class IpmiDcmiCollector(BlockingCollector): """Collector for ipmi dcmi metrics.""" def __init__(self, config: Config) -> None: - """Initialze the collector.""" + """Initialize the collector.""" self.ipmi_dcmi = IpmiDcmi(config) self.ipmi_tool = IpmiTool(config) self.dmidecode = Dmidecode(config) diff --git a/prometheus_hardware_exporter/collectors/redfish.py b/prometheus_hardware_exporter/collectors/redfish.py index 16da6f1..5a733dc 100644 --- a/prometheus_hardware_exporter/collectors/redfish.py +++ b/prometheus_hardware_exporter/collectors/redfish.py @@ -335,7 +335,7 @@ def get_storage_controller_data(self) -> Tuple[Dict[str, int], Dict[str, List]]: health = data.get("Status", {}).get("Health", "NA") if controller_id == "" or not state: # health is not required logger.warning( - "No relavent data found in storage controller data: %s", data + "No relevant data found in storage controller data: %s", data ) continue storage_controller_count[system_id] += 1 diff --git a/prometheus_hardware_exporter/collectors/sasircu.py b/prometheus_hardware_exporter/collectors/sasircu.py index 04143d2..2176232 100644 --- a/prometheus_hardware_exporter/collectors/sasircu.py +++ b/prometheus_hardware_exporter/collectors/sasircu.py @@ -88,7 +88,7 @@ def _parse_key_value(self, text: str) -> Dict[str, Any]: return data def _get_controller(self, text: str) -> Dict[str, str]: - """Return controller information from the contoller section text. + """Return controller information from the controller section text. Returns: Controller information diff --git a/prometheus_hardware_exporter/core.py b/prometheus_hardware_exporter/core.py index 9e8189e..ae2a100 100644 --- a/prometheus_hardware_exporter/core.py +++ b/prometheus_hardware_exporter/core.py @@ -132,7 +132,7 @@ def collect(self) -> Iterable[Metric]: Yields: metrics: the internal metrics """ - # The general exception hanlder will try to make sure the single + # The general exception handler will try to make sure the single # collector's bug will only change the metrics output to failed_metrics # and also make sure other collectors are still working. try: diff --git a/prometheus_hardware_exporter/exporter.py b/prometheus_hardware_exporter/exporter.py index fbc11aa..12e7180 100644 --- a/prometheus_hardware_exporter/exporter.py +++ b/prometheus_hardware_exporter/exporter.py @@ -20,7 +20,7 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): class SlientRequestHandler(WSGIRequestHandler): - """A Slient Request handler.""" + """A Silent Request handler.""" def log_message(self, format: str, *args: Any) -> None: # pylint: disable=W0622 """Log nothing.""" From 2d0b863877ca08c127d9b34b9f0feafdbd8c91ae Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 15:00:21 +0800 Subject: [PATCH 03/13] Update author name. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ae69237..5c7ad58 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ "description": "exports hardware related metrics", "use_scm_version": True, "setup_requires": ["setuptools_scm", "pyyaml"], - "author": "Canonical BootStack DevOps Centres", + "author": "Canonical Solution Engineering", "packages": ["prometheus_hardware_exporter", "prometheus_hardware_exporter.collectors"], "url": "https://github.com/canonical/prometheus-hardware-exporter", "entry_points": { From c0435258ce4376afe0e5ac1b34bda64505b2d278 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 15:28:07 +0800 Subject: [PATCH 04/13] Update the description for the cli: `prometheus-hardware-exporter` --- prometheus_hardware_exporter/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus_hardware_exporter/__main__.py b/prometheus_hardware_exporter/__main__.py index 67036e4..c4e4e25 100644 --- a/prometheus_hardware_exporter/__main__.py +++ b/prometheus_hardware_exporter/__main__.py @@ -1,4 +1,4 @@ -"""Package entrypoint.""" +"""Collect and export metrics for various hardware component.""" import argparse import logging From 07e835e0d28a3fb418a915de077dfc4c421bf7c9 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:04:01 +0800 Subject: [PATCH 05/13] Update existing readme and create readme for snap. --- README-SNAP.md | 63 +++++++++++++++++++++++++++++++ README.md | 100 ++++++++++++++++++++++++------------------------- 2 files changed, 112 insertions(+), 51 deletions(-) create mode 100644 README-SNAP.md diff --git a/README-SNAP.md b/README-SNAP.md new file mode 100644 index 0000000..4a3178f --- /dev/null +++ b/README-SNAP.md @@ -0,0 +1,63 @@ +## Prometheus Hardware Exporter Snap + +**Work In Progress**: the snap is only ready for local testing. + +## Local Build and Testing + +You need `snapcraft` to build the snap: + +```shell +sudo snap install snapcraft --classic +``` + +Snapcraft also requires backend to create isolated build environment, you can +choose the following two backends: + +- [LXD](https://linuxcontainers.org/lxd/introduction/), which creates container + image build instances. It can be used inside virtual machines. +- [Multipass](https://multipass.run/), which creates virtual machine build + instances. It cannot be reliably used on platforms that do not support nested + virtualization. For instance, Multipass will most likely not run inside a + virtual machine itself. + +To build the snap: + +```shell +make build +``` + +To try the snap that was built, you can install it locally: + +```shell +sudo snap install --devmode ./$(grep -E "^name:" snap/snapcraft.yaml | awk '{print $2}').snap +``` + +Start the exporter: + +```shell +sudo snap start prometheus-hardware-exporter # by default it listen on port 10000 +``` + +When you're done testing, you can remove the snap: + +```shell +sudo snap remove prometheus-hardware-exporter +``` + +## Snap Configuration + +The install hook (`./snap/hooks/install`) will generate a default configuration +for the exporter. By default, the exporter is started at port 10000 with a +logging level of INFO. + +You can change the default configuration by editing + +```shell +/var/snap/prometheus-hardware-exporter/current/config.yaml +``` + +and then restart the snap by + +```shell +sudo snap restart prometheus-hardware-exporter +``` diff --git a/README.md b/README.md index 5608374..d8b488b 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,63 @@ -# Prometheus Exporter Snap for Hardware Observer charm - - -You can learn more about Hardware Observer on [Charmhub](https://charmhub.io/hardware-observer). -## Getting Started - -Install the snap from snap store: - -```bash -$ sudo snap install prometheus-hardware-exporter --classic -``` - -Start the exporter: - -```bash -$ sudo snap start prometheus-hardware-exporter +# Prometheus Hardware Exporter + +Prometheus Hardware Exporter exports Prometheus metrics from BMCs (Baseboard +management controllers) using IPMI (Intelligent Platform Management Interface) +and Redfish protocol. It also exports and various SAS (Serial Attached SCSI) and +RAID (redundant array of inexpensive disks) controllers. + +Note that the exporter does not bundle the required third party or proprietary +software. If you would like to use this exporter you will need to install them +by yourself. Therefore, Prometheus Hardware Exporter is recommended for +[Juju](https://juju.is/) users, you can learn more about Hardware Observer on +[Charmhub](https://charmhub.io/hardware-observer). + +## Installation + +This package is not published in anywhere yet. For now, you can should install +this application locally (or via a virtual environment). To install it on a +virtual environment, you can run: + +```shell +# Install virtualvenv and source it +pip3 install virtualenv +python3 -m venv venv +source venv/bin/activate + +# Install the prometheus-hardware-exporter package; the "(venv)" means you are +# under the virtual environment +(venv) pip3 install . ``` -## Snap Configuration +To verify you have install the package, you can run: -The install hook (`./snap/hooks/install`) will generate a default configuration -for the exporter. By default, the exporter is started at port 10000 with a -logging level of INFO. - -You can change the default configuration by editing - -```bash -$ /var/snap/prometheus-hardware-exporter/current/config.yaml +```shell +(venv) prometheus-hardware-exporter -h ``` -and then restart the snap by - -```bash -$ sudo snap restart prometheus-hardware-exporter -``` +If you see the help message, then `prometheus-hardware-exporter` is installed on +the virtual environment. -## Local Build and Testing +## Usages -You need `snapcraft` to build the snap: +To run the exporter at port `10000` and enable the ipmi sensor collector, you +can run: -```bash -$ sudo snap install snapcraft --classic +```shell +(venv) prometheus-hardware-exporter -p 10000 --collector.ipmi_sensor ``` -Snapcraft also requires backend to create isolated build environment, you can -choose the following two backends: +Note that all the exporters are disabled by default as you will need to install +the appropriate third party or proprietary software to run the collectors. You +can check out [Resources](200~https://charmhub.io/hardware-observer/resources/) +to find out more information about the third party software. -- [LXD](https://linuxcontainers.org/lxd/introduction/), which creates container - image build instances. It can be used inside virtual machines. -- [Multipass](https://multipass.run/), which creates virtual machine build - instances. It cannot be reliably used on platforms that do not support nested - virtualization. For instance, Multipass will most likely not run inside a - virtual machine itself. +## Supported Metrics -To build the snap: +You can learn more about the metrics from [Hardware Observer +documentation](https://charmhub.io/hardware-observer/docs/metrics-and-alerts-common). -```bash -$ make build -``` - -To try the snap that was built, you can install it locally: +## Snap support -```bash -$ sudo snap install --devmode ./$(grep -E "^name:" snap/snapcraft.yaml | awk '{print $2}').snap -``` +This is still work in progress, and only support local testing. For more +information on building and running the snap locally, please refer to +[README-SNAP.md](https://github.com/canonical/prometheus-hardware-exporter/blob/main/README-SNAP.md) From 5cd00984be169a4ad3ff5decf9dc5671c81738ba Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:06:15 +0800 Subject: [PATCH 06/13] Update description of `snapcraft.yaml`. --- snap/snapcraft.yaml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e67013c..5319df7 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,12 +1,10 @@ name: prometheus-hardware-exporter base: core22 adopt-info: prometheus-hardware-exporter -summary: collects backup results and exports them as metrics +summary: collects hardware related information and exports them as metrics description: | - The prometheus-hardware-exporter is a snap for collecting backup - results from charm-hardware, and export those results as prometheus - metrics. The metrics are expected to be used with prometheus. - + The prometheus-hardware-exporter is a snap for collecting hardware related + information from the host machine, and export them as prometheus metrics. grade: stable confinement: classic From 79d6559df28640067df3e2981b5f707c9409963b Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:06:54 +0800 Subject: [PATCH 07/13] Move the "grade" in `snapcraft.yaml` back to devel. --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 5319df7..7fe288b 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -5,7 +5,7 @@ summary: collects hardware related information and exports them as metrics description: | The prometheus-hardware-exporter is a snap for collecting hardware related information from the host machine, and export them as prometheus metrics. -grade: stable +grade: devel confinement: classic apps: From 046ac688ec376365d7359d03c851b297854dfbd2 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:33:10 +0800 Subject: [PATCH 08/13] Fix broken snap build: move confinement back to `strict`. --- snap/snapcraft.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7fe288b..4a61637 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -6,7 +6,7 @@ description: | The prometheus-hardware-exporter is a snap for collecting hardware related information from the host machine, and export them as prometheus metrics. grade: devel -confinement: classic +confinement: strict apps: prometheus-hardware-exporter: From 024b6109f02877528f749fdd7ae02d83a6bb196f Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:39:49 +0800 Subject: [PATCH 09/13] Fix broken reference. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8b488b..037e231 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,4 @@ documentation](https://charmhub.io/hardware-observer/docs/metrics-and-alerts-com This is still work in progress, and only support local testing. For more information on building and running the snap locally, please refer to -[README-SNAP.md](https://github.com/canonical/prometheus-hardware-exporter/blob/main/README-SNAP.md) +[README-SNAP.md](README-SNAP.md) From 3c420dcaee0af8428d6780e874cda8ee2e9d89ab Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 16:41:07 +0800 Subject: [PATCH 10/13] Change title to header 1. --- README-SNAP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-SNAP.md b/README-SNAP.md index 4a3178f..5461150 100644 --- a/README-SNAP.md +++ b/README-SNAP.md @@ -1,4 +1,4 @@ -## Prometheus Hardware Exporter Snap +# Prometheus Hardware Exporter Snap **Work In Progress**: the snap is only ready for local testing. From 184f82ff7cc562eb9d6dfc51c3b48629c2dffe59 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Thu, 25 Apr 2024 17:11:29 +0800 Subject: [PATCH 11/13] Fix typo in classname. --- prometheus_hardware_exporter/exporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prometheus_hardware_exporter/exporter.py b/prometheus_hardware_exporter/exporter.py index 12e7180..0be497c 100644 --- a/prometheus_hardware_exporter/exporter.py +++ b/prometheus_hardware_exporter/exporter.py @@ -19,7 +19,7 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): daemon_threads = True -class SlientRequestHandler(WSGIRequestHandler): +class SilentRequestHandler(WSGIRequestHandler): """A Silent Request handler.""" def log_message(self, format: str, *args: Any) -> None: # pylint: disable=W0622 @@ -51,7 +51,7 @@ def run(self, daemon: bool = False) -> None: self.port, self.app, server_class=ThreadingWSGIServer, - handler_class=SlientRequestHandler, + handler_class=SilentRequestHandler, ) logger.info("Started prometheus hardware exporter at %s:%s.", self.addr, self.port) thread = threading.Thread(target=httpd.serve_forever) From 3a47d205f7ee205c3e447dd02e392e1765b29039 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Fri, 26 Apr 2024 10:13:35 +0800 Subject: [PATCH 12/13] Apply suggestion. --- README-SNAP.md | 4 ++-- README.md | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README-SNAP.md b/README-SNAP.md index 5461150..969988b 100644 --- a/README-SNAP.md +++ b/README-SNAP.md @@ -10,8 +10,8 @@ You need `snapcraft` to build the snap: sudo snap install snapcraft --classic ``` -Snapcraft also requires backend to create isolated build environment, you can -choose the following two backends: +Snapcraft also requires backend to create isolated build environment. You can +choose either of the following two backends for snapcraft: - [LXD](https://linuxcontainers.org/lxd/introduction/), which creates container image build instances. It can be used inside virtual machines. diff --git a/README.md b/README.md index 037e231..5199854 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,20 @@ management controllers) using IPMI (Intelligent Platform Management Interface) and Redfish protocol. It also exports and various SAS (Serial Attached SCSI) and RAID (redundant array of inexpensive disks) controllers. -Note that the exporter does not bundle the required third party or proprietary -software. If you would like to use this exporter you will need to install them -by yourself. Therefore, Prometheus Hardware Exporter is recommended for -[Juju](https://juju.is/) users, you can learn more about Hardware Observer on +Prometheus Hardware Exporter is recommended for [Juju](https://juju.is/) users, +you can deploy Prometheus Hardware Exporter using the Hardware Observer charm. +You can learn more about Hardware Observer on [Charmhub](https://charmhub.io/hardware-observer). +**Note**: this exporter does not bundle the required third party or proprietary +software. If you would like to use this exporter, you will need to install them +by yourself. + ## Installation -This package is not published in anywhere yet. For now, you can should install -this application locally (or via a virtual environment). To install it on a -virtual environment, you can run: +This package is not published anywhere as of now. Currently, it can be installed +locally or on a virtual environment. To install it on a virtual environment, +run: ```shell # Install virtualvenv and source it @@ -23,12 +26,12 @@ pip3 install virtualenv python3 -m venv venv source venv/bin/activate -# Install the prometheus-hardware-exporter package; the "(venv)" means you are -# under the virtual environment +# Install the prometheus-hardware-exporter package; the "(venv)" prefix on the +# shell prompt indicates that the virtual environment is active. (venv) pip3 install . ``` -To verify you have install the package, you can run: +To verify that the package has been installed successfully, run: ```shell (venv) prometheus-hardware-exporter -h @@ -39,8 +42,7 @@ the virtual environment. ## Usages -To run the exporter at port `10000` and enable the ipmi sensor collector, you -can run: +To start the exporter at port `10000` and enable the ipmi sensor collector, run: ```shell (venv) prometheus-hardware-exporter -p 10000 --collector.ipmi_sensor From f646efc14db199f485ef5cc41a190753df087774 Mon Sep 17 00:00:00 2001 From: Chi Wai Chan Date: Fri, 26 Apr 2024 10:41:47 +0800 Subject: [PATCH 13/13] Fix broken link. --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5199854..b371620 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ management controllers) using IPMI (Intelligent Platform Management Interface) and Redfish protocol. It also exports and various SAS (Serial Attached SCSI) and RAID (redundant array of inexpensive disks) controllers. -Prometheus Hardware Exporter is recommended for [Juju](https://juju.is/) users, -you can deploy Prometheus Hardware Exporter using the Hardware Observer charm. -You can learn more about Hardware Observer on +Prometheus Hardware Exporter is recommended for [Juju](https://juju.is/) users. +You can deploy Prometheus Hardware Exporter using the Hardware Observer charm. +For more information, you can read the documentation about Hardware Observer on [Charmhub](https://charmhub.io/hardware-observer). **Note**: this exporter does not bundle the required third party or proprietary @@ -50,8 +50,8 @@ To start the exporter at port `10000` and enable the ipmi sensor collector, run: Note that all the exporters are disabled by default as you will need to install the appropriate third party or proprietary software to run the collectors. You -can check out [Resources](200~https://charmhub.io/hardware-observer/resources/) -to find out more information about the third party software. +can check out [Resources](https://charmhub.io/hardware-observer/resources/) to +find out more information about the third party software. ## Supported Metrics