From bdd9766d0d7c660c6d2291e386e5470ad3c45e2b Mon Sep 17 00:00:00 2001 From: Nik Mikhaylichenko Date: Fri, 28 Apr 2023 15:55:58 +0300 Subject: [PATCH] feat: LOG_LEVEL env, bump poetry version, other small fixes --- Dockerfile | 2 +- app.py | 14 ++++++++++++-- docker-compose.yml | 3 ++- tmuxp.sh | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100755 tmuxp.sh diff --git a/Dockerfile b/Dockerfile index b9d9e65..f52650d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ ENV PYTHONDONTWRITEBYTECODE 1 WORKDIR /app RUN python -m venv venv && \ - pip install --no-cache-dir poetry==1.4.1 + pip install --no-cache-dir poetry==1.4.2 COPY pyproject.toml poetry.lock ./ diff --git a/app.py b/app.py index a059a1e..591832d 100644 --- a/app.py +++ b/app.py @@ -12,7 +12,6 @@ from prometheus_client import CollectorRegistry, push_to_gateway from urllib.parse import urljoin -logging.basicConfig(level='INFO') PUSHGATEWAY_URL = os.environ.get('PUSHGATEWAY_URL', 'http://pushgateway:9091') PUSHGATEWAY_BASIC_AUTH_USERNAME = os.environ.get( @@ -30,6 +29,12 @@ JOB_PREFIX = os.environ.get('JOB_PREFIX', 'env') +LOG_LEVEL = os.environ.get('LOG_LEVEL', 'INFO') + +logging.basicConfig(level=LOG_LEVEL) + +logging.info(f'Gate UP!') + def project_containers(): ''' @@ -88,7 +93,11 @@ def push_gateway_handler(url, method, timeout, headers, data): while True: time.sleep(SCRAPE_INTERVAL) - for container in project_containers(): + containers = project_containers() + if len(containers) == 0: + logging.info('There are no project containers') + continue + for container in containers: # --- specify the metrics url port, path = get_container_scrape_params(container) url = urljoin(f'http://{container.name}:{port}', path) @@ -102,3 +111,4 @@ def push_gateway_handler(url, method, timeout, headers, data): job=f'{JOB_PREFIX}-{container.name}', registry=registry, handler=push_gateway_handler) + diff --git a/docker-compose.yml b/docker-compose.yml index ec149b9..e847724 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,8 @@ services: - /var/run/docker.sock:/tmp/docker.sock:ro - ./:/app environment: - JOB_PREFIX: prod + JOB_PREFIX: test + # LOG_LEVEL: INFO # # --- push metrics to pushgateway with auth # PUSHGATEWAY_URL: http://pc-ip-address:19091 # PUSHGATEWAY_BASIC_AUTH_USERNAME: admin diff --git a/tmuxp.sh b/tmuxp.sh new file mode 100755 index 0000000..e3db348 --- /dev/null +++ b/tmuxp.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exec tmuxp load ./tmuxp.yaml