1
0
Fork 0

Basic HTTP stats to expvar

master
Philip O Toole 9 years ago
parent 68107a4874
commit ec3af02ba5

@ -288,7 +288,7 @@ 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 ### expvar
rqlite also exports [expvar]() information. This can be retrieved like so: rqlite also exports [expvar]() information. Both standard and custom information is exposed. This data can be retrieved like so:
```bash ```bash
curl -v localhost:4001/debug/vars curl -v localhost:4001/debug/vars

@ -51,6 +51,22 @@ type Response struct {
end time.Time end time.Time
} }
// stats captures stats for the HTTP service.
var stats *expvar.Map
const (
numExecutions = "executions"
numQueries = "queries"
numBackups = "backups"
)
func init() {
stats = expvar.NewMap("http")
stats.Add(numExecutions, 0)
stats.Add(numQueries, 0)
stats.Add(numBackups, 0)
}
// SetTime sets the Time attribute of the response. This way it will be present // SetTime sets the Time attribute of the response. This way it will be present
// in the serialized JSON version. // in the serialized JSON version.
func (r *Response) SetTime() { func (r *Response) SetTime() {
@ -119,10 +135,13 @@ func (s *Service) Close() {
func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch { switch {
case strings.HasPrefix(r.URL.Path, "/db/execute"): case strings.HasPrefix(r.URL.Path, "/db/execute"):
stats.Add(numExecutions, 1)
s.handleExecute(w, r) s.handleExecute(w, r)
case strings.HasPrefix(r.URL.Path, "/db/query"): case strings.HasPrefix(r.URL.Path, "/db/query"):
stats.Add(numQueries, 1)
s.handleQuery(w, r) s.handleQuery(w, r)
case strings.HasPrefix(r.URL.Path, "/db/backup"): case strings.HasPrefix(r.URL.Path, "/db/backup"):
stats.Add(numBackups, 1)
s.handleBackup(w, r) s.handleBackup(w, r)
case strings.HasPrefix(r.URL.Path, "/join"): case strings.HasPrefix(r.URL.Path, "/join"):
s.handleJoin(w, r) s.handleJoin(w, r)

Loading…
Cancel
Save