From e4ca2becb7574537fedaca642d48c6454be4e70b Mon Sep 17 00:00:00 2001 From: DeerMaximum Date: Mon, 31 Jul 2023 19:40:07 +0200 Subject: [PATCH 1/2] Add disk info --- src/pve_exporter/cli.py | 4 ++++ src/pve_exporter/collector.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/pve_exporter/cli.py b/src/pve_exporter/cli.py index b51cc10..c727f84 100755 --- a/src/pve_exporter/cli.py +++ b/src/pve_exporter/cli.py @@ -73,6 +73,9 @@ def main(): parser.add_argument('--collector.node', dest='collector_node', action=BooleanOptionalAction, default=True, help='Exposes PVE node info') + parser.add_argument('--collector.disk', dest='collector_disk', + action=BooleanOptionalAction, default=True, + help='Exposes PVE node info') parser.add_argument('--collector.cluster', dest='collector_cluster', action=BooleanOptionalAction, default=True, help='Exposes PVE cluster info') @@ -97,6 +100,7 @@ def main(): status=params.collector_status, version=params.collector_version, node=params.collector_node, + disk=params.collector_disk, cluster=params.collector_cluster, resources=params.collector_resources, config=params.collector_config diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index 7c838d3..3d6d0c0 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -16,6 +16,7 @@ 'status', 'version', 'node', + 'disk', 'cluster', 'resources', 'config', @@ -115,6 +116,38 @@ def collect(self): # pylint: disable=missing-docstring yield info_metrics +class ClusterDiskCollector: + """ + Collects Proxmox VE cluster disk information. E.g.: + + # HELP pve_disk_info Disk info + # TYPE pve_disk_info gauge + pve_disk_info{devpath="/dev/nvme0n1",health="PASSED",node="proxmox-host", + serial="S34NNL0TA1571AF",size="500107862016",type="nvme"} 1.0 + """ + + def __init__(self, pve): + self._pve = pve + + def collect(self): # pylint: disable=missing-docstring + nodes = [entry for entry in self._pve.cluster.status.get() if entry['type'] == 'node'] + labels = ['serial', 'health', 'devpath', 'size', 'type' , 'node'] + + if nodes: + info_metrics = GaugeMetricFamily( + 'pve_disk_info', + 'Disk info', + labels=labels) + + for node in nodes: + print(node) + for disk in self._pve.nodes(node['name']).disks.list.get(): + label_values = [ str(disk[key]) for key in labels[:-1] ] + label_values.append(node['name']) + info_metrics.add_metric(label_values, 1) + + yield info_metrics + class ClusterInfoCollector: """ Collects Proxmox VE cluster information. E.g.: @@ -322,6 +355,8 @@ def collect_pve(config, host, options: CollectorsOptions): registry.register(ClusterResourcesCollector(pve)) if options.node: registry.register(ClusterNodeCollector(pve)) + if options.disk: + registry.register(ClusterDiskCollector(pve)) if options.cluster: registry.register(ClusterInfoCollector(pve)) if options.config: From 5bb83d23120de2fd681845a3373840da157e415c Mon Sep 17 00:00:00 2001 From: DeerMaximum Date: Mon, 31 Jul 2023 19:41:41 +0200 Subject: [PATCH 2/2] Update help text --- src/pve_exporter/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pve_exporter/cli.py b/src/pve_exporter/cli.py index c727f84..45120a1 100755 --- a/src/pve_exporter/cli.py +++ b/src/pve_exporter/cli.py @@ -75,7 +75,7 @@ def main(): help='Exposes PVE node info') parser.add_argument('--collector.disk', dest='collector_disk', action=BooleanOptionalAction, default=True, - help='Exposes PVE node info') + help='Exposes PVE disk info') parser.add_argument('--collector.cluster', dest='collector_cluster', action=BooleanOptionalAction, default=True, help='Exposes PVE cluster info')