-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
59 lines (48 loc) · 1.9 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
"github.com/linki/instrumented_http"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/oauth2/google"
"google.golang.org/api/dns/v1"
)
func main() {
go func() {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe("127.0.0.1:9099", nil))
}()
defaultClient, err := google.DefaultClient(context.TODO(), dns.NdevClouddnsReadwriteScope)
if err != nil {
log.Fatal(err)
}
instrumentedClient := instrumented_http.NewClient(defaultClient, &instrumented_http.Callbacks{
PathProcessor: instrumented_http.LastPathElementProcessor,
})
dnsClient, err := dns.New(instrumentedClient)
if err != nil {
log.Fatal(err)
}
for {
zones, err := dnsClient.ManagedZones.List("<replace-with-your-google-project>").Do()
if err != nil {
log.Fatal(err)
}
for _, z := range zones.ManagedZones {
fmt.Println(z.Name)
}
time.Sleep(10 * time.Second)
}
}
// expected result:
//
// $ curl -Ss 127.0.0.1:9099/metrics | grep http
//
// http_request_duration_seconds{handler="instrumented_http",host="www.googleapis.com",method="GET",path="managedZones",query="",scheme="https",status="200",quantile="0.5"} 0.642468
// http_request_duration_seconds{handler="instrumented_http",host="www.googleapis.com",method="GET",path="managedZones",query="",scheme="https",status="200",quantile="0.9"} 0.660945
// http_request_duration_seconds{handler="instrumented_http",host="www.googleapis.com",method="GET",path="managedZones",query="",scheme="https",status="200",quantile="0.99"} 0.660945
// http_request_duration_seconds_sum{handler="instrumented_http",host="www.googleapis.com",method="GET",path="managedZones",query="",scheme="https",status="200"} 1.303413521
// http_request_duration_seconds_count{handler="instrumented_http",host="www.googleapis.com",method="GET",path="managedZones",query="",scheme="https",status="200"} 2