diff --git a/README.md b/README.md index 569b970..33dccaa 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,30 @@ controlled through environment variables. - PROMTAIL_LABEL_HOST=localbeach-${BEACH_PROJECT_NAME} ``` +## Testing with docker run + +Create a directory "test" on your local machine. Within that directory +create a file "test.log". + +Then run Promtail with `docker run`: + +```bash +docker run -v $(pwd)/logs:/logs \ + -e PROMTAIL_SCRAPE_PATH=/logs/test.log \ + -e PROMTAIL_CLIENT_URL=https://logs-prod-us-central1.grafana.net/loki/api/v1/push \ + -e PROMTAIL_BASIC_AUTH_USERNAME=loki-username \ + -e PROMTAIL_BASIC_AUTH_PASSWORD=loki-password \ + -e PROMTAIL_LABEL_JOB=test-job \ + flownative/promtail +``` + +In a separate terminal, add test content to the log file, for example with +`echo "some test" >> logs/test.log`. + ### Environment variables | Variable Name | Type | Default | Description | -| ---------------------------- | ------ | ---------------------------------------- | ------------------------------------------------------------------- | +|------------------------------|--------|------------------------------------------|---------------------------------------------------------------------| | PROMTAIL_CLIENT_URL | string | http://loki_loki_1:3100/loki/api/v1/push | URL pointing to the Loki push endpoint | | PROMTAIL_LABEL_HOST | string | $(hostname) | Value of the label "host" which is added to all log entries | | PROMTAIL_LABEL_JOB | string | promtail | Value of the label "job" which is added to all log entries | @@ -37,6 +57,7 @@ controlled through environment variables. | PROMTAIL_CLIENT_TENANT_ID | string | | An optional tenant id to sent as the `X-Scope-OrgID`-header | | PROMTAIL_BASIC_AUTH_USERNAME | string | | Username to use for basic auth, if required by Loki | | PROMTAIL_BASIC_AUTH_PASSWORD | string | | Password to use for basic auth, if required by Loki | +| PROMTAIL_SCRAPE_PATH | string | /application/Data/Logs/*.log | Path leading to log files to be scraped; supports glob syntax | ## Security aspects diff --git a/root-files/entrypoint.sh b/root-files/entrypoint.sh index d599b09..9ffbf43 100755 --- a/root-files/entrypoint.sh +++ b/root-files/entrypoint.sh @@ -14,7 +14,7 @@ banner_flownative Promtail eval "$(promtail_env)" eval "$(supervisor_env)" -# promtail_initialize +promtail_initialize supervisor_initialize supervisor_start diff --git a/root-files/opt/flownative/lib/promtail.sh b/root-files/opt/flownative/lib/promtail.sh index d5487a5..4e5f278 100755 --- a/root-files/opt/flownative/lib/promtail.sh +++ b/root-files/opt/flownative/lib/promtail.sh @@ -32,6 +32,7 @@ export PROMTAIL_LABEL_PROJECT="${PROMTAIL_LABEL_PROJECT:-}" export PROMTAIL_CLIENT_TENANT_ID="${PROMTAIL_CLIENT_TENANT_ID:-}" export PROMTAIL_BASIC_AUTH_USERNAME="${PROMTAIL_BASIC_AUTH_USERNAME:-}" export PROMTAIL_BASIC_AUTH_PASSWORD="${PROMTAIL_BASIC_AUTH_PASSWORD:-}" +export PROMTAIL_SCRAPE_PATH=${PROMTAIL_SCRAPE_PATH:-/application/Data/Logs/*.log} export PATH="${PATH}:${PROMTAIL_BASE_PATH}/bin" EOF @@ -45,4 +46,20 @@ EOF # promtail_initialize() { info "Promtail: Initializing ..." + + info "Will scrape logs found at ${PROMTAIL_SCRAPE_PATH}" + + path=$(dirname ${PROMTAIL_SCRAPE_PATH}) + if [ ! -d $path ]; then + warn "$path does not exist" + fi + + info "Logs will be sent to ${PROMTAIL_CLIENT_URL}" + + if [[ $PROMTAIL_BASIC_AUTH_USERNAME != "" && $PROMTAIL_BASIC_AUTH_PASSWORD != "" ]]; then + info "Will authenticate with username ${PROMTAIL_BASIC_AUTH_USERNAME} and a given password" + fi + if [[ $PROMTAIL_BASIC_AUTH_USERNAME != "" && $PROMTAIL_BASIC_AUTH_PASSWORD == "" ]]; then + warn "Authentication is configured to use username ${PROMTAIL_BASIC_AUTH_USERNAME} but no password was specified!" + fi } diff --git a/root-files/opt/flownative/promtail/etc/config.yaml b/root-files/opt/flownative/promtail/etc/config.yaml index 87d5916..990cd85 100644 --- a/root-files/opt/flownative/promtail/etc/config.yaml +++ b/root-files/opt/flownative/promtail/etc/config.yaml @@ -8,7 +8,7 @@ scrape_configs: organization: ${PROMTAIL_LABEL_ORGANIZATION} project: ${PROMTAIL_LABEL_PROJECT} host: ${PROMTAIL_LABEL_HOST} - __path__: /application/Data/Logs/*.log + __path__: ${PROMTAIL_SCRAPE_PATH} server: disable: true