diff --git a/README-SNAP.md b/README-SNAP.md new file mode 100644 index 0000000..969988b --- /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 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. +- [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..b371620 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,65 @@ -# Prometheus Exporter Snap for Hardware Observer charm +# 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. -You can learn more about Hardware Observer on [Charmhub](https://charmhub.io/hardware-observer). -## Getting Started +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). -Install the snap from snap store: +**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. -```bash -$ sudo snap install prometheus-hardware-exporter --classic -``` - -Start the exporter: - -```bash -$ sudo snap start prometheus-hardware-exporter -``` - -## Snap Configuration +## Installation -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. +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: -You can change the default configuration by editing +```shell +# Install virtualvenv and source it +pip3 install virtualenv +python3 -m venv venv +source venv/bin/activate -```bash -$ /var/snap/prometheus-hardware-exporter/current/config.yaml +# Install the prometheus-hardware-exporter package; the "(venv)" prefix on the +# shell prompt indicates that the virtual environment is active. +(venv) pip3 install . ``` -and then restart the snap by +To verify that the package has been installed successfully, run: -```bash -$ sudo snap restart prometheus-hardware-exporter +```shell +(venv) prometheus-hardware-exporter -h ``` -## Local Build and Testing +If you see the help message, then `prometheus-hardware-exporter` is installed on +the virtual environment. -You need `snapcraft` to build the snap: +## Usages -```bash -$ sudo snap install snapcraft --classic -``` +To start the exporter at port `10000` and enable the ipmi sensor collector, run: -Snapcraft also requires backend to create isolated build environment, you can -choose the following two backends: +```shell +(venv) prometheus-hardware-exporter -p 10000 --collector.ipmi_sensor +``` -- [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. +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](https://charmhub.io/hardware-observer/resources/) to +find out more information about the third party software. -To build the snap: +## Supported Metrics -```bash -$ make build -``` +You can learn more about the metrics from [Hardware Observer +documentation](https://charmhub.io/hardware-observer/docs/metrics-and-alerts-common). -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](README-SNAP.md) 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 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..0be497c 100644 --- a/prometheus_hardware_exporter/exporter.py +++ b/prometheus_hardware_exporter/exporter.py @@ -19,8 +19,8 @@ class ThreadingWSGIServer(ThreadingMixIn, WSGIServer): daemon_threads = True -class SlientRequestHandler(WSGIRequestHandler): - """A Slient Request handler.""" +class SilentRequestHandler(WSGIRequestHandler): + """A Silent Request handler.""" def log_message(self, format: str, *args: Any) -> None: # pylint: disable=W0622 """Log nothing.""" @@ -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) 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": { diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index e67013c..4a61637 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,14 +1,12 @@ 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. - -grade: stable -confinement: classic + 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: strict apps: prometheus-hardware-exporter: 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 .