diff --git a/Dockerfile b/Dockerfile index 850c811..10ca1a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,16 @@ -FROM alpine:latest -MAINTAINER Sophos -WORKDIR /bin -COPY bin/nginx-vts-exporter /bin/ -COPY docker-entrypoint.sh /bin/ -RUN chmod +x /bin/nginx-vts-exporter +FROM golang:alpine -ENV NGINX_HOST "http://localhost" +RUN apk --no-cache --update add git ca-certificates +WORKDIR $GOPATH/src/app/ +ADD . . +RUN go get -v +RUN mkdir /app +RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o nginx-vts-exporter . +RUN mv $GOPATH/src/app/nginx-vts-exporter /app/ + +COPY ./docker-entrypoint.sh /app/ +ENV NGIX_HOST http://localhost ENV METRICS_ENDPOINT "/metrics" ENV METRICS_ADDR ":9913" ENV DEFAULT_METRICS_NS "nginx" diff --git a/Dockerfile-build b/Dockerfile-build deleted file mode 100644 index 0263737..0000000 --- a/Dockerfile-build +++ /dev/null @@ -1,9 +0,0 @@ -FROM golang:alpine - -RUN apk --no-cache --update add git ca-certificates -WORKDIR $GOPATH/src/app/ -ADD . . -RUN go get -v -RUN mkdir /build -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o nginx-vts-exporter . -RUN mv $GOPATH/src/app/nginx-vts-exporter /build/ diff --git a/README.md b/README.md index 3f10b1c..042eca3 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ docker build -t vts-export . ### Docker Run ``` shell -docker run -ti --rm --env NGIX_HOST="http://localhost/status/format/json" --env METRICS_NS="nginx_prod1" vts-export +docker run -ti --rm --env NGIX_STATUS="http://localhost/status/format/json" --env METRICS_NS="nginx_prod1" vts-export ``` ## Metrics diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5aaa2c5..21dcf3d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -4,6 +4,7 @@ default_status="$NGIX_HOST/status/format/json" NGINX_STATUS=${NGINX_STATUS:-$default_status} METRICS_NS=${METRICS_NS:-$DEFAULT_METRICS_NS} + # If there are any arguments then we want to run those instead #if [[ "$1" == "$binary" || -z $1 ]]; then # exec "$@" diff --git a/nginx_vts_exporter.go b/nginx_vts_exporter.go index a48e600..15911cf 100644 --- a/nginx_vts_exporter.go +++ b/nginx_vts_exporter.go @@ -173,8 +173,8 @@ func NewExporter(uri string) *Exporter { "cache": newServerMetric("cache", "cache counter", []string{"host", "status"}), }, upstreamMetrics: map[string]*prometheus.Desc{ - "requests": newUpstreamMetric("requests", "requests counter", []string{"upstream", "code"}), - "bytes": newUpstreamMetric("bytes", "request/response bytes", []string{"upstream", "direction"}), + "requests": newUpstreamMetric("requests", "requests counter", []string{"upstream", "code", "backend"}), + "bytes": newUpstreamMetric("bytes", "request/response bytes", []string{"upstream", "direction", "backend"}), "response": newUpstreamMetric("response", "request response time", []string{"upstream", "backend"}), }, cacheMetrics: map[string]*prometheus.Desc{ @@ -264,17 +264,18 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) { outbytes += float64(s.OutBytes) ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["response"], prometheus.GaugeValue, float64(s.ResponseMsec), name, s.Server) - } - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, total, name, "total") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, one, name, "1xx") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, two, name, "2xx") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, three, name, "3xx") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, four, name, "4xx") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, five, name, "5xx") + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, total, name, "total", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, one, name, "1xx", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, two, name, "2xx", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, three, name, "3xx", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, four, name, "4xx", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["requests"], prometheus.CounterValue, five, name, "5xx", s.Server) + + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["bytes"], prometheus.CounterValue, inbytes, name, "in", s.Server) + ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["bytes"], prometheus.CounterValue, outbytes, name, "out", s.Server) - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["bytes"], prometheus.CounterValue, inbytes, name, "in") - ch <- prometheus.MustNewConstMetric(e.upstreamMetrics["bytes"], prometheus.CounterValue, outbytes, name, "out") + } } // CacheZones