mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
support version and basic stats
This commit is contained in:
parent
3683992183
commit
0ebd133a0d
@ -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/"):]
|
||||
|
2
etcd.go
2
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 {
|
||||
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
package main
|
||||
|
||||
var version = "v1"
|
||||
|
||||
var releaseVersion = "etcd <0.1>"
|
||||
|
Loading…
x
Reference in New Issue
Block a user