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

Add resourcepool metrics #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM python:3.7-alpine

LABEL MAINTAINER="Daniel Pryor <[email protected]>"
LABEL NAME=vmware_exporter
LABEL VERSION=0.18.4

WORKDIR /opt/vmware_exporter/
COPY . /opt/vmware_exporter/
Expand Down
98 changes: 57 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
VMware vCenter Exporter for Prometheus.

Get VMware vCenter information:

- Basic VM and Host metrics
- Current number of active snapshots
- Datastore size and other stuff
- Snapshot Unix timestamp creation date

## Badges

![Docker Stars](https://img.shields.io/docker/stars/pryorda/vmware_exporter.svg)
![Docker Pulls](https://img.shields.io/docker/pulls/pryorda/vmware_exporter.svg)
![Docker Automated](https://img.shields.io/docker/automated/pryorda/vmware_exporter.svg)
Expand All @@ -24,17 +26,17 @@ Get VMware vCenter information:
- Install with `$ python setup.py install` or via pip `$ pip install vmware_exporter`. The docker command below is preferred.
- Create `config.yml` based on the configuration section. Some variables can be passed as environment variables
- Run `$ vmware_exporter -c /path/to/your/config`
- Go to http://localhost:9272/metrics?vsphere_host=vcenter.company.com to see metrics
- Go to [http://localhost:9272/metrics?vsphere_host=vcenter.company.com](http://localhost:9272/metrics?vsphere_host=vcenter.company.com) to see metrics

Alternatively, if you don't wish to install the package, run it using `$ vmware_exporter/vmware_exporter.py` or use the following docker command:

```
```shell
docker run -it --rm -p 9272:9272 -e VSPHERE_USER=${VSPHERE_USERNAME} -e VSPHERE_PASSWORD=${VSPHERE_PASSWORD} -e VSPHERE_HOST=${VSPHERE_HOST} -e VSPHERE_IGNORE_SSL=True -e VSPHERE_SPECS_SIZE=2000 --name vmware_exporter pryorda/vmware_exporter
```

When using containers combined with `--env-file` flag, please use capital letters to set bolleans, for example:

```
```shell
$ podman run -it --rm -p 9272:9272 --name vmware_exporter --env-file config.env pryorda/vmware_exporter
$ cat config.env
[email protected]
Expand All @@ -44,24 +46,29 @@ VSPHERE_IGNORE_SSL=TRUE
VSPHERE_SPECS_SIZE=2000
```


### Configuration and limiting data collection

Only provide a configuration file if enviroment variables are not used. If you do plan to use a configuration file, be sure to override the container entrypoint or add -c config.yml to the command arguments.

If you want to limit the scope of the metrics gathered, you can update the subsystem under `collect_only` in the config section, e.g. under `default`, or by using the environment variables:

```yaml
collect_only:
vms: False
vmguests: True
datastores: True
hosts: True
snapshots: True
resourcepools: False
```

This would only connect datastores and hosts.

**WARNING**: Enabling resourcepools will have a significant performance penalty.

You can have multiple sections for different hosts and the configuration would look like:
```

```yaml
default:
vsphere_host: "vcenter"
vsphere_user: "user"
Expand All @@ -77,6 +84,7 @@ default:
datastores: True
hosts: True
snapshots: True
resourcepools: True

esx:
vsphere_host: vc.example2.com
Expand All @@ -93,6 +101,7 @@ esx:
datastores: False
hosts: True
snapshots: True
resourcepools: False

limited:
vsphere_host: slowvc.example.com
Expand All @@ -109,52 +118,56 @@ limited:
datastores: True
hosts: False
snapshots: False

resourcepools: False
```

Switching sections can be done by adding ?section=limited to the URL.

#### Environment Variables
| Variable | Precedence | Defaults | Description |
| --------------------------------------| ---------------------- | -------- | --------------------------------------------------------------------------|
| `VSPHERE_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_FETCH_ALARMS` | config, env | False | Fetch objects triggered alarms, and in case of hosts hdw alarms as well |
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |

| Variable | Precedence | Defaults | Description |
|-----------------------------------|------------------------|----------|---------------------------------------------------------------------------------|
| `VSPHERE_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_FETCH_ALARMS` | config, env | False | Fetch objects triggered alarms, and in case of hosts hdw alarms as well |
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |
| `VSPHERE_COLLECT_RESOURCEPOOLS` | config, env | True | Set to false to disable collection of resourcepool metrics |

You can create new sections as well, with very similiar variables. For example, to create a `limited` section you can set:

| Variable | Precedence | Defaults | Description |
| ----------------------------------------------| ---------------------- | -------- | --------------------------------------------------------------------------|
| `VSPHERE_LIMITED_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_LIMITED_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_LIMITED_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_LIMITED_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_LIMITED_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_LIMITED_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_LIMITED_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_LIMITED_FETCH_ALARMS` | config, env | False | Fetch objects triggered alarms, and in case of hosts hdw alarms as well |
| `VSPHERE_LIMITED_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_LIMITED_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_LIMITED_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_LIMITED_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_LIMITED_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |
| Variable | Precedence | Defaults | Description |
| ------------------------------------------| ---------------------- | -------- | ------------------------------------------------------------------------|
| `VSPHERE_LIMITED_HOST` | config, env, get_param | n/a | vsphere server to connect to |
| `VSPHERE_LIMITED_USER` | config, env | n/a | User for connecting to vsphere |
| `VSPHERE_LIMITED_PASSWORD` | config, env | n/a | Password for connecting to vsphere |
| `VSPHERE_LIMITED_SPECS_SIZE` | config, env | 5000 | Size of specs list for query stats function |
| `VSPHERE_LIMITED_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_LIMITED_FETCH_CUSTOM_ATTRIBUTES` | config, env | False | Set to true to collect objects custom attributes as metric labels |
| `VSPHERE_LIMITED_FETCH_TAGS` | config, env | False | Set to true to collect objects tags as metric labels |
| `VSPHERE_LIMITED_FETCH_ALARMS` | config, env | False | Fetch objects triggered alarms, and in case of hosts hdw alarms as well |
| `VSPHERE_LIMITED_COLLECT_HOSTS` | config, env | True | Set to false to disable collection of host metrics |
| `VSPHERE_LIMITED_COLLECT_DATASTORES` | config, env | True | Set to false to disable collection of datastore metrics |
| `VSPHERE_LIMITED_COLLECT_VMS` | config, env | True | Set to false to disable collection of virtual machine metrics |
| `VSPHERE_LIMITED_COLLECT_VMGUESTS` | config, env | True | Set to false to disable collection of virtual machine guest metrics |
| `VSPHERE_LIMITED_COLLECT_SNAPSHOTS` | config, env | True | Set to false to disable collection of snapshot metrics |
| `VSPHERE_LIMITED_COLLECT_RESOURCEPOOLS` | config, env | True | Set to false to disable collection of resourcepool metrics |

You need to set at least `VSPHERE_SECTIONNAME_USER` for the section to be detected.

### Prometheus configuration

You can use the following parameters in the Prometheus configuration file. The `params` section is used to manage multiple login/passwords.

```
```yaml
- job_name: 'vmware_vcenter'
metrics_path: '/metrics'
static_configs:
Expand Down Expand Up @@ -205,6 +218,7 @@ You can use the following parameters in the Prometheus configuration file. The `

- vCenter and vSphere 6.0/6.5 have been tested.
- VM information, Snapshot, Host and Datastore basic information is exported, i.e:

```
# HELP vmware_snapshots VMware current number of existing snapshots
# TYPE vmware_snapshot_count gauge
Expand Down Expand Up @@ -253,16 +267,18 @@ vmware_host_memory_max{host_name="esx1.company.com"} 131059.01953125
## References

The VMware exporter uses theses libraries:

- [pyVmomi](https://github.com/vmware/pyvmomi) for VMware connection
- Prometheus [client_python](https://github.com/prometheus/client_python) for Prometheus supervision
- [Twisted](http://twistedmatrix.com/trac/) for HTTP server

The initial code is mainly inspired by:
- https://www.robustperception.io/writing-a-jenkins-exporter-in-python/
- https://github.com/vmware/pyvmomi-community-samples
- https://github.com/jbidinger/pyvmomi-tools

Forked from https://github.com/rverchere/vmware_exporter. I removed the fork so that I could do searching and everything.
- [https://www.robustperception.io/writing-a-jenkins-exporter-in-python](https://www.robustperception.io/writing-a-jenkins-exporter-in-python/)
- [https://github.com/vmware/pyvmomi-community-samples](https://github.com/vmware/pyvmomi-community-samples)
- [https://github.com/jbidinger/pyvmomi-tools](https://github.com/jbidinger/pyvmomi-tools)

Forked from [rverchere/vmware_exporter](https://github.com/rverchere/vmware_exporter). I removed the fork so that I could do searching and everything.

## Maintainer

Expand Down
Loading