1. adding statistics reporting

2. refactor version to util package
This commit is contained in:
Chris Lu
2014-03-25 13:46:59 -07:00
parent 6e0601a73b
commit 39b774a131
17 changed files with 319 additions and 32 deletions

View File

@@ -4,7 +4,9 @@ import (
"bytes"
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/stats"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
"fmt"
"net"
@@ -14,6 +16,14 @@ import (
"strings"
)
var serverStats *stats.ServerStats
func init() {
serverStats = stats.NewServerStats()
go serverStats.Start()
}
func writeJson(w http.ResponseWriter, r *http.Request, obj interface{}) (err error) {
w.Header().Set("Content-Type", "application/javascript")
var bytes []byte
@@ -152,3 +162,15 @@ func parseURLPath(path string) (vid, fid, filename, ext string, isVolumeIdOnly b
}
return
}
func statsCounterHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = util.VERSION
m["Statistics"] = serverStats
writeJsonQuiet(w, r, m)
}
func statsMemoryHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = util.VERSION
m["Statistics"] = serverStats
writeJsonQuiet(w, r, m)
}

View File

@@ -23,7 +23,6 @@ type MasterServer struct {
defaultReplicaPlacement string
garbageThreshold string
whiteList []string
version string
Topo *topology.Topology
vg *replication.VolumeGrowth
@@ -32,7 +31,7 @@ type MasterServer struct {
bounedLeaderChan chan int
}
func NewMasterServer(r *mux.Router, version string, port int, metaFolder string,
func NewMasterServer(r *mux.Router, port int, metaFolder string,
volumeSizeLimitMB uint,
pulseSeconds int,
confFile string,
@@ -41,7 +40,6 @@ func NewMasterServer(r *mux.Router, version string, port int, metaFolder string,
whiteList []string,
) *MasterServer {
ms := &MasterServer{
version: version,
volumeSizeLimitMB: volumeSizeLimitMB,
pulseSeconds: pulseSeconds,
defaultReplicaPlacement: defaultReplicaPlacement,
@@ -68,6 +66,8 @@ func NewMasterServer(r *mux.Router, version string, port int, metaFolder string,
r.HandleFunc("/vol/vacuum", ms.proxyToLeader(secure(ms.whiteList, ms.volumeVacuumHandler)))
r.HandleFunc("/submit", secure(ms.whiteList, ms.submitFromMasterServerHandler))
r.HandleFunc("/{filekey}", ms.redirectHandler)
r.HandleFunc("/stats/counter", secure(ms.whiteList, statsCounterHandler))
r.HandleFunc("/stats/memory", secure(ms.whiteList, statsMemoryHandler))
ms.Topo.StartRefreshWritableVolumes(garbageThreshold)

View File

@@ -1,6 +1,7 @@
package weed_server
import (
"code.google.com/p/weed-fs/go/stats"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"encoding/json"
@@ -37,6 +38,7 @@ func (ms *MasterServer) dirLookupHandler(w http.ResponseWriter, r *http.Request)
}
func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request) {
stats.AssignRequest()
c, e := strconv.Atoi(r.FormValue("count"))
if e != nil {
c = 1
@@ -119,7 +121,7 @@ func (ms *MasterServer) dirJoinHandler(w http.ResponseWriter, r *http.Request) {
func (ms *MasterServer) dirStatusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = ms.version
m["Version"] = util.VERSION
m["Topology"] = ms.Topo.ToMap()
writeJsonQuiet(w, r, m)
}
@@ -159,7 +161,7 @@ func (ms *MasterServer) volumeGrowHandler(w http.ResponseWriter, r *http.Request
func (ms *MasterServer) volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = ms.version
m["Version"] = util.VERSION
m["Volumes"] = ms.Topo.ToVolumeMap()
writeJsonQuiet(w, r, m)
}

View File

@@ -21,14 +21,12 @@ type RaftServer struct {
raftServer raft.Server
dataDir string
httpAddr string
version string
router *mux.Router
topo *topology.Topology
}
func NewRaftServer(r *mux.Router, version string, peers []string, httpAddr string, dataDir string, topo *topology.Topology, pulseSeconds int) *RaftServer {
func NewRaftServer(r *mux.Router, peers []string, httpAddr string, dataDir string, topo *topology.Topology, pulseSeconds int) *RaftServer {
s := &RaftServer{
version: version,
peers: peers,
httpAddr: httpAddr,
dataDir: dataDir,

View File

@@ -15,15 +15,13 @@ type VolumeServer struct {
rack string
whiteList []string
store *storage.Store
version string
}
func NewVolumeServer(r *http.ServeMux, version string, ip string, port int, publicUrl string, folders []string, maxCounts []int,
func NewVolumeServer(r *http.ServeMux, ip string, port int, publicUrl string, folders []string, maxCounts []int,
masterNode string, pulseSeconds int,
dataCenter string, rack string,
whiteList []string) *VolumeServer {
vs := &VolumeServer{
version: version,
masterNode: masterNode,
pulseSeconds: pulseSeconds,
dataCenter: dataCenter,
@@ -40,6 +38,8 @@ func NewVolumeServer(r *http.ServeMux, version string, ip string, port int, publ
r.HandleFunc("/admin/vacuum_volume_commit", secure(vs.whiteList, vs.vacuumVolumeCommitHandler))
r.HandleFunc("/admin/freeze_volume", secure(vs.whiteList, vs.freezeVolumeHandler))
r.HandleFunc("/admin/delete_collection", secure(vs.whiteList, vs.deleteCollectionHandler))
r.HandleFunc("/stats/counter", secure(vs.whiteList, statsCounterHandler))
r.HandleFunc("/stats/memory", secure(vs.whiteList, statsMemoryHandler))
r.HandleFunc("/", vs.storeHandler)
go func() {

View File

@@ -4,7 +4,9 @@ import (
"code.google.com/p/weed-fs/go/glog"
"code.google.com/p/weed-fs/go/operation"
"code.google.com/p/weed-fs/go/replication"
"code.google.com/p/weed-fs/go/stats"
"code.google.com/p/weed-fs/go/storage"
"code.google.com/p/weed-fs/go/util"
"mime"
"net/http"
"strconv"
@@ -16,7 +18,7 @@ var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
m := make(map[string]interface{})
m["Version"] = vs.version
m["Version"] = util.VERSION
m["Volumes"] = vs.store.Status()
writeJsonQuiet(w, r, m)
}
@@ -86,14 +88,19 @@ func (vs *VolumeServer) submitFromVolumeServerHandler(w http.ResponseWriter, r *
func (vs *VolumeServer) storeHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
stats.ReadRequest()
vs.GetOrHeadHandler(w, r, true)
case "HEAD":
stats.ReadRequest()
vs.GetOrHeadHandler(w, r, false)
case "DELETE":
stats.DeleteRequest()
secure(vs.whiteList, vs.DeleteHandler)(w, r)
case "PUT":
stats.WriteRequest()
secure(vs.whiteList, vs.PostHandler)(w, r)
case "POST":
stats.WriteRequest()
secure(vs.whiteList, vs.PostHandler)(w, r)
}
}