Ejemplo n.º 1
0
func doStats(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	acctStore := s.AccountingStore()
	reg := acctStore.MetricRegistry()

	switch req.Method {
	case "GET":
		stats := make(map[string]interface{})
		for name, metric := range reg.Counters() {
			addMetricData(name, stats, getMetricData(metric))
		}
		for name, metric := range reg.Gauges() {
			addMetricData(name, stats, getMetricData(metric))
		}
		for name, metric := range reg.Timers() {
			addMetricData(name, stats, getMetricData(metric))
		}
		for name, metric := range reg.Meters() {
			addMetricData(name, stats, getMetricData(metric))
		}
		for name, metric := range reg.Histograms() {
			addMetricData(name, stats, getMetricData(metric))
		}
		return stats, nil
	default:
		return nil, nil
	}
}
Ejemplo n.º 2
0
func (this *httpRequest) writePrefix(srvr *server.Server, signature value.Value) bool {
	return this.writeString("{\n") &&
		this.writeRequestID() &&
		this.writeClientContextID() &&
		this.writeSignature(srvr.Signature(), signature) &&
		this.writeString(",\n    \"results\": [")
}
Ejemplo n.º 3
0
func Run(mockServer *server.Server, q string) ([]interface{}, []errors.Error, errors.Error) {

	var metrics value.Tristate
	base := server.NewBaseRequest(q, nil, nil, nil, "json", value.FALSE, metrics, value.TRUE, nil, "", nil)

	mr := &MockResponse{
		results: []interface{}{}, warnings: []errors.Error{}, done: make(chan bool),
	}

	query := &MockQuery{
		BaseRequest: *base,
		response:    mr,
	}

	select {
	case mockServer.Channel() <- query:
		// Wait until the request exits.
		<-query.CloseNotify()
	default:
		// Timeout.
		return nil, nil, errors.NewError(nil, "Query timed out")
	}

	// wait till all the results are ready
	<-mr.done
	return mr.results, mr.warnings, mr.err
}
Ejemplo n.º 4
0
func (this *httpRequest) Execute(srvr *server.Server, signature value.Value, stopNotify chan bool) {
	defer this.Stop(server.COMPLETED)

	this.NotifyStop(stopNotify)

	this.httpRespCode = http.StatusOK
	_ = this.writePrefix(srvr, signature) &&
		this.writeResults()
	this.writeSuffix(srvr.Metrics(), "")
	this.writer.noMoreData()
}
Ejemplo n.º 5
0
func (this *httpRequest) Failed(srvr *server.Server) {
	this.writeString("{\n")
	this.writeRequestID()
	this.writeClientContextID()
	this.writeErrors()
	this.writeWarnings()
	this.writeState("")
	this.writeMetrics(srvr.Metrics())
	this.writeString("\n}\n")
	this.writer.noMoreData()
}
Ejemplo n.º 6
0
func doClusters(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	cfgStore := s.ConfigurationStore()
	cm := cfgStore.ConfigurationManager()
	switch req.Method {
	case "GET":
		return cm.GetClusters()
	case "POST":
		cluster, err := getClusterFromRequest(req)
		if err != nil {
			return nil, err
		}
		return cfgStore.ConfigurationManager().AddCluster(cluster)
	default:
		return nil, nil
	}
}
Ejemplo n.º 7
0
func doCluster(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	vars := mux.Vars(req)
	name := vars["cluster"]
	cfgStore := s.ConfigurationStore()
	cluster, err := cfgStore.ClusterByName(name)
	if err != nil {
		return nil, err
	}

	switch req.Method {
	case "GET":
		return cluster, nil
	case "DELETE":
		return cfgStore.ConfigurationManager().RemoveCluster(cluster)
	default:
		return nil, nil
	}
}
Ejemplo n.º 8
0
func NewServiceEndpoint(server *server.Server, staticPath string, metrics bool) *HttpEndpoint {
	rv := &HttpEndpoint{
		server:  server,
		metrics: metrics,
		bufpool: NewSyncPool(server.KeepAlive()),
	}

	rv.registerHandlers(staticPath)
	return rv
}
Ejemplo n.º 9
0
func doStat(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	vars := mux.Vars(req)
	name := vars["stat"]
	acctStore := s.AccountingStore()
	reg := acctStore.MetricRegistry()

	switch req.Method {
	case "GET":
		metric := reg.Get(name)
		if metric != nil {
			return getMetricData(metric), nil
		} else {
			return nil, nil
		}
	case "DELETE":
		return nil, reg.Unregister(name)
	default:
		return nil, nil
	}
}
Ejemplo n.º 10
0
func doNodes(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	vars := mux.Vars(req)
	name := vars["cluster"]
	cfgStore := s.ConfigurationStore()
	cluster, err := cfgStore.ClusterByName(name)
	if err != nil || cluster == nil {
		return cluster, err
	}
	switch req.Method {
	case "GET":
		return cluster.ClusterManager().GetQueryNodes()
	case "POST":
		node, err := getNodeFromRequest(req)
		if err != nil {
			return nil, err
		}
		return cluster.ClusterManager().AddQueryNode(node)
	default:
		return nil, nil
	}
}
Ejemplo n.º 11
0
func doConfig(s *server.Server, w http.ResponseWriter, req *http.Request) (interface{}, errors.Error) {
	if localConfig.myConfig != nil {
		return localConfig.myConfig, nil
	}
	var self clustering.QueryNode
	ip, err := util.ExternalIP()
	if err != nil {
		return nil, err
	}

	name, er := os.Hostname()
	if er != nil {
		return nil, err
	}

	cm := s.ConfigurationStore().ConfigurationManager()
	clusters, err := cm.GetClusters()
	if err != nil {
		return nil, err
	}

	for _, c := range clusters {
		clm := c.ClusterManager()
		queryNodes, err := clm.GetQueryNodes()
		if err != nil {
			return nil, err
		}

		for _, qryNode := range queryNodes {
			if qryNode.Name() == ip || qryNode.Name() == name {
				self = qryNode
				break
			}
		}
	}
	localConfig.Lock()
	defer localConfig.Unlock()
	localConfig.myConfig = self
	return localConfig.myConfig, nil
}