Skip to main content

Export prometheus metrics from vcenter host

Project description

# Vcenter Prometheus Exporter

Export prometheus metrics from vcenter host

## Installation

pip install pipenv
pipenv install vcenter_prometheus_exporter

## Usage

Default config file: **/etc/default/vcenter_exporter.yaml**

vcenter_exporter run


vcenter_exporter run -c config.yaml

## How it works

This exporter read an yaml config file composed with:
- vcenter: vcenter host and credentials
- objects: objects to get from vcenter and filter properties
- metrics: metrics to generates from objects

**See config_sample.yaml**

The exporter will:
- generate an exported resource view from vcenter objects
- set the metric type
- apply metric labels
- set metric value
- return Metric Object List to the embedded http server.


# HELP vcenter_host_cpu_cores vcenter_host_cpu_cores
# TYPE vcenter_host_cpu_cores gauge
vcenter_host_cpu_cores{hostname=""} 24.0
# HELP vcenter_host_memory_capacity vcenter_host_memory_capacity
# TYPE vcenter_host_memory_capacity gauge
vcenter_host_memory_capacity{hostname=""} 274645385216.0
# HELP vcenter_host_uptime_seconds vcenter_host_uptime_seconds
# TYPE vcenter_host_uptime_seconds gauge
vcenter_host_uptime_seconds{hostname=""} 3544985.0
# HELP vcenter_host_memory_usage vcenter_host_memory_usage
# TYPE vcenter_host_memory_usage gauge
vcenter_host_memory_usage{hostname=""} 209072.0
# HELP vcenter_host_power_state vcenter_host_power_state
# TYPE vcenter_host_power_state gauge
vcenter_host_power_state{hostname=""} 0.0
# HELP vcenter_host_cpu_frequency vcenter_host_cpu_frequency
# TYPE vcenter_host_cpu_frequency gauge
vcenter_host_cpu_frequency{hostname=""} 2195.0
# HELP vcenter_vm_memory_usage vcenter_vm_memory_usage
# TYPE vcenter_vm_memory_usage gauge
vcenter_vm_memory_usage{host="",vmname=""} 2785.0
# HELP vcenter_vm_power_state vcenter_vm_power_state
# TYPE vcenter_vm_power_state gauge
vcenter_vm_power_state{vmname=""} 0.0
# HELP vcenter_vm_cpu_usage vcenter_vm_cpu_usage
# TYPE vcenter_vm_cpu_usage gauge
vcenter_vm_cpu_usage{host="",vmname=""} 6211.0

## Specific features

There are **four** specific features:
- States Values
- Regex Filters
- Functions
- Objects Refs

**Note**: If a value to get is not specified, the default is 0.

### States values

As the prometheus python client doesn't yet support (Enum, Info..) types,
we can map text to value.


Getting the cluster heath status send three text states: **green, yellow and red**.

To have a valid metric, we map each state to an integer value.

type: Gauge
labels: ["cluster_name"]
labels: ["name"]
states: {"green": 0, "yellow": 1, "red": 2}
value: overallStatus

### Regex Filters

**match_filter:** get all objects which name match with the regex

type: VirtualMachine
match_filter: ".*testvm.*"
- "name"

**ignore_filter:** ignore all objects which name match with the regex

type: VirtualMachine
ignore_filter: "^testvm.*"
- "name"

### Functions

It's possible to call some object functions to get specfic info.

**Example: get the cluster storage used in MB**

Declare the function to use in:

type: ComputeResource
- GetResourceUsage
Give the value to get in the metric:
type: Gauge
labels: ["cluster_name"]
labels: ["name"]
value: memCapacityMB

#### Technical view:

This will execute the function:


(vim.cluster.ResourceUsageSummary) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
cpuUsedMHz = 673265,
cpuCapacityMHz = 842880,
memUsedMB = 3611287,
memCapacityMB = 4190768,
pMemAvailableMB = <unset>,
pMemCapacityMB = <unset>,
storageUsedMB = 34709118L,
storageCapacityMB = 60418304L

and update the dict:

{'memUsedMB': 3611336, 'storageCapacityMB': 60418304L, 'obj': 'vim.ClusterComputeResource:domain-c34', u'name': 'cluster_integration', 'dynamicProperty': (vmodl.DynamicProperty) [], 'dynamicType': None, u'summary.numEffectiveHosts': 16, 'pMemCapacityMB': None, 'cpuUsedMHz': 665617, u'summary.numHosts': 16, 'storageUsedMB': 34709118L, 'memCapacityMB': 4190768, u'overallStatus': 'green', 'pMemAvailableMB': None, 'cpuCapacityMHz': 842880}
### Objects Refs

In some cases, we want to get a property from an another object reference.

**Example: apply host label to vm metric**

Declare the property separated by **|** and the attribute to get:

type: Gauge
labels: ["vmname", "host"]
labels: ["name", "|name"]
value: summary.quickStats.overallCpuUsage
We are getting the attribute **'name'** from object **'vim.HostSystem:host-6077'**.

**Note: Getting an object ref consume time as it's not an view resource.**

## References

Vcenter Prometheus Exporter uses theses libraries:
- [pyVmomi]( for VMWare connection
- Prometheus [client_python]( for Prometheus supervision

Inspired by:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcenter-prometheus-exporter-0.0.1.tar.gz (7.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page