1
0
Fork 0

More /status functionality

master
Philip O'Toole 9 years ago
parent 59cdb6856c
commit 92329628cf

@ -237,14 +237,10 @@ Using an in-memory does not put your data at risk. Since the Raft log is the aut
Pass `-mem` to `rqlited` at start-up to enable an in-memory database.
## Administration API
*Being refactored for v2.0, and is currently non-functional.*
## Status API
An Status API exists, which dumps some basic diagnostic and statistical information, as well as basic information about the underlying Raft node. Assuming rqlite is started with default settings, the endpoints are available like so:
An Administration API exists, which dumps some basic diagnostic and statistical information, as well as basic information about the underlying Raft node. Assuming rqlite is started with default settings, the endpoints are available like so:
curl localhost:4001/raft?pretty
curl localhost:4001/diagnostics?pretty
curl localhost:4001/statistics?pretty
curl localhost:4001/status?pretty
The use of the URL param `pretty` is optional, and results in pretty-printed JSON responses.

@ -57,6 +57,8 @@ type Service struct {
ln net.Listener // Service listener
store Store // The Raft-backed database store.
lastBackup time.Time // Time of last successful backup.
}
// New returns an uninitialized HTTP service.
@ -107,7 +109,7 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case strings.HasPrefix(r.URL.Path, "/join"):
s.handleJoin(w, r)
case strings.HasPrefix(r.URL.Path, "/status"):
s.handleStoreStatus(w, r)
s.handleStatus(w, r)
default:
w.WriteHeader(http.StatusNotFound)
}
@ -143,7 +145,7 @@ func (s *Service) handleJoin(w http.ResponseWriter, r *http.Request) {
}
}
// handleStoreStatus returns stats on the Raft module.
// handleSBackup returns stats on the Raft module.
func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
@ -167,10 +169,11 @@ func (s *Service) handleBackup(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
s.lastBackup = time.Now()
}
// handleStoreStatus returns stats on the Raft module.
func (s *Service) handleStoreStatus(w http.ResponseWriter, r *http.Request) {
// handleStatus returns status on the system.
func (s *Service) handleStatus(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
@ -182,12 +185,22 @@ func (s *Service) handleStoreStatus(w http.ResponseWriter, r *http.Request) {
return
}
httpStatus := map[string]interface{}{
"addr": s.Addr().String(),
}
status := map[string]interface{}{
"store": results,
"http": httpStatus,
"last_backup": s.lastBackup,
}
pretty, _ := isPretty(r)
var b []byte
if pretty {
b, err = json.MarshalIndent(results, "", " ")
b, err = json.MarshalIndent(status, "", " ")
} else {
b, err = json.Marshal(results)
b, err = json.Marshal(status)
}
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) // Internal error actually

Loading…
Cancel
Save