-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from sfudeus/add_refresh_age_metric
Add refresh age metric and healthcheck
- Loading branch information
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
FROM python:3.12-slim-bookworm | ||
COPY requirements.txt /tmp | ||
RUN apt-get update && apt-get install curl -y | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_seconds{' | cut -d ' ' -f2 | cut -d '.' -f1) | ||
|
||
if [[ $age -lt $maxage ]]; then | ||
exit 0 | ||
else | ||
# Maximum age exceeded → unhealthy | ||
exit 1 | ||
fi |