Skip to content

Add tags collector exposing vSphere tag assignments for VMs - #47

Open
poulpreben wants to merge 2 commits into
prezhdarov:masterfrom
poulpreben:feature/vm-tags
Open

Add tags collector exposing vSphere tag assignments for VMs#47
poulpreben wants to merge 2 commits into
prezhdarov:masterfrom
poulpreben:feature/vm-tags

Conversation

@poulpreben

Copy link
Copy Markdown

What

Adds a new tags collector that exposes vSphere tag assignments for virtual machines, so tag/category metadata can be joined onto the existing VM metrics in PromQL.

For every tag attached to a VM it emits:

vmware_vm_tag{category="environment",tag="production",vcenter="vcenter01.example.com",vm="app-server-01",vmmo="vm-1001"} 1
vmware_vm_tag{category="environment",tag="staging",vcenter="vcenter01.example.com",vm="app-server-02",vmmo="vm-1002"} 1
vmware_vm_tag{category="backup-policy",tag="no-backup",vcenter="vcenter01.example.com",vm="db-server-01",vmmo="vm-1003"} 1

which joins onto any other VM metric via the vmmo label, e.g.:

vmware_vm_cpu_usagemhz_average
  * on(vmmo) group_left(category, tag)
    vmware_vm_tag

How

  • vmware/collectors/tags.go (new): registers a tags collector (flag -collector.tags, enabled by default, honors -disable.default.collectors). It fetches all VM refs/names through the property collector (name only, so the property fetch stays cheap), resolves tag categories once per scrape, then calls GetAttachedTagsOnObjects in batches of 500 VMs per vAPI request.
  • vmware/api/vmware.go: tags live behind the vAPI REST endpoint, which needs its own session on top of the SOAP one. Login now also creates the REST session and stores a tags.Manager in loginData - but only when the tags collector is enabled, so nothing changes for users who disable it. Logout tears the REST session down.
  • README.md: documents the new flag and metric.

No new dependencies - only the vapi/rest and vapi/tags packages from the already-vendored govmomi version.

Testing

  • go build ./..., go vet ./... and the existing test suite pass.
  • Verified against a live vCenter 8 instance: the collector returned all tag assignments (metric count matched the number of tag attachments in the inventory), vmware_scrape_collector_success{collector="tags"} 1, and the collector completed in ~0.35s for an inventory of several hundred VMs - comparable to the vm collector on the same scrape.

🤖 Generated with Claude Code

Logs into the vAPI REST endpoint alongside the existing SOAP session
(only when the tags collector is enabled) and emits
vmware_vm_tag{vmmo,vm,category,tag,vcenter} = 1 for every tag attached
to a virtual machine, ready to join onto other VM metrics via vmmo.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@poulpreben
poulpreben marked this pull request as ready for review July 6, 2026 11:26
Emits one gauge per virtual disk with the configured capacity in bytes,
labelled with a stable 0-based disk index (ordered by controller bus,
then unit number, then device key) and the vSphere device label.
Requires fetching config.hardware.device in the VM property collector.

Also fixes the copy-pasted description on vmware_vm_datastore_capacity_used.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant