mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-28 07:22:00 +00:00
add option to start http server for profiling
This commit is contained in:
parent
ca9433e0ea
commit
52bc59aee9
3 changed files with 34 additions and 4 deletions
12
cli/flags.go
12
cli/flags.go
|
@ -139,6 +139,18 @@ var (
|
||||||
EnvVars: []string{"CONFIG_FILE"},
|
EnvVars: []string{"CONFIG_FILE"},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "enable-profiling",
|
||||||
|
Usage: "enables the go http profiling endpoints",
|
||||||
|
EnvVars: []string{"ENABLE_PROFILING"},
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "profiling-address",
|
||||||
|
Usage: "specify ip address and port the profiling server should listen on",
|
||||||
|
EnvVars: []string{"PROFILING_ADDRESS"},
|
||||||
|
Value: "localhost:9999",
|
||||||
|
},
|
||||||
|
|
||||||
// ############################
|
// ############################
|
||||||
// ### ACME Client Settings ###
|
// ### ACME Client Settings ###
|
||||||
// ############################
|
// ############################
|
||||||
|
|
18
server/profiling.go
Normal file
18
server/profiling.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StartProfilingServer(listeningAddress string) {
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: listeningAddress,
|
||||||
|
Handler: http.DefaultServeMux,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
log.Fatal(server.ListenAndServe())
|
||||||
|
}()
|
||||||
|
}
|
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -43,9 +42,6 @@ func Serve(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel)
|
log.Logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).With().Timestamp().Logger().Level(logLevel)
|
||||||
|
|
||||||
foo, _ := json.Marshal(cfg)
|
|
||||||
log.Trace().RawJSON("config", foo).Msg("starting server with config")
|
|
||||||
|
|
||||||
listeningSSLAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
listeningSSLAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.Port)
|
||||||
listeningHTTPAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.HttpPort)
|
listeningHTTPAddress := fmt.Sprintf("%s:%d", cfg.Server.Host, cfg.Server.HttpPort)
|
||||||
|
|
||||||
|
@ -133,6 +129,10 @@ func Serve(ctx *cli.Context) error {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.IsSet("enable-profiling") {
|
||||||
|
StartProfilingServer(ctx.String("profiling-address"))
|
||||||
|
}
|
||||||
|
|
||||||
// Create ssl handler based on settings
|
// Create ssl handler based on settings
|
||||||
sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)
|
sslHandler := handler.Handler(cfg.Server, giteaClient, dnsLookupCache, canonicalDomainCache, redirectsCache)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue