Skip to content

Commit

Permalink
Add pyroscope support
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg committed Apr 10, 2023
1 parent 81c4c7b commit 299f5e9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ services:
volumes:
- ./docker/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml

pyroscope:
image: "pyroscope/pyroscope:latest"
ports:
- "4040:4040"
command:
- "server"

grafana:
build: ./docker/grafana/
environment:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/pyroscope-io/client v0.7.0 // indirect
github.com/pyroscope-io/godeltaprof v0.1.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/tdewolff/minify/v2 v2.7.1-0.20200112204046-70870d25a935 // indirect
github.com/tdewolff/parse/v2 v2.4.2 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/pyroscope-io/client v0.7.0 h1:LWuuqPQ1oa6x7BnmUOuo/aGwdX85QGhWZUBYWWW3zdk=
github.com/pyroscope-io/client v0.7.0/go.mod h1:4h21iOU4pUOq0prKyDlvYRL+SCKsBc5wKiEtV+rJGqU=
github.com/pyroscope-io/godeltaprof v0.1.0 h1:UBqtjt0yZi4jTxqZmLAs34XG6ycS3vUTlhEUSq4NHLE=
github.com/pyroscope-io/godeltaprof v0.1.0/go.mod h1:psMITXp90+8pFenXkKIpNhrfmI9saQnPbba27VIaiQE=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
Expand Down
35 changes: 34 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"sort"
"strings"
"sync"
Expand All @@ -38,6 +39,7 @@ import (
"github.com/imdario/mergo"
"github.com/joho/godotenv"
"github.com/lpar/gzipped"
"github.com/pyroscope-io/client/pyroscope"

"github.com/tdewolff/canvas"
"github.com/tdewolff/canvas/rasterizer"
Expand Down Expand Up @@ -958,7 +960,6 @@ func IndexHTML() func(next http.Handler) http.Handler {
}

func main() {

startupTime = time.Now()

versionPtr := flag.Bool("version", false, "print version and exit")
Expand All @@ -975,6 +976,38 @@ func main() {

loadEnv()

if os.Getenv("PYROSCOPE_HOST") != "" {
log.Printf("pyroscope enabled at %s", os.Getenv("PYROSCOPE_HOST"))

// These 2 lines are only required if you're using mutex or block profiling
// Read the explanation below for how to set these rates:
runtime.SetMutexProfileFraction(5)
runtime.SetBlockProfileRate(5)

pyroscope.Start(pyroscope.Config{
ApplicationName: "photofield",
ServerAddress: os.Getenv("PYROSCOPE_HOST"),
Logger: nil,
AuthToken: os.Getenv("PYROSCOPE_AUTH_TOKEN"),
Tags: map[string]string{"hostname": os.Getenv("HOSTNAME")},
ProfileTypes: []pyroscope.ProfileType{
// these profile types are enabled by default:
pyroscope.ProfileCPU,
pyroscope.ProfileAllocObjects,
pyroscope.ProfileAllocSpace,
pyroscope.ProfileInuseObjects,
pyroscope.ProfileInuseSpace,

// these profile types are optional:
pyroscope.ProfileGoroutines,
pyroscope.ProfileMutexCount,
pyroscope.ProfileMutexDuration,
pyroscope.ProfileBlockCount,
pyroscope.ProfileBlockDuration,
},
})
}

if err := yaml.Unmarshal(defaultsYaml, &defaults); err != nil {
panic(err)
}
Expand Down

0 comments on commit 299f5e9

Please sign in to comment.