Skip to content

Commit

Permalink
Merge pull request #5 from brancz/master
Browse files Browse the repository at this point in the history
Bring in latest upstream changes
  • Loading branch information
bison authored Dec 15, 2021
2 parents 6b20adb + 68b3fae commit 1250a5b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.0
v0.4.0
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module github.com/rhobs/prometheus-example-app

go 1.13

require github.com/prometheus/client_golang v1.3.0
require (
github.com/prometheus/client_golang v1.3.0
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980
)

replace github.com/prometheus/client_golang => github.com/prometheus/client_golang v1.3.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f h1:68K/z8GLUxV76xGSqwTWw2gyk/jwn79LUL43rES2g8o=
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
22 changes: 17 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)

var (
appVersion string
version = prometheus.NewGauge(prometheus.GaugeOpts{
version = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "version",
Help: "Version information about this binary",
ConstLabels: map[string]string{
Expand All @@ -34,8 +36,10 @@ var (
func main() {
version.Set(1)
bind := ""
enableH2c := false
flagset := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flagset.StringVar(&bind, "bind", ":8080", "The socket to bind to.")
flagset.BoolVar(&enableH2c, "h2c", false, "Enable h2c (http/2 over tcp) protocol.")
flagset.Parse(os.Args[1:])

r := prometheus.NewRegistry()
Expand All @@ -56,9 +60,17 @@ func main() {
promhttp.InstrumentHandlerCounter(httpRequestsTotal, foundHandler),
)

http.Handle("/", foundChain)
http.Handle("/err", promhttp.InstrumentHandlerCounter(httpRequestsTotal, notfoundHandler))
mux := http.NewServeMux()
mux.Handle("/", foundChain)
mux.Handle("/err", promhttp.InstrumentHandlerCounter(httpRequestsTotal, notfoundHandler))
mux.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))

http.Handle("/metrics", promhttp.HandlerFor(r, promhttp.HandlerOpts{}))
log.Fatal(http.ListenAndServe(bind, nil))
var srv *http.Server
if enableH2c {
srv = &http.Server{Addr: bind, Handler: h2c.NewHandler(mux, &http2.Server{})}
} else {
srv = &http.Server{Addr: bind, Handler: mux}
}

log.Fatal(srv.ListenAndServe())
}

0 comments on commit 1250a5b

Please sign in to comment.