mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
feat: call the HTTP API to get master state information
This commit is contained in:
@@ -135,10 +135,6 @@ type CommonResponseBody struct {
|
||||
}
|
||||
|
||||
type APIGetWorkersRequestBody struct {
|
||||
ID string `json:"id"`
|
||||
State int32 `json:"state"`
|
||||
CPUUsage float64 `json:"cpu_usage"`
|
||||
MemoryUsage float64 `json:"memory_usage"`
|
||||
}
|
||||
|
||||
type APIGetWorkersResponseBody struct {
|
||||
@@ -146,6 +142,14 @@ type APIGetWorkersResponseBody struct {
|
||||
Data []boomer.WorkerNode `json:"data"`
|
||||
}
|
||||
|
||||
type APIGetMasterRequestBody struct {
|
||||
}
|
||||
|
||||
type APIGetMasterResponseBody struct {
|
||||
ServerStatus
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type apiHandler struct {
|
||||
boomer *HRPBoomer
|
||||
}
|
||||
@@ -321,6 +325,16 @@ func (api *apiHandler) GetWorkersInfo(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, body, http.StatusOK)
|
||||
}
|
||||
|
||||
func (api *apiHandler) GetMasterInfo(w http.ResponseWriter, r *http.Request) {
|
||||
resp := &APIGetMasterResponseBody{
|
||||
ServerStatus: EnumAPIResponseSuccess,
|
||||
Data: api.boomer.GetMasterInfo(),
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(resp)
|
||||
writeJSON(w, body, http.StatusOK)
|
||||
}
|
||||
|
||||
func (api *apiHandler) Handler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
@@ -330,6 +344,7 @@ func (api *apiHandler) Handler() http.Handler {
|
||||
mux.HandleFunc("/stop", methods(api.Stop, "GET"))
|
||||
mux.HandleFunc("/quit", methods(api.Quit, "GET"))
|
||||
mux.HandleFunc("/workers", methods(api.GetWorkersInfo, "GET"))
|
||||
mux.HandleFunc("/master", methods(api.GetMasterInfo, "GET"))
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user