1
0
Fork 0

Support pprof information over HTTP

master
Philip O'Toole 8 years ago
parent bbdf486fed
commit 6f4814a4c3

@ -1,3 +1,6 @@
## 3.3.0 (unreleased)
- [PR #148](https://github.com/rqlite/rqlite/pull/148): Support pprof information over HTTP.
## 3.2.1 (May 22nd 2016) ## 3.2.1 (May 22nd 2016)
- [PR #143](https://github.com/rqlite/rqlite/pull/143): Use DELETE as HTTP method to remove nodes. - [PR #143](https://github.com/rqlite/rqlite/pull/143): Use DELETE as HTTP method to remove nodes.

@ -73,6 +73,7 @@ var raftAdv string
var joinAddr string var joinAddr string
var noVerify bool var noVerify bool
var expvar bool var expvar bool
var pprofEnabled bool
var dsn string var dsn string
var onDisk bool var onDisk bool
var noVerifySelect bool var noVerifySelect bool
@ -92,6 +93,7 @@ func init() {
flag.StringVar(&joinAddr, "join", "", "protocol://host:port of leader to join") flag.StringVar(&joinAddr, "join", "", "protocol://host:port of leader to join")
flag.BoolVar(&noVerify, "noverify", false, "Skip verification of any HTTPS cert when joining") flag.BoolVar(&noVerify, "noverify", false, "Skip verification of any HTTPS cert when joining")
flag.BoolVar(&expvar, "expvar", true, "Serve expvar data on HTTP server") flag.BoolVar(&expvar, "expvar", true, "Serve expvar data on HTTP server")
flag.BoolVar(&pprofEnabled, "pprof", true, "Serve pprof data on HTTP server")
flag.StringVar(&dsn, "dsn", "", `SQLite DSN parameters. E.g. "cache=shared&mode=memory"`) flag.StringVar(&dsn, "dsn", "", `SQLite DSN parameters. E.g. "cache=shared&mode=memory"`)
flag.BoolVar(&onDisk, "ondisk", false, "Use an on-disk SQLite database") flag.BoolVar(&onDisk, "ondisk", false, "Use an on-disk SQLite database")
flag.BoolVar(&noVerifySelect, "nosel", false, "Don't verify that all queries begin with SELECT") flag.BoolVar(&noVerifySelect, "nosel", false, "Don't verify that all queries begin with SELECT")
@ -237,6 +239,7 @@ func main() {
s.KeyFile = x509Key s.KeyFile = x509Key
s.NoVerifySelect = noVerifySelect s.NoVerifySelect = noVerifySelect
s.Expvar = expvar s.Expvar = expvar
s.Pprof = pprofEnabled
s.BuildInfo = map[string]interface{}{ s.BuildInfo = map[string]interface{}{
"commit": commit, "commit": commit,
"branch": branch, "branch": branch,

@ -8,8 +8,17 @@ curl localhost:4001/status?pretty
The use of the URL param `pretty` is optional, and results in pretty-printed JSON responses. The use of the URL param `pretty` is optional, and results in pretty-printed JSON responses.
## expvar support ## expvar support
rqlite also exports [expvar](http://godoc.org/pkg/expvar/) information. The standard expvar information, as well as some custom information, is exposed. This data can be retrieved like so: rqlite also exports [expvar](http://godoc.org/pkg/expvar/) information. The standard expvar information, as well as some custom information, is exposed. This data can be retrieved like so (assuming the node is started in its default configuration):
```bash ```bash
curl localhost:4001/debug/vars curl localhost:4001/debug/vars
``` ```
## pprof support
pprof information is available by default and can be retrieved as follows:
```bash
curl localhost:4001/debug/pprof/cmdline
curl localhost:4001/debug/pprof/profile
curl localhost:4001/debug/pprof/symbol
```

@ -12,6 +12,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"net/http/pprof"
"os" "os"
"runtime" "runtime"
"strings" "strings"
@ -128,6 +129,7 @@ type Service struct {
credentialStore CredentialStore credentialStore CredentialStore
Expvar bool Expvar bool
Pprof bool
BuildInfo map[string]interface{} BuildInfo map[string]interface{}
@ -217,6 +219,8 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.handleStatus(w, r) s.handleStatus(w, r)
case r.URL.Path == "/debug/vars" && s.Expvar: case r.URL.Path == "/debug/vars" && s.Expvar:
serveExpvar(w, r) serveExpvar(w, r)
case strings.HasPrefix(r.URL.Path, "/debug/pprof") && s.Pprof:
servePprof(w, r)
default: default:
w.WriteHeader(http.StatusNotFound) w.WriteHeader(http.StatusNotFound)
} }
@ -599,6 +603,20 @@ func serveExpvar(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "\n}\n") fmt.Fprintf(w, "\n}\n")
} }
// servePprof serves pprof information over HTTP.
func servePprof(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/debug/pprof/cmdline":
pprof.Cmdline(w, r)
case "/debug/pprof/profile":
pprof.Profile(w, r)
case "/debug/pprof/symbol":
pprof.Symbol(w, r)
default:
pprof.Index(w, r)
}
}
func writeResponse(w http.ResponseWriter, r *http.Request, j *Response) { func writeResponse(w http.ResponseWriter, r *http.Request, j *Response) {
var b []byte var b []byte
var err error var err error

Loading…
Cancel
Save