Skip to content

Commit

Permalink
Use flags instead of positional arguments for config file and listen …
Browse files Browse the repository at this point in the history
…address (#190)

* Use flags instead of positional arguments for config file and listen address

* Adapt docker image for changed arguments
  • Loading branch information
znerol authored Nov 5, 2023
1 parent 1452f99 commit ded9219
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ USER prometheus
EXPOSE 9221

ENTRYPOINT [ "/usr/bin/pve_exporter" ]

CMD [ "/etc/pve.yml" ]
13 changes: 7 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,18 @@ Usage
[--collector.cluster | --no-collector.cluster]
[--collector.resources | --no-collector.resources]
[--collector.config | --no-collector.config]
[--config.file CONFIG_FILE]
[--web.listen-address WEB_LISTEN_ADDRESS]
[--server.keyfile SERVER_KEYFILE]
[--server.certfile SERVER_CERTFILE]
[config] [port] [address]

positional arguments:
config Path to configuration file (pve.yml)
port Port on which the exporter is listening (9221)
address Address to which the exporter will bind

options:
-h, --help show this help message and exit
--config.file CONFIG_FILE
Path to config file (/etc/prometheus/pve.yml)
--web.listen-address WEB_LISTEN_ADDRESS
Address on which to expose metrics and web server.
([::]:9221)
--server.keyfile SERVER_KEYFILE
SSL key for server
--server.certfile SERVER_CERTFILE
Expand Down
20 changes: 12 additions & 8 deletions src/pve_exporter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from argparse import ArgumentParser, BooleanOptionalAction
import os
import pathlib
import yaml
from pve_exporter.http import start_http_server
from pve_exporter.config import config_from_yaml
Expand Down Expand Up @@ -45,13 +46,16 @@ def main():
action=BooleanOptionalAction, default=True,
help='Exposes PVE onboot status')

parser.add_argument('config', nargs='?', default='pve.yml',
help='Path to configuration file (pve.yml)')
parser.add_argument('--config.file', type=pathlib.Path,
dest="config_file", default='/etc/prometheus/pve.yml',
help='Path to config file (/etc/prometheus/pve.yml)')

parser.add_argument('port', nargs='?', type=int, default='9221',
help='Port on which the exporter is listening (9221)')
parser.add_argument('address', nargs='?', default='',
help='Address to which the exporter will bind')
parser.add_argument('--web.listen-address',
dest="web_listen_address", default='[::]:9221',
help=(
'Address on which to expose metrics and web server. '
'([::]:9221)'
))
parser.add_argument('--server.keyfile', dest='server_keyfile',
help='SSL key for server')
parser.add_argument('--server.certfile', dest='server_certfile',
Expand All @@ -72,11 +76,11 @@ def main():
if 'PVE_USER' in os.environ:
config = config_from_env(os.environ)
else:
with open(params.config, encoding='utf-8') as handle:
with open(params.config_file, encoding='utf-8') as handle:
config = config_from_yaml(yaml.safe_load(handle))

gunicorn_options = {
'bind': f'{params.address}:{params.port}',
'bind': f'{params.web_listen_address}',
'threads': 2,
'keyfile': params.server_keyfile,
'certfile': params.server_certfile,
Expand Down

0 comments on commit ded9219

Please sign in to comment.