From 4b52934656303943c37c01e2db50053026d8c642 Mon Sep 17 00:00:00 2001 From: Flavio Meyer Date: Tue, 1 Sep 2020 12:55:11 +0200 Subject: [PATCH 1/4] Adjust import of dutchcoders/go-clamd dependency --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index 8025085..25e5104 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,9 @@ FROM golang:alpine # Update RUN apk update upgrade; +# Install git +RUN apk add git + # Set timezone to Europe/Zurich RUN apk add tzdata RUN ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime @@ -21,6 +24,7 @@ RUN freshclam --quiet --no-dns # Build go package ADD . /go/src/clamav-rest/ +RUN go get github.com/dutchcoders/go-clamd ADD ./server.* /etc/ssl/clamav-rest/ RUN cd /go/src/clamav-rest && go build -v From ae6687b7d2c87a1828373a7f94d6c329dec7b389 Mon Sep 17 00:00:00 2001 From: Flavio Meyer Date: Tue, 1 Sep 2020 12:56:35 +0200 Subject: [PATCH 2/4] Implement Prometheus metrics --- Dockerfile | 1 + clamrest.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Dockerfile b/Dockerfile index 25e5104..1fb87b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,7 @@ RUN freshclam --quiet --no-dns # Build go package ADD . /go/src/clamav-rest/ RUN go get github.com/dutchcoders/go-clamd +RUN go get github.com/prometheus/client_golang/prometheus/promhttp ADD ./server.* /etc/ssl/clamav-rest/ RUN cd /go/src/clamav-rest && go build -v diff --git a/clamrest.go b/clamrest.go index a58d659..43aa1b3 100644 --- a/clamrest.go +++ b/clamrest.go @@ -12,6 +12,7 @@ import ( "time" "github.com/dutchcoders/go-clamd" + "github.com/prometheus/client_golang/prometheus/promhttp" ) var opts map[string]string @@ -184,6 +185,9 @@ func main() { http.HandleFunc("/scanPath", scanPathHandler) http.HandleFunc("/", home) + // Prometheus metrics + http.Handle("/metrics", promhttp.Handler()) + // Start the HTTPS server in a goroutine go http.ListenAndServeTLS(SSL_PORT, "/etc/ssl/clamav-rest/server.crt", "/etc/ssl/clamav-rest/server.key", nil) From 83906fe937ed9ded1a3d8064f776f56b6dfcfe33 Mon Sep 17 00:00:00 2001 From: Flavio Meyer Date: Tue, 1 Sep 2020 13:08:10 +0200 Subject: [PATCH 3/4] Update README with Prometheus --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed8b454..abf7b62 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,9 @@ - [Configuration](#configuration) - [Environment Variables](#environment-variables) - [Networking](#networking) -- [Maintenance](#maintenance) +- [Maintenance / Monitoring](#maintenance-/-monitoring) - [Shell Access](#shell-access) + - [Developing](#developing) - [References](#references) @@ -134,7 +135,7 @@ Below is the complete list of available options that can be used to customize yo |-----------|-------------| | `3310` | ClamD Listening Port | -# Maintenance +# Maintenance / Monitoring ## Shell Access @@ -143,6 +144,15 @@ For debugging and maintenance purposes you may want access the containers shell. ```bash docker exec -it (whatever your container name is e.g. clamav-rest) /bin/sh ``` +## Prometheus + +[Prometheus metrics](https://prometheus.io/docs/guides/go-application/) were implemented, which can be retrieved as follows + +**HTTP**: +curl http://localhost:9000/metrics + +**HTTPS:** +curl https://localhost:9443/metrics # Developing From f52cca384136aaebd3cf5caf77fd1f11a42c0929 Mon Sep 17 00:00:00 2001 From: Flavio Meyer Date: Tue, 1 Sep 2020 13:10:56 +0200 Subject: [PATCH 4/4] Update table of contents with the correct link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index abf7b62..411c7d7 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ - [Configuration](#configuration) - [Environment Variables](#environment-variables) - [Networking](#networking) -- [Maintenance / Monitoring](#maintenance-/-monitoring) +- [Maintenance / Monitoring](#maintenance--monitoring) - [Shell Access](#shell-access) - [Developing](#developing)