-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (79 loc) · 2.58 KB
/
main.go
File metadata and controls
88 lines (79 loc) · 2.58 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2019 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/pprof"
"time"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
registerProcessMetrics = flag.Bool(
"enable-process-metrics", true,
"Include (potentially expensive) process_* metrics.",
)
registerGoMetrics = flag.Bool(
"enable-go-metrics", true,
"Include (potentially expensive) go_* metrics.",
)
allowCompression = flag.Bool(
"allow-metrics-compression", true,
"Allow gzip compression of metrics.",
)
numEndpoints = flag.Int(
"num-endpoints", 50,
"Number of API endpoints to generate (e.g., /api/service-1, /api/service-2, ...).",
)
numRegions = flag.Int(
"num-regions", 5,
"Number of region labels to generate (e.g., us-east-1, us-west-1, ...).",
)
numVersions = flag.Int(
"num-versions", 3,
"Number of version labels to generate (e.g., v1.0.0, v1.1.0, ...).",
)
start = time.Now()
)
func main() {
flag.Parse()
if *registerProcessMetrics {
registry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
}
if *registerGoMetrics {
registry.MustRegister(collectors.NewGoCollector())
}
mux := http.NewServeMux()
mux.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("This is a fake webserver to generate metrics data. Please use the /metrics endpoint to get the metrics data."))
}))
mux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
mux.Handle("/metrics", promhttp.HandlerFor(
registry,
promhttp.HandlerOpts{
DisableCompression: !*allowCompression,
},
))
go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", 8080), mux))
}()
runClient()
}