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)
}