Skip to content

Commit

Permalink
Add a healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelosthege committed May 21, 2024
1 parent c47a05a commit 463a2e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ COPY requirements.txt /tmp
RUN pip3 install --no-cache-dir -r /tmp/requirements.txt

COPY exporter.py /usr/local/bin/homematic_exporter
COPY healthcheck.sh /usr/local/bin/healthcheck.sh

ENTRYPOINT [ "/usr/local/bin/homematic_exporter" ]

EXPOSE 8010
HEALTHCHECK --interval=20s --timeout=3s \
CMD bash /usr/local/bin/healthcheck.sh
14 changes: 14 additions & 0 deletions healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# First argument is the maximum age in seconds (default: 60)
maxage=${1:-60}

# Get the age of the last successful metrics refresh in seconds
age=$(curl -s http://localhost:9040/metrics | grep 'homematic_refresh_age{' | cut -d ' ' -f2 | cut -d '.' -f1)

if [[ $age -lt $maxage ]]; then
exit 0
else
# Maximum age exceeded → unhealthy
exit 1
fi

0 comments on commit 463a2e8

Please sign in to comment.