diff --git a/client_handlers.go b/client_handlers.go index b2a893330..011b4adaf 100644 --- a/client_handlers.go +++ b/client_handlers.go @@ -225,6 +225,18 @@ func MachinesHttpHandler(w http.ResponseWriter, req *http.Request) { } +// Handler to return the current version of etcd +func VersionHttpHandler(w http.ResponseWriter, req *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte(releaseVersion)) +} + +// Handler to return the basic stats of etcd +func StatsHttpHandler(w http.ResponseWriter, req *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write(etcdStore.Stats()) +} + // Get Handler func GetHttpHandler(w *http.ResponseWriter, req *http.Request) { key := req.URL.Path[len("/v1/keys/"):] diff --git a/etcd.go b/etcd.go index ea6f3ecaa..db8d8d45f 100644 --- a/etcd.go +++ b/etcd.go @@ -434,6 +434,8 @@ func startClientTransport(port int, st int) { http.HandleFunc("/"+version+"/watch/", WatchHttpHandler) http.HandleFunc("/leader", LeaderHttpHandler) http.HandleFunc("/machines", MachinesHttpHandler) + http.HandleFunc("/", VersionHttpHandler) + http.HandleFunc("/stats", StatsHttpHandler) switch st { diff --git a/store/store.go b/store/store.go index 649ec617c..de0134618 100644 --- a/store/store.go +++ b/store/store.go @@ -42,6 +42,9 @@ type Store struct { // Current index of the raft machine Index uint64 + + // Basic statistics information of etcd storage + BasicStats EtcdStats } // A Node represents a Value in the Key-Value pair in the store @@ -139,6 +142,9 @@ func (s *Store) Set(key string, value string, expireTime time.Time, index uint64 //Update index s.Index = index + //Update stats + s.BasicStats.Sets++ + key = path.Clean("/" + key) isExpire := !expireTime.Equal(PERMANENT) @@ -285,6 +291,9 @@ func (s *Store) internalGet(key string) *Response { // If key is a directory reuturn an array of files func (s *Store) Get(key string) ([]byte, error) { + //Update stats + s.BasicStats.Gets++ + key = path.Clean("/" + key) nodes, keys, dirs, ok := s.Tree.list(key) @@ -331,6 +340,9 @@ func (s *Store) Get(key string) ([]byte, error) { // Delete the key func (s *Store) Delete(key string, index uint64) ([]byte, error) { + //Update stats + s.BasicStats.Deletes++ + key = path.Clean("/" + key) //Update index @@ -381,6 +393,9 @@ func (s *Store) Delete(key string, index uint64) ([]byte, error) { // Set the value of the key to the value if the given prevValue is equal to the value of the key func (s *Store) TestAndSet(key string, prevValue string, value string, expireTime time.Time, index uint64) ([]byte, error) { + //Update stats + s.BasicStats.TestAndSets++ + resp := s.internalGet(key) if resp == nil { @@ -540,3 +555,4 @@ func (s *Store) checkNode(key string, node *Node) { } } } + diff --git a/version.go b/version.go index b64a7814b..b73797f85 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,5 @@ package main var version = "v1" + +var releaseVersion = "etcd <0.1>"