func testMetricIostat() {
	var response cpmserverapi.MetricIostatResponse
	var err error
	request := &cpmserverapi.MetricIostatRequest{"something", "yes"}
	response, err = cpmserverapi.MetricIostatClient("http://192.168.0.106:10001", request)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println("returned " + response.Output)
}
コード例 #2
0
//monitor server - get info
func MonitorServerGetInfo(w rest.ResponseWriter, r *rest.Request) {
	dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
	if err != nil {
		logit.Error.Println("BackupNow: error " + err.Error())
		rest.Error(w, err.Error(), 400)
		return

	}
	defer dbConn.Close()
	err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
	if err != nil {
		logit.Error.Println("MonitorServerGetInfo: authorize error " + err.Error())
		rest.Error(w, err.Error(), http.StatusUnauthorized)
		return
	}
	ServerID := r.PathParam("ServerID")
	Metric := r.PathParam("Metric")

	if ServerID == "" {
		logit.Error.Println("MonitorServerGetInfo: error ServerID required")
		rest.Error(w, "ServerID required", http.StatusBadRequest)
		return
	}
	if Metric == "" {
		logit.Error.Println("MonitorServerGetInfo: error metric required")
		rest.Error(w, "Metric required", http.StatusBadRequest)
		return
	}

	//go get the IPAddress
	server, err := admindb.GetServer(dbConn, ServerID)
	if err != nil {
		logit.Error.Println("MonitorServerGetInfo:" + err.Error())
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	var output string
	url := "http://" + server.IPAddress + ":10001"
	if Metric == "cpmiostat" {
		iostatreq := cpmserverapi.MetricIostatRequest{}
		var iostatResp cpmserverapi.MetricIostatResponse
		iostatResp, err = cpmserverapi.MetricIostatClient(url, &iostatreq)
		if err != nil {
			logit.Error.Println("MonitorServerGetInfo:" + err.Error())
			rest.Error(w, err.Error(), 400)
			return
		}
		output = iostatResp.Output
	} else if Metric == "cpmdf" {
		dfreq := cpmserverapi.MetricDfRequest{}
		var dfResp cpmserverapi.MetricDfResponse
		dfResp, err = cpmserverapi.MetricDfClient(url, &dfreq)
		if err != nil {
			logit.Error.Println("MonitorServerGetInfo:" + err.Error())
			rest.Error(w, err.Error(), 400)
			return
		}
		output = dfResp.Output
	} else {
		logit.Error.Println("unknown Metric received")
		rest.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	w.(http.ResponseWriter).Write([]byte(output))
	//w.Header().set("Content-Type", "text/json")
	w.WriteHeader(http.StatusOK)
}