Skip to content

Commit

Permalink
Add support for smartctl exporter (canonical#242)
Browse files Browse the repository at this point in the history
* Refactor to support multiple exporters

* feat: SmartCtl exporter

---------

Co-authored-by: Sudeep Bhandari <[email protected]>

* Add grafana dashboard for smart (canonical#241)

* Skip tests that require service when no hardware is present (canonical#245)

* Skip tests that require service when no hardware is present

---------

Co-authored-by: james_lin <[email protected]>
Co-authored-by: Xuhui Zhu <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent 5d8ba2a commit d9eea1e
Show file tree
Hide file tree
Showing 15 changed files with 6,130 additions and 1,220 deletions.
12 changes: 9 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
#

options:
exporter-port:
hardware-exporter-port:
type: int
default: 10200
description: |
Start the prometheus exporter at "exporter-port". By default, it will
start at port 10200.
Start the prometheus hardware exporter at "hardware-exporter-port". By default,
it will start at port 10200.
smartctl-exporter-port:
type: int
default: 10201
description: |
Start the prometheus smartctl exporter at "smartctl-exporter-port". By default,
it will start at port 10201.
exporter-log-level:
type: string
default: "INFO"
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ distro
ops >= 2.2.0
jinja2
redfish # requests is included in this
pydantic < 2
git+https://github.com/canonical/prometheus-hardware-exporter.git
327 changes: 131 additions & 196 deletions src/charm.py

Large diffs are not rendered by default.

61 changes: 47 additions & 14 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,50 @@
from enum import Enum
from pathlib import Path

# Exporter
EXPORTER_NAME = "hardware-exporter"
EXPORTER_CONFIG_PATH = Path(f"/etc/{EXPORTER_NAME}-config.yaml")
EXPORTER_SERVICE_PATH = Path(f"/etc/systemd/system/{EXPORTER_NAME}.service")
EXPORTER_CONFIG_TEMPLATE = f"{EXPORTER_NAME}-config.yaml.j2"
EXPORTER_SERVICE_TEMPLATE = f"{EXPORTER_NAME}.service.j2"
EXPORTER_HEALTH_RETRY_COUNT = 3
EXPORTER_HEALTH_RETRY_TIMEOUT = 3
EXPORTER_CRASH_MSG = "Exporter crashed unexpectedly, please refer to systemd logs..."
from pydantic import BaseModel # pylint: disable = no-name-in-module

# Redfish
REDFISH_TIMEOUT = 10
REDFISH_MAX_RETRY = 2

class ExporterSettings(BaseModel): # pylint: disable = too-few-public-methods
"""Constant settings common across exporters."""

health_retry_count: int = 3
health_retry_timeout: int = 3
service_template: str
service_path: Path
name: str
config_template: str
config_path: Path


class HardwareExporterSettings(ExporterSettings): # pylint: disable = too-few-public-methods
"""Constant settings for Hardware Exporter."""

name: str = "hardware-exporter"
config_path: Path = Path(f"/etc/{name}-config.yaml")
service_path: Path = Path(f"/etc/systemd/system/{name}.service")
config_template: str = f"{name}-config.yaml.j2"
service_template: str = f"{name}.service.j2"
crash_msg: str = "Hardware exporter crashed unexpectedly, please refer to systemd logs..."

redfish_timeout: int = 10
redfish_max_retry: int = 2


HARDWARE_EXPORTER_SETTINGS = HardwareExporterSettings()


class SmartCtlExporterSettings(ExporterSettings): # pylint: disable = too-few-public-methods
"""Constant settings for SmartCtl Exporter."""

name: str = "smartctl-exporter"
config_path: Path = Path(f"/etc/{name}-config.yaml")
service_path: Path = Path(f"/etc/systemd/system/{name}.service")
config_template: str = f"{name}-config.yaml.j2"
service_template: str = f"{name}.service.j2"
crash_msg: str = "SmartCtl exporter crashed unexpectedly, please refer to systemd logs..."


SMARTCTL_EXPORTER_SETTINGS = SmartCtlExporterSettings()


class SystemVendor(str, Enum):
Expand Down Expand Up @@ -46,6 +77,8 @@ class HWTool(str, Enum):
IPMI_SEL = "ipmi_sel"
IPMI_SENSOR = "ipmi_sensor"
REDFISH = "redfish"
SMARTCTL = "smartctl"
SMARTCTL_EXPORTER = "smartctl_exporter"


TPR_RESOURCES: t.Dict[HWTool, str] = {
Expand All @@ -55,7 +88,7 @@ class HWTool(str, Enum):
HWTool.SAS3IRCU: "sas3ircu-bin",
}

EXPORTER_COLLECTOR_MAPPING = {
HARDWARE_EXPORTER_COLLECTOR_MAPPING = {
HWTool.STORCLI: ["collector.mega_raid"],
HWTool.PERCCLI: ["collector.poweredge_raid"],
HWTool.SAS2IRCU: ["collector.lsi_sas_2"],
Expand All @@ -70,4 +103,4 @@ class HWTool(str, Enum):
TOOLS_DIR = Path("/usr/sbin")

# SNAP environment
SNAP_COMMON = Path(f"/var/snap/{EXPORTER_NAME}/common")
SNAP_COMMON = Path(f"/var/snap/{HARDWARE_EXPORTER_SETTINGS.name}/common")
Loading

0 comments on commit d9eea1e

Please sign in to comment.