diff --git a/Dockerfile b/Dockerfile index d93a8d9..22e17fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,3 +2,10 @@ ARG ALPINE_VERSION=3.13.6 ARG BASE_IMAGE=sutty/monit FROM ${BASE_IMAGE}:${ALPINE_VERSION} MAINTAINER "f " + +RUN apk add --no-cache prometheus daemonize +COPY ./monit.conf /etc/monit.d/prometheus.conf +COPY ./prometheusd.sh /usr/local/bin/prometheusd + +EXPOSE 9090 +VOLUME /var/lib/prometheus diff --git a/monit.conf b/monit.conf new file mode 100644 index 0000000..e28a78f --- /dev/null +++ b/monit.conf @@ -0,0 +1,4 @@ +check process prometheus with pidfile /tmp/prometheus.pid + start program = "/usr/local/bin/prometheusd start" + stop program = "/usr/local/bin/prometheusd stop" + if 5 restarts within 8 cycles then alert diff --git a/prometheusd.sh b/prometheusd.sh new file mode 100755 index 0000000..6fee544 --- /dev/null +++ b/prometheusd.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +pid=/tmp/prometheus.pid +var=/var/lib/prometheus + +case $1 in + stop) + test -f "${pid}" || exit 0 + + cat "${pid}" | xargs -r kill + + rm "${pid}" + ;; + start) + rm -f "${pid}" + + chown prometheus:prometheus "${var}" + chmod -R u=rwX,g=rX,o= "${var}" + + daemonize -p "${pid}" -l "${pid}" -u prometheus -c "${var}" \ + /usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path="${var}/data" + ;; +esac + +exit $?