这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
FROM alpine:latest
MAINTAINER Sophos <hnlq.sysu@gmail.com>

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"
Expand Down
9 changes: 0 additions & 9 deletions Dockerfile-build

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
Expand Down
23 changes: 12 additions & 11 deletions nginx_vts_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down