Permalink
Browse files

Added support for general toplevel stats.

  • Loading branch information...
1 parent eea5b83 commit 3be59c3fa279d3275ae1cbcf1c997ab9eb01619f @dustin dustin committed Jun 12, 2012
Showing with 92 additions and 1 deletion.
  1. +22 −1 static/vbmap.js
  2. +70 −0 vbmap.go
View
@@ -10,7 +10,8 @@ if(!Object.keys) Object.keys = function(o) {
// Base URL for all map requests. Can allow for remote requests.
var mapRequestBase = "/map";
-var statRequestBase = "/vb";
+var vbStatRequestBase = "/vb";
+var statRequestBase = "/stats";
function getClusterParams() {
var s = document.location.search.substring(1);
@@ -131,6 +132,26 @@ function doVBStatRequest(clusterInfo, fun, errfun, finfun) {
if (clusterInfo.bucket) {
params += '&bucket=' + clusterInfo.bucket;
}
+ d3.json(vbStatRequestBase + "?" + params, function(json) {
+ if (json != null) {
+ fun(json);
+ } else if(errfun) {
+ errfun();
+ }
+ if (finfun) {
+ finfun();
+ }
+ });
+}
+
+function doGenericStatRequest(clusterInfo, st, fun, errfun, finfun) {
+ var params="rand=" + Math.random();
+ if (clusterInfo.cluster) {
+ params += '&cluster=' + clusterInfo.cluster;
+ }
+ if (clusterInfo.bucket) {
+ params += '&bucket=' + clusterInfo.bucket;
+ }
d3.json(statRequestBase + "?" + params, function(json) {
if (json != null) {
fun(json);
View
@@ -150,6 +150,42 @@ func getVbStats(bucket *couchbase.Bucket, commonSuffixMC string) map[string]vbst
return processVBDetails(bucket.GetStats("vbucket-details"), commonSuffixMC)
}
+func processGenericStats(in map[string]map[string]string, commonSuffixMC string) map[string]map[string]string {
+ out := map[string]map[string]string{}
+ for k, v := range in {
+ out[couchbase.CleanupHost(k, commonSuffixMC)] = v
+ }
+ return out
+}
+
+func getStats(bucket *couchbase.Bucket, commonSuffixMC string) map[string]map[string]string {
+ return processGenericStats(bucket.GetStats(""), commonSuffixMC)
+}
+
+func statsHandler(w http.ResponseWriter, req *http.Request) {
+ w.Header().Set("Content-type", "application/json")
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+
+ bucket := getBucket(req)
+ defer bucket.Close()
+
+ commonSuffixMC := couchbase.FindCommonSuffix(bucket.VBucketServerMap.ServerList)
+
+ rv := getStats(bucket, commonSuffixMC)
+
+ req.ParseForm()
+ var_name := req.FormValue("name")
+
+ if var_name != "" {
+ fmt.Fprintf(w, "var "+var_name+" = ")
+ }
+ err := json.NewEncoder(w).Encode(rv)
+ maybefatal(err, "Error encoding output: %v", err)
+ if var_name != "" {
+ fmt.Fprintf(w, ";")
+ }
+}
+
func vbHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
@@ -247,6 +283,37 @@ func replayvbHandler(w http.ResponseWriter, req *http.Request) {
}
}
+func replaystatsHandler(w http.ResponseWriter, req *http.Request) {
+ w.Header().Set("Content-type", "application/json")
+ w.Header().Set("Access-Control-Allow-Origin", "*")
+
+ re := currentState.current()
+
+ conv := map[string]map[string]string{}
+ for s, m := range re.All {
+ out, ok := conv[s]
+ if !ok {
+ out = make(map[string]string)
+ conv[s] = out
+ }
+ for k, v := range m {
+ out[k] = fmt.Sprintf("%v", v)
+ }
+ }
+
+ req.ParseForm()
+ var_name := req.FormValue("name")
+
+ if var_name != "" {
+ fmt.Fprintf(w, "var "+var_name+" = ")
+ }
+ err := json.NewEncoder(w).Encode(conv)
+ maybefatal(err, "Error encoding output: %v", err)
+ if var_name != "" {
+ fmt.Fprintf(w, ";")
+ }
+}
+
func main() {
staticPath := flag.Bool("static", false,
"Interpret URL as a static path (for testing)")
@@ -270,13 +337,16 @@ func main() {
default:
http.HandleFunc("/map", mapHandler)
http.HandleFunc("/vb", vbHandler)
+ http.HandleFunc("/stats", statsHandler)
case *staticPath:
http.HandleFunc("/map", files("application/json", flag.Args()...))
http.HandleFunc("/vb", files("application/json", flag.Args()...))
+ http.HandleFunc("/stats", files("application/json", flag.Args()...))
case *replayPath:
go startReplay(*replaySpeed, flag.Arg(0))
http.HandleFunc("/map", replaymapHandler)
http.HandleFunc("/vb", replayvbHandler)
+ http.HandleFunc("/stats", replaystatsHandler)
}
log.Fatal(http.ListenAndServe(":4444", nil))

0 comments on commit 3be59c3

Please sign in to comment.