Exemple #1
0
func (h *NsStatsHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request) {

	_, indexDefsMap, err := h.mgr.GetIndexDefs(false)
	if err != nil {
		rest.ShowError(w, req, "could not retrieve index defs", 500)
		return
	}

	nsIndexStats := make(NSIndexStats, len(indexDefsMap))
	for indexDefName, indexDef := range indexDefsMap {
		nsIndexStats[indexDef.SourceName+":"+indexDefName] = NewIndexStat()
	}

	feeds, pindexes := h.mgr.CurrentMaps()

	sourceName := ""
	for _, pindex := range pindexes {
		sourceName = pindex.SourceName
		lindexName := pindex.SourceName + ":" + pindex.IndexName
		nsIndexStat, ok := nsIndexStats[lindexName]
		if ok {

			// manually track a statistic representing
			// the number of pindex in the index
			oldValue, ok := nsIndexStat["num_pindexes"]
			if ok {
				switch oldValue := oldValue.(type) {
				case float64:
					oldValue += float64(1)
					nsIndexStat["num_pindexes"] = oldValue
				}
			}

			// automatically process all the pindex dest stats
			err := addPindexStats(pindex, nsIndexStat)
			if err != nil {
				rest.ShowError(w, req, fmt.Sprintf("error processing PIndex stats: %v", err), 500)
				return
			}
		}
	}

	for _, feed := range feeds {
		lindexName := sourceName + ":" + feed.IndexName()
		nsIndexStat, ok := nsIndexStats[lindexName]
		if ok {
			err := addFeedStats(feed, nsIndexStat)

			// automatically process all the feed stats
			if err != nil {
				rest.ShowError(w, req, fmt.Sprintf("error processing Feed stats: %v", err), 500)
				return
			}
		}
	}

	// FIXME hard-coded top-level stats
	nsIndexStats[""] = make(map[string]interface{})
	nsIndexStats[""]["num_connections"] = 0
	nsIndexStats[""]["needs_restart"] = false

	rest.MustEncode(w, nsIndexStats)
}
Exemple #2
0
func (h *NsStatusHandler) ServeHTTP(
	w http.ResponseWriter, req *http.Request) {

	cfg := h.mgr.Cfg()
	planPIndexes, _, err := cbgt.CfgGetPlanPIndexes(cfg)
	if err != nil {
		rest.ShowError(w, req, "could not retrieve plan pIndexes", 500)
		return
	}

	nodesDefs, _, err := cbgt.CfgGetNodeDefs(cfg, cbgt.NODE_DEFS_WANTED)
	if err != nil {
		rest.ShowError(w, req, "could not retrieve node defs (wanted)", 500)
		return
	}

	_, indexDefsMap, err := h.mgr.GetIndexDefs(false)
	if err != nil {
		rest.ShowError(w, req, "could not retrieve index defs", 500)
		return
	}

	w.Write(cbgt.JsonOpenBrace)
	w.Write(statsNamePrefix)
	w.Write([]byte("status"))
	w.Write(statsNameSuffix)
	w.Write([]byte("["))

	indexDefNames := make(sort.StringSlice, 0, len(indexDefsMap))
	for indexDefName := range indexDefsMap {
		indexDefNames = append(indexDefNames, indexDefName)
	}

	sort.Sort(indexDefNames)

	for i, indexDefName := range indexDefNames {
		indexDef := indexDefsMap[indexDefName]
		if i > 0 {
			w.Write(cbgt.JsonComma)
		}

		rest.MustEncode(w, struct {
			Completion int      `json:"completion"`
			Hosts      []string `json:"hosts"`
			Status     string   `json:"status"`
			Bucket     string   `json:"bucket"`
			Name       string   `json:"name"`
		}{
			Bucket: indexDef.SourceName,
			Name:   indexDefName,
			Hosts:  HostsForIndex(indexDefName, planPIndexes, nodesDefs),
			// FIXME hard-coded
			Completion: 100,
			Status:     "Ready",
		})

	}
	w.Write([]byte("],"))
	w.Write(statsNamePrefix)
	w.Write([]byte("code"))
	w.Write(statsNameSuffix)
	w.Write([]byte("\"success\""))
	w.Write(cbgt.JsonCloseBrace)

}