Skip to content

Commit

Permalink
Lock dependencies (#33)
Browse files Browse the repository at this point in the history
* Use prometheus/common/log

The lib github.com/prometheus/log has been deprecated in favor of
github.com/prometheus/common/log.

* Lock external dependencies with dep tool

* Dockerfile: use dep tool, reduce context, indent
  • Loading branch information
wjkohnen authored and discordianfish committed Jan 8, 2018
1 parent 2142193 commit 40e9421
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
vendor
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nginx_exporter
vendor
30 changes: 19 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
FROM golang:1.9
LABEL maintainer="@discordianfish"
WORKDIR /go/src/github.com/discordianfish/nginx_exporter
ENV GOOS=linux CGO_ENABLED=0
COPY . .
RUN go get -d && go build
FROM golang:1.9
LABEL maintainer="@discordianfish"

# Install dep tool
ARG DEP_VERSION=v0.3.2
ARG DEP_SHA256=322152b8b50b26e5e3a7f6ebaeb75d9c11a747e64bbfd0d8bb1f4d89a031c2b5
RUN wget -q https://github.com/golang/dep/releases/download/${DEP_VERSION}/dep-linux-amd64 -O /usr/local/bin/dep \
&& echo "${DEP_SHA256} /usr/local/bin/dep" | sha256sum -c - \
&& chmod 755 /usr/local/bin/dep

FROM quay.io/prometheus/busybox:glibc
EXPOSE 9113
COPY --from=0 /go/src/github.com/discordianfish/nginx_exporter/nginx_exporter /bin/
USER nobody
ENTRYPOINT [ "/bin/nginx_exporter" ]
ENV GOOS=linux CGO_ENABLED=0
WORKDIR /go/src/github.com/discordianfish/nginx_exporter
COPY Gopkg.* *.go ./
RUN dep ensure --vendor-only \
&& go install

FROM quay.io/prometheus/busybox:glibc
EXPOSE 9113
COPY --from=0 /go/bin/nginx_exporter /usr/local/bin/
USER nobody
ENTRYPOINT [ "/usr/local/bin/nginx_exporter" ]
87 changes: 87 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[constraint]]
name = "github.com/prometheus/client_golang"
version = "0.8.0"

[[constraint]]
branch = "master"
name = "github.com/prometheus/common"
6 changes: 3 additions & 3 deletions nginx_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"sync"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/log"
"github.com/prometheus/common/log"
)

const (
Expand Down Expand Up @@ -167,7 +167,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.mutex.Lock() // To protect metrics from concurrent collects.
defer e.mutex.Unlock()
if err := e.collect(ch); err != nil {
log.Printf("Error scraping nginx: %s", err)
log.Errorf("Error scraping nginx: %s", err)
e.scrapeFailures.Inc()
e.scrapeFailures.Collect(ch)
}
Expand All @@ -182,7 +182,7 @@ func main() {
exporter := NewExporter(*nginxScrapeURI)
prometheus.MustRegister(exporter)

log.Printf("Starting Server: %s", *listeningAddress)
log.Infof("Starting Server: %s", *listeningAddress)
http.Handle(*metricsEndpoint, prometheus.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
Expand Down

0 comments on commit 40e9421

Please sign in to comment.