From da3b5343064ccba5cf7194d32eac949af3d80c83 Mon Sep 17 00:00:00 2001 From: zoues Date: Sun, 12 Mar 2017 20:20:49 +0800 Subject: [PATCH 1/5] add s.Server add upstream host --- nginx_vts_exporter.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 From 6bfed1a8455910ea5616c088f45010b90e731e0b Mon Sep 17 00:00:00 2001 From: zoues Date: Sun, 12 Mar 2017 20:21:34 +0800 Subject: [PATCH 2/5] Update docker-entrypoint.sh --- docker-entrypoint.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 9dd8966..aa759e1 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,10 +6,7 @@ NGINX_STATUS=${NGINX_STATUS:-$default_status} METRICS_NS=${METRICS_NS:-$DEFAULT_METRICS_NS} VERSION=${VERSION:-$DEFAULT_VERSION} -wget https://github.com/hnlq715/nginx-vts-exporter/releases/download/${VERSION}/nginx-vts-exporter-linux-amd64.tar.gz -tar xf nginx-vts-exporter-linux-amd64.tar.gz -mv nginx-vts-exporter-linux-amd64 $binary -rm nginx-vts-exporter-linux-amd64.tar.gz + # If there are any arguments then we want to run those instead #if [[ "$1" == "$binary" || -z $1 ]]; then # exec "$@" From 7158fa986e43554ae069fc579dbcd928695fe930 Mon Sep 17 00:00:00 2001 From: zoues Date: Sun, 12 Mar 2017 20:42:17 +0800 Subject: [PATCH 3/5] drop it --- Dockerfile | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 203000a..0000000 --- a/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM alpine:3.4 - -# Creating directory for our application -RUN mkdir /app - -# Copying entrypoint script -COPY ./docker-entrypoint.sh /app/ - -ENV NGIX_HOST http://localhost -ENV METRICS_ENDPOINT "/metrics" -ENV METRICS_ADDR ":9913" -ENV DEFAULT_METRICS_NS "nginx" -ENV DEFAULT_VERSION "v0.4" - -EXPOSE 9913 - -ENTRYPOINT ["/app/docker-entrypoint.sh"] From a6b363f16a2b3c882f9f568d0951082c0a43970b Mon Sep 17 00:00:00 2001 From: zoues Date: Sun, 12 Mar 2017 20:43:27 +0800 Subject: [PATCH 4/5] Update and rename Dockerfile-build to Dockerfile --- Dockerfile | 21 +++++++++++++++++++++ Dockerfile-build | 9 --------- 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 Dockerfile delete mode 100644 Dockerfile-build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a37964d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:alpine + +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" +ENV DEFAULT_VERSION "v0.4" + +EXPOSE 9913 + +ENTRYPOINT ["/app/docker-entrypoint.sh"] 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/ From 411acc7738ac4cd7e4ea0dfcb068e6f9a84caa4d Mon Sep 17 00:00:00 2001 From: zoues Date: Sun, 12 Mar 2017 20:56:30 +0800 Subject: [PATCH 5/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 39578df..d06f236 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,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