File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -117,4 +117,11 @@ func init() {
117117 os .Getenv ("API_TOKEN" ),
118118 "Token used for authentication when API tokens are in use on the backend" ,
119119 )
120+ agentCmd .PersistentFlags ().BoolVarP (
121+ & agent .Profiling ,
122+ "enable-pprof" ,
123+ "" ,
124+ false ,
125+ "Enables the pprof profiling server on the agent (port: 6060)." ,
126+ )
120127}
Original file line number Diff line number Diff line change @@ -4,9 +4,12 @@ import (
44 "bytes"
55 "context"
66 "encoding/json"
7+ "errors"
78 "fmt"
89 "io/ioutil"
910 "log"
11+ "net/http"
12+ _ "net/http/pprof"
1013 "net/url"
1114 "os"
1215 "strings"
@@ -50,6 +53,9 @@ var StrictMode bool
5053// APIToken is an authentication token used for the backend API as an alternative to oauth flows.
5154var APIToken string
5255
56+ // Profiling flag enabled pprof endpoints to run on the agent
57+ var Profiling bool
58+
5359// schema version of the data sent by the agent.
5460// The new default version is v2.
5561// In v2 the agent posts data readings using api.gathereredResources
@@ -64,6 +70,16 @@ func Run(cmd *cobra.Command, args []string) {
6470 defer cancel ()
6571 config , preflightClient := getConfiguration ()
6672
73+ if Profiling {
74+ log .Printf ("pprof profiling was enabled.\n Running profiling on port :6060" )
75+ go func () {
76+ err := http .ListenAndServe (":6060" , nil )
77+ if err != nil && ! errors .Is (err , http .ErrServerClosed ) {
78+ log .Fatalf ("failed to run pprof profiler: %s" , err )
79+ }
80+ }()
81+ }
82+
6783 dataGatherers := map [string ]datagatherer.DataGatherer {}
6884 var wg sync.WaitGroup
6985
You can’t perform that action at this time.
0 commit comments