diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8afbefe --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.md +include requirements.txt diff --git a/README.md b/README.md index d5e4bc9..c8d52d7 100644 --- a/README.md +++ b/README.md @@ -9,10 +9,13 @@ Get VMWare VCenter information: ## 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. -- Run `$ python vmware_exporter.py` +- Run `$ vmware_exporter -c /path/to/your/config` - Go to http://localhost:9272/metrics?target=vcenter.company.com to see metrics +Alternatively, if you don't wish to install the package, run using `$ vmware_exporter/vmware_exporter.py` + ### Prometheus configuration You can use the following parameters in prometheus configuration file. The `params` section is used to manage multiple login/passwords. diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..71ebe05 --- /dev/null +++ b/setup.py @@ -0,0 +1,23 @@ +from setuptools import setup, find_packages +import vmware_exporter + +setup( + name='vmware_exporter', + version=vmware_exporter.__version__, + author=vmware_exporter.__author__, + description='VMWare VCenter Exporter for Prometheus', + long_description=open('README.md').read(), + url='https://github.com/rverchere/vmware_exporter', + download_url=("https://github.com/rverchere/vmware_exporter/tarball/%s" % + vmware_exporter.__version__), + keywords=['VMWare', 'VCenter', 'Prometheus'], + license=vmware_exporter.__license__, + packages=find_packages(exclude=['*.test', '*.test.*']), + include_package_data=True, + install_requires=open('requirements.txt').readlines(), + entry_points={ + 'console_scripts': [ + 'vmware_exporter=vmware_exporter.vmware_exporter:main' + ] + } +) diff --git a/vmware_exporter/__init__.py b/vmware_exporter/__init__.py new file mode 100644 index 0000000..505a9c9 --- /dev/null +++ b/vmware_exporter/__init__.py @@ -0,0 +1,3 @@ +__version__ = "0.1.0" +__author__ = "Remi Verchere" +__license__ = "BSD 3-Clause License" diff --git a/vmware_exporter.py b/vmware_exporter/vmware_exporter.py similarity index 98% rename from vmware_exporter.py rename to vmware_exporter/vmware_exporter.py index 53de39d..2419125 100755 --- a/vmware_exporter.py +++ b/vmware_exporter/vmware_exporter.py @@ -11,7 +11,6 @@ import sys import time -from argparse import ArgumentParser from datetime import datetime from yamlconfig import YamlConfig @@ -36,7 +35,7 @@ class VMWareMetricsResource(Resource): """ isLeaf = True - def __init__(self): + def __init__(self, args): try: self.config = YamlConfig(args.config_file) if 'default' not in self.config.keys(): @@ -419,21 +418,24 @@ def _vmware_get_hosts(self, content, host_metrics): float(summary.hardware.memorySize) / 1024 / 1024) - -if __name__ == '__main__': - parser = ArgumentParser(description='VMWare metrics exporter for Prometheus') +def main(): + parser = argparse.ArgumentParser(description='VMWare metrics exporter for Prometheus') parser.add_argument('-c', '--config', dest='config_file', default='config.yml', help="configuration file") parser.add_argument('-p', '--port', dest='port', type=int, default=9272, help="HTTP port to expose metrics") - args = parser.parse_args(sys.argv[1:]) + args = parser.parse_args() # Start up the server to expose the metrics. root = Resource() - root.putChild(b'metrics', VMWareMetricsResource()) + root.putChild(b'metrics', VMWareMetricsResource(args)) factory = Site(root) print("Starting web server on port {}".format(args.port)) - reactor.listenTCP(args.port, factory) - reactor.run() + #reactor.listenTCP(args.port, factory) + #reactor.run() + + +if __name__ == '__main__': + main()