Skip to content

Commit

Permalink
Merge pull request #2 from flownative/configurable-scrape-path
Browse files Browse the repository at this point in the history
Configurable scrape path
  • Loading branch information
robertlemke authored Aug 31, 2022
2 parents 95a6290 + a9f4dbc commit 522eb67
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion root-files/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ banner_flownative Promtail
eval "$(promtail_env)"
eval "$(supervisor_env)"

# promtail_initialize
promtail_initialize

supervisor_initialize
supervisor_start
Expand Down
17 changes: 17 additions & 0 deletions root-files/opt/flownative/lib/promtail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion root-files/opt/flownative/promtail/etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 522eb67

Please sign in to comment.