From 1b1a3226742365e86643c3dd3d34c0a380bc0588 Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Thu, 16 Apr 2020 14:20:54 +0200 Subject: [PATCH 1/6] added config read from pve --- src/pve_exporter/collector.py | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index ab8f193..a3fabf3 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -244,6 +244,49 @@ def collect(self): # pylint: disable=missing-docstring return itertools.chain(metrics.values(), info_metrics.values()) +class NodeVmConfigCollector(object): + """ + Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. + For manual test: "pvesh get /nodes////config" + + # HELP pve_vm_config_onboot Proxmox vm config onboot value + # TYPE pve_vm_config_onboot gauge + pve_vm_config_onboot{id="qemu/113",node="XXXX",type="qemu"} 1.0 + """ + + def __init__(self, pve): + self._pve = pve + + def collect(self): + metrics = { + 'onboot': GaugeMetricFamily( + 'pve_vm_config_onboot', + 'Proxmox vm config onboot value', + labels=['id','node', 'type']), + 'memory': GaugeMetricFamily( + 'pve_vm_config_memory', + 'Proxmox vm config memory value', + labels=['id','node', 'type']), + } + + for node in self._pve.nodes.get(): + # Qemu + vmtype = 'qemu' + for vm in self._pve.nodes(node['node']).qemu.get(): + for key, metric_value in self._pve.nodes(node['node']).qemu(vm['vmid']).config.get().items(): + label_values = ["%s/%s" % (vmtype, vm['vmid']), node['node'], vmtype] + if key in metrics: + metrics[key].add_metric(label_values, metric_value) + # LXC + vmtype = 'lxc' + for vm in self._pve.nodes(node['node']).lxc.get(): + for key, metric_value in self._pve.nodes(node['node']).lxc(vm['vmid']).config.get().items(): + label_values = ["%s/%s" % (vmtype, vm['vmid']), node['node'], vmtype] + if key in metrics: + metrics[key].add_metric(label_values, metric_value) + + return metrics.values() + def collect_pve(config, host): """Scrape a host and return prometheus text format for it""" @@ -254,5 +297,6 @@ def collect_pve(config, host): registry.register(ClusterResourcesCollector(pve)) registry.register(ClusterNodeCollector(pve)) registry.register(ClusterInfoCollector(pve)) + registry.register(NodeVmConfigCollector(pve)) registry.register(VersionCollector(pve)) return generate_latest(registry) From 946890248c237b7955c4b96f5213c1db8adce9ae Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Thu, 16 Apr 2020 14:59:49 +0200 Subject: [PATCH 2/6] fixing CI errors space, varname and row lenght --- src/pve_exporter/collector.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index a3fabf3..2fa0ff5 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -244,9 +244,9 @@ def collect(self): # pylint: disable=missing-docstring return itertools.chain(metrics.values(), info_metrics.values()) -class NodeVmConfigCollector(object): +class ClusterNodeConfigCollector(object): """ - Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. + Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. For manual test: "pvesh get /nodes////config" # HELP pve_vm_config_onboot Proxmox vm config onboot value @@ -262,26 +262,28 @@ def collect(self): 'onboot': GaugeMetricFamily( 'pve_vm_config_onboot', 'Proxmox vm config onboot value', - labels=['id','node', 'type']), + labels=['id', 'node', 'type']), 'memory': GaugeMetricFamily( 'pve_vm_config_memory', 'Proxmox vm config memory value', - labels=['id','node', 'type']), + labels=['id', 'node', 'type']), } for node in self._pve.nodes.get(): # Qemu vmtype = 'qemu' - for vm in self._pve.nodes(node['node']).qemu.get(): - for key, metric_value in self._pve.nodes(node['node']).qemu(vm['vmid']).config.get().items(): - label_values = ["%s/%s" % (vmtype, vm['vmid']), node['node'], vmtype] + for vmdata in self._pve.nodes(node['node']).qemu.get(): + config = self._pve.nodes(node['node']).qemu(vmdata['vmid']).config.get().items() + for key, metric_value in config: + label_values = ["%s/%s" % (vmtype, vmdata['vmid']), node['node'], vmtype] if key in metrics: metrics[key].add_metric(label_values, metric_value) # LXC vmtype = 'lxc' - for vm in self._pve.nodes(node['node']).lxc.get(): - for key, metric_value in self._pve.nodes(node['node']).lxc(vm['vmid']).config.get().items(): - label_values = ["%s/%s" % (vmtype, vm['vmid']), node['node'], vmtype] + for vmdata in self._pve.nodes(node['node']).lxc.get(): + config = self._pve.nodes(node['node']).lxc(vmdata['vmid']).config.get().items() + for key, metric_value in config: + label_values = ["%s/%s" % (vmtype, vmdata['vmid']), node['node'], vmtype] if key in metrics: metrics[key].add_metric(label_values, metric_value) @@ -297,6 +299,6 @@ def collect_pve(config, host): registry.register(ClusterResourcesCollector(pve)) registry.register(ClusterNodeCollector(pve)) registry.register(ClusterInfoCollector(pve)) - registry.register(NodeVmConfigCollector(pve)) + registry.register(ClusterNodeConfigCollector(pve)) registry.register(VersionCollector(pve)) return generate_latest(registry) From 1b71950e530d5867db8b9736435eab21f08c42e1 Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Thu, 16 Apr 2020 15:05:41 +0200 Subject: [PATCH 3/6] fix white space and pylink def docstring --- src/pve_exporter/collector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index 2fa0ff5..d87466e 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -246,7 +246,7 @@ def collect(self): # pylint: disable=missing-docstring class ClusterNodeConfigCollector(object): """ - Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. + Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. For manual test: "pvesh get /nodes////config" # HELP pve_vm_config_onboot Proxmox vm config onboot value @@ -257,7 +257,7 @@ class ClusterNodeConfigCollector(object): def __init__(self, pve): self._pve = pve - def collect(self): + def collect(self): # pylint: disable=missing-docstring metrics = { 'onboot': GaugeMetricFamily( 'pve_vm_config_onboot', From 342f61cda41699b05afe652c661cc434fad94b9f Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Mon, 20 Apr 2020 11:48:41 +0200 Subject: [PATCH 4/6] suggested changes in PR remove pve_vm_config_memory and rename to pve_onboot_status --- src/pve_exporter/collector.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index d87466e..22b84e9 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -260,13 +260,9 @@ def __init__(self, pve): def collect(self): # pylint: disable=missing-docstring metrics = { 'onboot': GaugeMetricFamily( - 'pve_vm_config_onboot', + 'pve_onboot_status', 'Proxmox vm config onboot value', labels=['id', 'node', 'type']), - 'memory': GaugeMetricFamily( - 'pve_vm_config_memory', - 'Proxmox vm config memory value', - labels=['id', 'node', 'type']), } for node in self._pve.nodes.get(): From a31eeeb73ef3bbcd1a713c336034a330b9d78b3f Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Mon, 20 Apr 2020 11:57:39 +0200 Subject: [PATCH 5/6] forgot to change comment example to match change --- src/pve_exporter/collector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index 22b84e9..941ed74 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -251,7 +251,7 @@ class ClusterNodeConfigCollector(object): # HELP pve_vm_config_onboot Proxmox vm config onboot value # TYPE pve_vm_config_onboot gauge - pve_vm_config_onboot{id="qemu/113",node="XXXX",type="qemu"} 1.0 + pve_onboot_status{id="qemu/113",node="XXXX",type="qemu"} 1.0 """ def __init__(self, pve): From a38b99158e5de799bd538f29a10fe8d0c8e93c2f Mon Sep 17 00:00:00 2001 From: Jakub Pinkas Date: Mon, 20 Apr 2020 11:59:43 +0200 Subject: [PATCH 6/6] and once more --- src/pve_exporter/collector.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pve_exporter/collector.py b/src/pve_exporter/collector.py index 941ed74..aa2bc48 100644 --- a/src/pve_exporter/collector.py +++ b/src/pve_exporter/collector.py @@ -249,8 +249,8 @@ class ClusterNodeConfigCollector(object): Collects Proxmox VE VM information directly from config, i.e. boot, name, onboot, etc. For manual test: "pvesh get /nodes////config" - # HELP pve_vm_config_onboot Proxmox vm config onboot value - # TYPE pve_vm_config_onboot gauge + # HELP pve_onboot_status Proxmox vm config onboot value + # TYPE pve_onboot_status gauge pve_onboot_status{id="qemu/113",node="XXXX",type="qemu"} 1.0 """