Skip to content

Commit

Permalink
simplify main
Browse files Browse the repository at this point in the history
Signed-off-by: Zen <[email protected]>
  • Loading branch information
desultory committed Jan 20, 2024
1 parent da13028 commit 711f089
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "prometheus_exporter"
version = "0.13.0"
version = "0.13.2"
authors = [
{ name="Desultory", email="[email protected]" },
]
Expand All @@ -17,7 +17,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"zenlib >= 1.6.5",
"zenlib >= 1.7.0",
"aiohttp >= 3.9.1"
]

Expand Down
7 changes: 6 additions & 1 deletion src/prometheus_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
from .metric import Metric
from .labels import Labels

__all__ = ['Exporter', 'cached_exporter', 'Metric', 'Labels']
DEFAULT_EXPORTER_ARGS = [
{'flags': ['-p', '--port'], 'dest': 'listen_port', 'type': int, 'nargs': '?', 'help': 'Port to listen on.'},
{'flags': ['-a', '--address'], 'dest': 'listen_ip', 'type': str, 'nargs': '?', 'help': 'Address to listen on.'},
{'flags': ['config_file'], 'type': str, 'nargs': '?', 'help': 'Config file to use.'}]

__all__ = ['Exporter', 'cached_exporter', 'Metric', 'Labels', 'DEFAULT_EXPORTER_ARGS']
23 changes: 4 additions & 19 deletions src/prometheus_exporter/main.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
#!/usr/bin/env python3


from zenlib.util import init_logger, init_argparser, process_args

from zenlib.util import get_kwargs
from .exporter import Exporter
from .__init__ import DEFAULT_EXPORTER_ARGS


def main():
argparser = init_argparser(prog=__package__, description='Metric Exporter for Prometheus')
logger = init_logger(__package__)

argparser.add_argument('-p', '--port', type=int, nargs='?', help='Port to listen on.')
argparser.add_argument('-a', '--address', type=str, nargs='?', help='Address to listen on.')

args = process_args(argparser, logger=logger)

kwargs = {'logger': logger}

if args.port:
kwargs['listen_port'] = args.port
if args.address:
kwargs['listen_ip'] = args.address
kwargs = get_kwargs(package=__package__, description='Metric Exporter for Prometheus',
arguments=DEFAULT_EXPORTER_ARGS)

exporter = Exporter(**kwargs)
exporter.start()
Expand Down

0 comments on commit 711f089

Please sign in to comment.