...
1 package server
2
3 import (
4 "flag"
5 "fmt"
6
7 "github.com/grafana/pyroscope-go"
8 "golang.conradwood.net/go-easyops/appinfo"
9 )
10
11 const (
12 pyroscope_port = 3900
13 )
14
15 var (
16 debug_pyroscope = flag.Bool("ge_debug_pyroscope", false, "if true print pyroscope messages stuff")
17 start_pyroscope = flag.Bool("ge_start_pyroscope", false, "use ge-pyroscope:3900 to record hotspots")
18 pyroscope_host = flag.String("ge_pyroscope_host", "ge-pyroscope", "use `hostname`:3900 to record hotspots")
19 )
20
21 func start_profiling(sd *serverDef) {
22 if *start_pyroscope {
23 pyro_url := fmt.Sprintf("http://%s:%d", *pyroscope_host, pyroscope_port)
24 pyroscope.Start(pyroscope.Config{
25 ApplicationName: sd.name,
26 ServerAddress: pyro_url,
27 Logger: &pyroLogger{},
28
29 Tags: map[string]string{
30 "service_user_id": fmt.Sprintf("%s", sd.service_user_id),
31 "artefactid": fmt.Sprintf("%d", appinfo.AppInfo().ArtefactID),
32 "version": fmt.Sprintf("%d", appinfo.AppInfo().Number),
33 },
34 })
35 fmt.Printf("[go-easyops] pyroscope started, connecting to host %s\n", pyro_url)
36 }
37 }
38
39 type pyroLogger struct {
40 }
41
42 func (*pyroLogger) Infof(a string, b ...interface{}) {
43 if !*debug_pyroscope {
44 return
45 }
46 fmt.Printf("[PYROSCOPE-INFO] "+a+"\n", b...)
47 }
48 func (*pyroLogger) Debugf(a string, b ...interface{}) {
49 if !*debug_pyroscope {
50 return
51 }
52 fmt.Printf("[PYROSCOPE-DEBUG] "+a+"\n", b...)
53 }
54 func (*pyroLogger) Errorf(a string, b ...interface{}) {
55 if !*debug_pyroscope {
56 return
57 }
58 fmt.Printf("[PYROSCOPE-ERROR] "+a+"\n", b...)
59 }
60
View as plain text