Skip to content

Commit 0216cac

Browse files
committed
Initial commit
0 parents  commit 0216cac

File tree

4 files changed

+583
-0
lines changed

4 files changed

+583
-0
lines changed

Diff for: examples/main.go

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"time"
7+
8+
prom_http_exporter "github.com/pan-net-security/go-prometheus-http-exporter"
9+
"github.com/prometheus/client_golang/prometheus/promhttp"
10+
)
11+
12+
func foo(w http.ResponseWriter, r *http.Request) {
13+
time.Sleep(200 * time.Millisecond)
14+
w.WriteHeader(301)
15+
w.Write([]byte("foo"))
16+
}
17+
18+
func bar(w http.ResponseWriter, r *http.Request) {
19+
w.WriteHeader(401)
20+
w.Write([]byte("bar"))
21+
}
22+
23+
func main() {
24+
e := prom_http_exporter.New()
25+
26+
r := http.NewServeMux()
27+
r.Handle(e.Metric("/foo", foo))
28+
r.Handle(e.Metric("/bar", bar))
29+
r.Handle("/metrics", promhttp.Handler())
30+
31+
s := &http.Server{
32+
ReadTimeout: 5 * time.Second,
33+
WriteTimeout: 5 * time.Second,
34+
Handler: r,
35+
}
36+
log.Fatalln(http.ListenAndServe(":8080", s.Handler))
37+
}

Diff for: go.mod

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module github.com/pan-net-security/go-prometheus-http-exporter
2+
3+
go 1.17
4+
5+
require github.com/prometheus/client_golang v1.12.1
6+
7+
require (
8+
github.com/beorn7/perks v1.0.1 // indirect
9+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
10+
github.com/golang/protobuf v1.5.2 // indirect
11+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
12+
github.com/prometheus/client_model v0.2.0 // indirect
13+
github.com/prometheus/common v0.32.1 // indirect
14+
github.com/prometheus/procfs v0.7.3 // indirect
15+
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
16+
google.golang.org/protobuf v1.26.0 // indirect
17+
)

0 commit comments

Comments
 (0)