Skip to content

Commit

Permalink
flake8, adding precommit, and various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pryor committed Jun 27, 2018
1 parent 251e5ca commit 7d79dde
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 295 deletions.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
# Git state
- id: check-merge-conflict
stages: [commit]
- id: check-added-large-files
stages: [commit]
# Sensitive information
- id: detect-private-key
stages: [commit]
- id: detect-aws-credentials
stages: [commit]
# Generic file state
- id: trailing-whitespace
stages: [commit]
- id: mixed-line-ending
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
exclude: .*\.tfvars$ # terraform fmt separates everything with blank lines leaving a trailing line at the end
- id: check-executables-have-shebangs
stages: [commit]
# Language syntax/formatting
- id: check-yaml
stages: [commit]
- id: check-json
stages: [commit]
- id: pretty-format-json
stages: [commit]
args:
- --autofix
- id: flake8
stages: [commit]
- repo: https://github.com/mattlqx/pre-commit-sign
rev: v1.1.1
hooks:
- id: sign-commit
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 4
}
4 changes: 2 additions & 2 deletions Dockerfile
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ LABEL MAINTAINER Daniel Pryor <dpryor@pryorda.net>
WORKDIR /opt/vmware_exporter/

COPY . /opt/vmware_exporter/

RUN set -x; buildDeps="gcc python-dev musl-dev libffi-dev openssl openssl-dev" \
&& apk add --no-cache --update $buildDeps \
&& pip install -r requirements.txt \
&& apk del $buildDeps

EXPOSE 9272

ENTRYPOINT ["/opt/vmware_exporter/vmware_exporter/vmware_exporter.py", "-c", "/opt/vmware_exporter/config.yml"]
ENTRYPOINT ["/opt/vmware_exporter/vmware_exporter/vmware_exporter.py"]
82 changes: 65 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,76 @@ Get VMWare VCenter information:
- Datastore size and other stuff
- Basic VM and Host metrics

## Unmaintained

:warning: This projet needs maintainers! As I do not work anymore with Prometheus + VMWare actively, I cannot maintain this exporter on my free time. If you want to help, just fork and enhance it ;) :warning:

## Usage

- install with `$ python setup.py install` or `$ pip install vmware_exporter`
- Create a `config.yml` file based on the `config.yml.sample` with at least a `default` section.
- install with `$ python setup.py install` or `$ pip install vmware_exporter` (Installing from pip will install an old version. This is likely something I wont persue)
- Create a `config.yml` file based on the configuration section. Some variables can be passed in as environment variables
- Run `$ vmware_exporter -c /path/to/your/config`
- Go to http://localhost:9272/metrics?target=vcenter.company.com to see metrics
- Go to http://localhost:9272/metrics?vsphere_host=vcenter.company.com to see metrics

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

### Limiting data collection
```
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 --name vmware_exporter pryorda/vmware_exporter
```

Large installations may have trouble collecting all of the data in a timely fashion,
so you can limit which subsystems are collected by adding a
`collect_only` argument the config section, e.g. under `default`:
### Configuration amd limiting data collection

You do not need to provide a configuration file unless you are not going to use Environment variables. If you do plan to use a configuration file be sure to override the container entrypoint or add -c config.yml to the command args.

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

collect_only:
# - vms
- datastores
- hosts
vms: False
datastores: True
hosts: True

This would only connect datastores and hosts.

would skip collecting information on the VMs. If there is no `collect_only`
argument, everything will be collected as normal.
You can have multiple sections for different hosts and the configuration would look like:
```
default:
vsphere_host: "vcenter"
vsphere_user: "user"
vsphere_password: "password"
ignore_ssl: False
collect_only:
vms: True
datastores: True
hosts: True
esx:
vsphere_host: vc.example2.com
vsphere_user: 'root'
vsphere_password: 'password'
ignore_ssl: True
collect_only:
vms: False
datastores: False
hosts: True
limited:
vsphere_host: slowvc.example.com
vsphere_user: 'administrator@vsphere.local'
vsphere_password: 'password'
ignore_ssl: True
collect_only:
vms: False
datastores: True
hosts: False
```
Switching sections can be done by adding ?section=limited to the url.

#### Environment Variables
| Varible | 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_IGNORE_SSL` | config, env | False | Ignore the ssl cert on the connection to vsphere host |
| `VSPHERE_COLLECT_HOSTS` | config, env | True | Set to false to disable collect of hosts |
| `VSPHERE_COLLECT_DATASTORES` | config, env | True | Set to false to disable collect of datastores |
| `VSPHERE_COLLECT_VMS` | config, env | True | Set to false to disable collect of virtual machines |

### Prometheus configuration

Expand Down Expand Up @@ -129,6 +173,10 @@ The initial code is mainly inspired from:
- https://github.com/vmware/pyvmomi-community-samples
- https://github.com/jbidinger/pyvmomi-tools

#### Maintainer

Daniel Pryor [pryorda](https://github.com/pryorda)

## License

See LICENSE file
18 changes: 0 additions & 18 deletions config.yml.sample

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

prometheus-client==0.0.19
pytz
pyvmomi>=6.5
Expand Down
4 changes: 2 additions & 2 deletions vmware_exporter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.1.2"
__author__ = "Remi Verchere"
__version__ = "0.2.0"
__author__ = "Daniel Pryor"
__license__ = "BSD 3-Clause License"
29 changes: 29 additions & 0 deletions vmware_exporter/threader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import threading


class Threader(object):
"""
Takes method and data and threads it
"""
_thread = ''

def thread_it(self, method, data):
"""
Thread any method and data will be used as args
"""
self._thread = threading.Thread(target=method, args=(data))
self._thread.start()
if threading.active_count() >= 50:
self.join()

def join(self):
"""
join all threads and complete them
"""
try:
self._thread.join()
except RuntimeError:
# Thread terminated.
pass
except ReferenceError:
pass
Loading

0 comments on commit 7d79dde

Please sign in to comment.