mirror of https://github.com/statping/statping
Docker healthcheck
parent
5502179144
commit
41f944c237
|
@ -2,11 +2,14 @@ ARG VERSION
|
||||||
FROM hunterlong/statup:base-v${VERSION}
|
FROM hunterlong/statup:base-v${VERSION}
|
||||||
MAINTAINER "Hunter Long (https://github.com/hunterlong)"
|
MAINTAINER "Hunter Long (https://github.com/hunterlong)"
|
||||||
|
|
||||||
# Locked version of Statup for 'latest' Docker tag
|
RUN apk --no-cache add curl jq
|
||||||
ENV IS_DOCKER=true
|
ENV IS_DOCKER=true
|
||||||
ENV STATUP_DIR=/app
|
ENV STATUP_DIR=/app
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME /app
|
VOLUME /app
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:8080/health" | jq -r -e ".online==true"
|
||||||
|
|
||||||
CMD ["statup"]
|
CMD ["statup"]
|
||||||
|
|
|
@ -4,7 +4,7 @@ MAINTAINER "Hunter Long (https://github.com/hunterlong)"
|
||||||
# Statup 'test' image for running a full test using the production environment
|
# Statup 'test' image for running a full test using the production environment
|
||||||
|
|
||||||
ENV DEP_VERSION=v0.5.0
|
ENV DEP_VERSION=v0.5.0
|
||||||
RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl
|
RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl jq
|
||||||
|
|
||||||
RUN curl -L -s https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 -o /go/bin/dep && \
|
RUN curl -L -s https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 -o /go/bin/dep && \
|
||||||
chmod +x /go/bin/dep
|
chmod +x /go/bin/dep
|
||||||
|
@ -25,4 +25,7 @@ RUN make install
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
VOLUME /app
|
VOLUME /app
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:8080/health" | jq -r -e ".online==true"
|
||||||
|
|
||||||
ENTRYPOINT statup
|
ENTRYPOINT statup
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/hunterlong/statup/core"
|
"github.com/hunterlong/statup/core"
|
||||||
"github.com/hunterlong/statup/types"
|
"github.com/hunterlong/statup/types"
|
||||||
"github.com/hunterlong/statup/utils"
|
"github.com/hunterlong/statup/utils"
|
||||||
|
@ -30,6 +31,15 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
executeResponse(w, r, "index.html", core.CoreApp, nil)
|
executeResponse(w, r, "index.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
health := map[string]interface{}{
|
||||||
|
"services": len(core.Services()),
|
||||||
|
"online": core.Configs != nil,
|
||||||
|
}
|
||||||
|
json.NewEncoder(w).Encode(health)
|
||||||
|
}
|
||||||
|
|
||||||
func trayHandler(w http.ResponseWriter, r *http.Request) {
|
func trayHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
executeResponse(w, r, "tray.html", core.CoreApp, nil)
|
executeResponse(w, r, "tray.html", core.CoreApp, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,6 +119,7 @@ func Router() *mux.Router {
|
||||||
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("POST")
|
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("POST")
|
||||||
|
|
||||||
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
|
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
|
||||||
|
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
|
||||||
r.Handle("/tray", http.HandlerFunc(trayHandler))
|
r.Handle("/tray", http.HandlerFunc(trayHandler))
|
||||||
r.NotFoundHandler = http.HandlerFunc(error404Handler)
|
r.NotFoundHandler = http.HandlerFunc(error404Handler)
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in New Issue