Skip to content

Commit

Permalink
Merge pull request #14 from Cleafy/feature/dockerize-commands
Browse files Browse the repository at this point in the history
make Promrec container use log rotation and run using environment variables
  • Loading branch information
cravingPixels authored Jul 28, 2023
2 parents d07d44d + c51655d commit abe6b5f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15 as build
FROM golang:1.15 AS build

RUN apt update && apt install -yq go-dep

Expand All @@ -17,4 +17,15 @@ WORKDIR /promqueen

COPY --from=build $GOPATH/bin/promrec /promqueen

ENTRYPOINT ["/promqueen/promrec"]
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y logrotate findutils && rm -rf /var/lib/apt/lists/*

ARG METRICS_DIR="/var/log/cleafy/metrics"

RUN mkdir -p $METRICS_DIR

COPY log_rotate_conf.sh .
COPY rotate-metrics.sh .
COPY entrypoint.sh .

ENTRYPOINT ["./entrypoint.sh"]
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ Flags:
Period of time to store data for
```

### Environment variables

```PROM_ARGS```: The argument for the promqueen service. Output, interval and at least one service is mandatory.
- E.g. --output=/var/log/promqueen/metrics/metrics.prom --interval=30s -u serviceName1=URL1 -u serviceName2=URL2 ...


```ROTATION_FILE_LOG```: where the rotation should occurr. Must be the same of the "output" parameter in PROM_ARGS


```ROTATION_PERIOD```: how frequently a rotation will occurr. Default: "daily"

```ROTATION_COUNT```: how many rotation will be retained. Default: 10

```ROTATION_SIZE```: how big each rotation file will be in bytes. -1 means no limit. Default: -1. E.g. 100M


```
docker run -d --network=host --name promqueen \
-e ROTATION_FILE_LOG="/var/log/promqueen/metrics/metrics.prom" \
-e PROM_ARGS="--output=/var/log/promqueen/metrics/metrics.prom --interval=30s -u service1=URL1 -u service2=URL2" \
promqueen_image
```

### Notes

As of today **PromQueen** only supports backfilling inside _prometheus_ local storage. New storage types such as influxdb are not supported.
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

CONF_LOG_FILE=/etc/logrotate.d/metrics

touch $CONF_LOG_FILE

./log_rotate_conf.sh "$ROTATION_FILE_LOG" "${ROTATION_PERIOD:=daily}" "${ROTATION_COUNT:=10}" "${ROTATION_SIZE:=-1}" $CONF_LOG_FILE

source ./rotate-metrics.sh &

# shellcheck disable=SC2086
/promqueen/promrec $PROM_ARGS
31 changes: 31 additions & 0 deletions log_rotate_conf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

LOGFILE=$5

echo "LOG {
ROTATION_PERIOD
ROTATION_COUNT
ROTATION_SIZE
copytruncate
delaycompress
compress
notifempty
missingok
sharedscripts
}" > "$LOGFILE"


sed -i "s+LOG+$1+" "$LOGFILE"
sed -i "s/ROTATION_PERIOD/$2/" "$LOGFILE"
sed -i "s/ROTATION_COUNT/rotate $3/" "$LOGFILE"

if [[ $4 =~ ^[0-9]+[kMG]$ ]]; then
sed -i "s/ROTATION_SIZE/maxsize $4/" "$LOGFILE"

elif [[ $4 == -1 ]]; then
sed -i '4d' "$LOGFILE"

else
echo "rotation size $4 is not valid. Skipped configuration"
sed -i '4d' "$LOGFILE"
fi
7 changes: 7 additions & 0 deletions rotate-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

while true
do
logrotate /etc/logrotate.d/metrics
sleep 300 # 5 minutes
done

0 comments on commit abe6b5f

Please sign in to comment.