Skip to content

Commit

Permalink
Merge pull request #51 from zazuko/prometheus-exporter
Browse files Browse the repository at this point in the history
Enable Prometheus exporter
  • Loading branch information
ludovicm67 authored Jun 24, 2024
2 parents b91b8e4 + 3db843d commit 5e189da
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fair-games-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"varnish-post": minor
---

Enable Prometheus Exporter by setting `ENABLE_PROMETHEUS_EXPORTER` to `true`.
21 changes: 20 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Build the prometheus_varnish_exporter binary
FROM docker.io/library/golang:1.22 as prometheus_varnish_exporter
WORKDIR /app

# Releases: https://github.com/jonnenauha/prometheus_varnish_exporter/releases
ARG PROMETHEUS_VARNISH_EXPORTER_VERSION=1.6.1

RUN git clone https://github.com/jonnenauha/prometheus_varnish_exporter.git . \
&& git checkout "${PROMETHEUS_VARNISH_EXPORTER_VERSION}" \
&& go mod download \
&& go build -o prometheus_varnish_exporter

# Build the final image
FROM docker.io/library/ubuntu:22.04

# Configuration
Expand All @@ -11,6 +24,7 @@ ENV DISABLE_ERROR_CACHING="true"
ENV DISABLE_ERROR_CACHING_TTL="30s"
ENV CONFIG_FILE="default.vcl"
ENV ENABLE_LOGS="true"
ENV ENABLE_PROMETHEUS_EXPORTER="false"

# Install some dependencies
RUN apt-get update \
Expand All @@ -21,11 +35,16 @@ RUN apt-get update \
varnish-modules \
&& apt-get clean

# Get the prometheus_varnish_exporter binary
COPY --from=prometheus_varnish_exporter \
/app/prometheus_varnish_exporter \
/usr/local/bin/prometheus_varnish_exporter

# Deploy our custom configuration
WORKDIR /etc/varnish
COPY config/ /templates
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

EXPOSE 80 8443
EXPOSE 80 8443 9131
ENTRYPOINT [ "tini", "--", "/entrypoint.sh" ]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ You can use following environment variables for configuration:
- `DISABLE_ERROR_CACHING_TTL`: time where requests should be directly sent to the backend after an error occured (default: `30s`)
- `CONFIG_FILE`: the name of the configuration file to use (default: `default.vcl`)
- `ENABLE_LOGS`: enable logs (default: `true`)
- `ENABLE_PROMETHEUS_EXPORTER`: enable the Prometheus exporter if set to `true` (default: `false`).
If enabled, the exporter will be available on the 9131 port.

## Cache invalidation

Expand Down
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh

ENABLE_LOGS="${ENABLE_LOGS}"
ENABLE_PROMETHEUS_EXPORTER="${ENABLE_PROMETHEUS_EXPORTER}"

set -eu

Expand All @@ -18,6 +19,13 @@ if [ "${ENABLE_LOGS}" = "true" ]; then
varnishncsa&
fi

# Start prometheus_varnish_exporter if enabled
if [ "${ENABLE_PROMETHEUS_EXPORTER}" = "true" ]; then
(sleep 2 && prometheus_varnish_exporter \
-web.listen-address ":9131" \
-web.telemetry-path "/metrics") &
fi

set -x

# Run Varnish
Expand Down

0 comments on commit 5e189da

Please sign in to comment.