Skip to content
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

Update the out-of-date readme file #72

Merged
merged 13 commits into from
Apr 26, 2024
Merged
63 changes: 63 additions & 0 deletions README-SNAP.md
Original file line number Diff line number Diff line change
@@ -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
```
90 changes: 45 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

chanchiwai-ray marked this conversation as resolved.
Show resolved Hide resolved
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).
Pjack marked this conversation as resolved.
Show resolved Hide resolved

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)
2 changes: 1 addition & 1 deletion prometheus_hardware_exporter/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Package entrypoint."""
"""Collect and export metrics for various hardware component."""

import argparse
import logging
Expand Down
2 changes: 1 addition & 1 deletion prometheus_hardware_exporter/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion prometheus_hardware_exporter/collectors/redfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prometheus_hardware_exporter/collectors/sasircu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion prometheus_hardware_exporter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions prometheus_hardware_exporter/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
12 changes: 5 additions & 7 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
3 changes: 0 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ basepython = python3
setenv = PYTHONPATH={toxinidir}

[testenv:dev-environment]
envdir = {toxinidir}/.venv
deps =
pre-commit
{[testenv:lint]deps}
Expand All @@ -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

Expand All @@ -48,7 +46,6 @@ deps =
{[testenv:func]deps}

[testenv:reformat]
envdir = {toxworkdir}/lint
rgildein marked this conversation as resolved.
Show resolved Hide resolved
deps = {[testenv:lint]deps}
commands =
black .
Expand Down
Loading