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

Collect hard disk information #155

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pve_exporter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 disk info')
parser.add_argument('--collector.cluster', dest='collector_cluster',
action=BooleanOptionalAction, default=True,
help='Exposes PVE cluster info')
Expand All @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/pve_exporter/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'status',
'version',
'node',
'disk',
'cluster',
'resources',
'config',
Expand Down Expand Up @@ -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.:
Expand Down Expand Up @@ -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:
Expand Down