From edf0682a6b2d1b26ccd5549df7c7c2eac6fa4c00 Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Mon, 7 Nov 2022 15:10:30 +0100 Subject: [PATCH 1/9] Add UUID and Instance UUID in VM labels --- vmware_exporter/vmware_exporter.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index e497fa2..b1a1045 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -94,9 +94,9 @@ def __init__( # label names and ammount will be needed later to insert labels from custom attributes self._labelNames = { - 'vms': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], - 'vm_perf': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], - 'vmguests': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], + 'vms': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], + 'vm_perf': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], + 'vmguests': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], 'snapshots': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], 'datastores': ['ds_name', 'dc_name', 'ds_cluster'], 'hosts': ['host_name', 'dc_name', 'cluster_name'], @@ -738,6 +738,8 @@ def vm_inventory(self): 'runtime.host', 'parent', 'summary.config.vmPathName', + 'summary.config.uuid', + 'summary.config.instanceUuid', ] if self.collect_only['vms'] is True: @@ -1104,6 +1106,15 @@ def vm_labels(self): if host_moid in host_labels: labels[moid] = labels[moid] + host_labels[host_moid] + if 'summary.config.uuid' in row: + labels[moid] += [row['summary.config.uuid']] + else: + labels[moid] += ["no_uuid"] + if 'summary.config.instanceUuid' in row: + labels[moid] += [row['summary.config.instanceUuid']] + else: + labels[moid] += ["no_instanceUuid"] + """ this code was in vm_inventory before but I have the feeling it is best placed here where From 77a200367c8518e589e47949c56d998fdb382e72 Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Wed, 28 Aug 2024 21:00:02 +0200 Subject: [PATCH 2/9] Fix custom attributes --- vmware_exporter/vmware_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index b1a1045..0b2afc2 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -1199,7 +1199,7 @@ def updateMetricsLabelNames(self, metrics, metric_types): for metric_name in self._metricNames.get(metric_type, []): metric = metrics.get(metric_name) labelnames = metric._labelnames - metric._labelnames = labelnames[0:len(self._labelNames[metric_type])] + metric._labelnames = list(labelnames[0:len(self._labelNames[metric_type])]) metric._labelnames += customAttributesLabelNames metric._labelnames += labelnames[len(self._labelNames[metric_type]):] metric._labelnames = list(map(lambda x: re.sub('[^a-zA-Z0-9_]', '_', x), metric._labelnames)) From 866e5039c8e0535020a52c763ce4e385d8e960fb Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Wed, 28 Aug 2024 21:00:49 +0200 Subject: [PATCH 3/9] Bump python version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 4ade0e9..5066bb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.12-alpine LABEL MAINTAINER="Daniel Pryor " LABEL NAME=vmware_exporter From b3f7a045b6a65c86625ebc77d4e1aa8789c90228 Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Wed, 28 Aug 2024 21:01:14 +0200 Subject: [PATCH 4/9] Add requests in requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index d924920..9e0b32f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ pyvmomi>=6.5 twisted>=14.0.2 pyyaml>=5.1 service-identity +requests From cbc3c3170016147ade1a46d67e579348a2900cda Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Wed, 28 Aug 2024 21:01:48 +0200 Subject: [PATCH 5/9] docker-compose for dev only --- docker-compose.yml | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 64d4dc3..8c944bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,16 +2,14 @@ version: '2' services: vmware_exporter: # Using the latest tag, but you can use vers(v0.9.5 for example - image: pryorda/vmware_exporter:latest + image: localhost/pryorda/vmware_exporter:dev + build: + context: . + dockerfile: Dockerfile ports: - - "9275:9272" - environment: - VSPHERE_HOST: "vcenter-host" - VSPHERE_USER: "username" - VSPHERE_PASSWORD: "P@ssw0rd" - VSPHERE_IGNORE_SSL: "True" - VSPHERE_COLLECT_VMS: "False" - VSPHERE_COLLECT_VMGUESTS: "False" + - "9272:9272" + volumes: + - ./config.yml:/config.yml:ro restart: always #FOR DEBUG UNCOMMENT NEXT LINE - #command: ["-l","DEBUG"] + command: ["-l","DEBUG", "-c" , "/config.yml"] From 5a778accd45eb41805e4371a70d5bd7bbf32d9ff Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Fri, 30 Aug 2024 15:27:41 +0200 Subject: [PATCH 6/9] Add moid label in vms metrics --- vmware_exporter/vmware_exporter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index 0b2afc2..897551d 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -94,9 +94,9 @@ def __init__( # label names and ammount will be needed later to insert labels from custom attributes self._labelNames = { - 'vms': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], - 'vm_perf': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], - 'vmguests': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid'], + 'vms': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid', 'moid'], + 'vm_perf': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid', 'moid'], + 'vmguests': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid','moid'], 'snapshots': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], 'datastores': ['ds_name', 'dc_name', 'ds_cluster'], 'hosts': ['host_name', 'dc_name', 'cluster_name'], @@ -1114,7 +1114,7 @@ def vm_labels(self): labels[moid] += [row['summary.config.instanceUuid']] else: labels[moid] += ["no_instanceUuid"] - + labels[moid] += [moid] """ this code was in vm_inventory before but I have the feeling it is best placed here where From bfc96d57042a65d44fbe312a21b9a415aa730239 Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Mon, 14 Oct 2024 10:55:51 +0200 Subject: [PATCH 7/9] Fix tags and custom attributes on snapshots --- vmware_exporter/vmware_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index 897551d..4a0a552 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -97,7 +97,7 @@ def __init__( 'vms': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid', 'moid'], 'vm_perf': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid', 'moid'], 'vmguests': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid','moid'], - 'snapshots': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name'], + 'snapshots': ['vm_name', 'ds_name', 'host_name', 'dc_name', 'cluster_name', 'uuid', 'instance_uuid','moid'], 'datastores': ['ds_name', 'dc_name', 'ds_cluster'], 'hosts': ['host_name', 'dc_name', 'cluster_name'], 'host_perf': ['host_name', 'dc_name', 'cluster_name'], From c35cd3281f7f945bbbb1270d87357012e7241ffd Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Tue, 15 Oct 2024 17:02:44 +0200 Subject: [PATCH 8/9] Remove finish when client is disconnected --- vmware_exporter/vmware_exporter.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vmware_exporter/vmware_exporter.py b/vmware_exporter/vmware_exporter.py index 4a0a552..82f31f2 100755 --- a/vmware_exporter/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -1950,6 +1950,8 @@ def _async_render_GET(self, request): logging.error(traceback.format_exc()) request.setResponseCode(500) request.write(b'# Collection failed') + if request._disconnected: + return request.finish() # We used to call request.processingFailed to send a traceback to browser @@ -1993,10 +1995,11 @@ def generate_latest_metrics(self, request): registry = CollectorRegistry() registry.register(ListCollector(metrics)) output = generate_latest(registry) - request.setHeader("Content-Type", "text/plain; charset=UTF-8") request.setResponseCode(200) request.write(output) + if request._disconnected: + return request.finish() From 3751d91d2575329ca34b96dd89fc0405383a6b32 Mon Sep 17 00:00:00 2001 From: Anthony Belhadj Date: Tue, 15 Oct 2024 17:03:20 +0200 Subject: [PATCH 9/9] Bump prometheus lib --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9e0b32f..53843e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -prometheus-client==0.0.19 +prometheus-client==0.21.0 pytz pyvmomi>=6.5 twisted>=14.0.2