forked from prometheus-community/PushProx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.07 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
package main
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sync/errgroup"
"github.com/lawyzheng/promproxy/client"
)
func createMetric() prometheus.Counter {
counter := prometheus.NewCounter(prometheus.CounterOpts{
Name: "test_metrics",
Help: "metrics for testing",
})
go func() {
for {
counter.Add(1)
time.Sleep(1 * time.Second)
}
}()
return counter
}
// use prometheus default registry
func clientWithDefaultRegistry() error {
prometheus.MustRegister(createMetric())
c := client.New("client_with_default", "http://localhost:8080", nil)
return <-c.RunBackGround(context.Background())
}
// define you own registry
func clientWithCustomRegistry() error {
myRegistry := prometheus.NewRegistry()
myRegistry.MustRegister(createMetric())
c := client.New("client_with_custom", "http://localhost:8080", myRegistry)
return <-c.RunBackGround(context.Background())
}
func main() {
g := new(errgroup.Group)
g.Go(clientWithDefaultRegistry)
g.Go(clientWithCustomRegistry)
if err := g.Wait(); err != nil {
panic(err)
}
}